From 141eea74fd9e273f359b0a389d254cc7df7c69f2 Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Tue, 6 Dec 2022 17:31:57 +0300 Subject: [PATCH] Include DBGLOC instructions in the compiler output --- rebar.config | 2 +- rebar.lock | 2 +- src/aeso_compiler.erl | 7 ++-- src/aeso_fcode_to_fate.erl | 69 ++++---------------------------------- 4 files changed, 11 insertions(+), 69 deletions(-) diff --git a/rebar.config b/rebar.config index d22de4b..3e7f773 100644 --- a/rebar.config +++ b/rebar.config @@ -2,7 +2,7 @@ {erl_opts, [debug_info]}. -{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {tag, "v3.2.0"}}} +{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref, "0939e29"}}} , {getopt, "1.0.1"} , {eblake2, "1.0.0"} , {jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "2.8.0"}}} diff --git a/rebar.lock b/rebar.lock index 85a9709..c979d6a 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,7 +1,7 @@ {"1.2.0", [{<<"aebytecode">>, {git,"https://github.com/aeternity/aebytecode.git", - {ref,"2a0a397afad6b45da52572170f718194018bf33c"}}, + {ref,"0939e29448b5d0cdba6a4b0c56e4785ea7026087"}}, 0}, {<<"aeserialization">>, {git,"https://github.com/aeternity/aeserialization.git", diff --git a/src/aeso_compiler.erl b/src/aeso_compiler.erl index 41f7de5..c38a798 100644 --- a/src/aeso_compiler.erl +++ b/src/aeso_compiler.erl @@ -119,7 +119,7 @@ from_string1(ContractString, Options) -> , warnings := Warnings } = string_to_code(ContractString, Options), #{ child_con_env := ChildContracts } = FCodeEnv, SavedFreshNames = maps:get(saved_fresh_names, FCodeEnv, #{}), - {FateCode, VarsRegs, DbglocMap} = aeso_fcode_to_fate:compile(ChildContracts, FCode, SavedFreshNames, Options), + {FateCode, VarsRegs} = aeso_fcode_to_fate:compile(ChildContracts, FCode, SavedFreshNames, Options), pp_assembler(FateCode, Options), ByteCode = aeb_fate_code:serialize(FateCode, []), {ok, Version} = version(), @@ -132,8 +132,7 @@ from_string1(ContractString, Options) -> payable => maps:get(payable, FCode), warnings => Warnings }, - ResDbg = Res#{ variables_registers => VarsRegs, - instructions_lines => DbglocMap }, + ResDbg = Res#{ variables_registers => VarsRegs }, FinalRes = case proplists:get_value(debug_info, Options, false) of true -> ResDbg; @@ -205,7 +204,7 @@ add_extra_call(Contract0, Call, Options) -> #{fcode := OrgFcode , fcode_env := #{child_con_env := ChildContracts} , ast := Ast} = string_to_code(Contract0, Options), - {FateCode, _, _} = aeso_fcode_to_fate:compile(ChildContracts, OrgFcode, #{}, []), + {FateCode, _} = aeso_fcode_to_fate:compile(ChildContracts, OrgFcode, #{}, []), %% collect all hashes and compute the first name without hash collision to SymbolHashes = maps:keys(aeb_fate_code:symbols(FateCode)), CallName = first_none_match(?CALL_NAME, SymbolHashes, diff --git a/src/aeso_fcode_to_fate.erl b/src/aeso_fcode_to_fate.erl index 050d8c9..4faad6f 100644 --- a/src/aeso_fcode_to_fate.erl +++ b/src/aeso_fcode_to_fate.erl @@ -84,8 +84,7 @@ compile(ChildContracts, FCode, SavedFreshNames, Options) -> try compile1(ChildContracts, FCode, SavedFreshNames, Options) after - put(variables_registers, undefined), - put(instructions_locations, undefined) + put(variables_registers, undefined) end. compile1(ChildContracts, FCode, SavedFreshNames, Options) -> @@ -94,58 +93,12 @@ compile1(ChildContracts, FCode, SavedFreshNames, Options) -> SFuns = functions_to_scode(ChildContracts, ContractName, Functions, SavedFreshNames, Options), SFuns1 = optimize_scode(SFuns, Options), FateCode = to_basic_blocks(SFuns1), - {FateCode1, DbglocMap} = - case proplists:get_value(debug_info, Options, false) of - true -> remove_dbgloc(FateCode); - false -> {FateCode, #{}} - end, - add_instructions_locations(ContractName, DbglocMap), - ?debug(compile, Options, "~s\n", [aeb_fate_asm:pp(FateCode1)]), + ?debug(compile, Options, "~s\n", [aeb_fate_asm:pp(FateCode)]), FateCode2 = case proplists:get_value(include_child_contract_symbols, Options, false) of - false -> FateCode1; - true -> add_child_symbols(ChildContracts, FateCode1) + false -> FateCode; + true -> add_child_symbols(ChildContracts, FateCode) end, - {FateCode2, get_variables_registers(), get_instructions_locations()}. - --spec block_dbgloc_map(bcode()) -> DbglocMap when - DbglocMap :: #{integer() => {aeso_syntax:ann_file(), aeso_syntax:ann_line(), aeso_syntax:ann_col()}}. -block_dbgloc_map(BB) -> block_dbgloc_map(BB, 0, maps:new()). - --spec block_dbgloc_map(bcode(), integer(), DbglocMap) -> DbglocMap when - DbglocMap :: #{integer() => {aeso_syntax:ann_file(), aeso_syntax:ann_line(), aeso_syntax:ann_col()}}. -block_dbgloc_map([], _, DbglocMap) -> - DbglocMap; -block_dbgloc_map([{'DBGLOC', File, Line, Col} | Rest], Index, DbglocMap) -> - block_dbgloc_map(Rest, Index, maps:put(Index, {File, Line, Col}, DbglocMap)); -block_dbgloc_map([_ | Rest], Index, DbglocMap) -> - block_dbgloc_map(Rest, Index + 1, DbglocMap). - --spec remove_dbgloc(aeb_fate_code:fcode()) -> {aeb_fate_code:fcode(), DbglocMap} when - DbglocMap :: #{integer() => {aeso_syntax:ann_file(), aeso_syntax:ann_line(), aeso_syntax:ann_col()}}. -remove_dbgloc(FateCode) -> - RemoveDbglocFromBBs = - fun(_, BB) -> - IsDbg = fun({'DBGLOC', _, _, _}) -> false; - (_) -> true - end, - lists:filter(IsDbg, BB) - end, - - RemoveDbglocFromFuns = - fun(_, Fun = {_, _, BBs}) -> - NewBBs = maps:map(RemoveDbglocFromBBs, BBs), - setelement(3, Fun, NewBBs) - end, - - DbglocMapFromBBs = - fun(_, {_, _, BBs}) -> - maps:map(fun(_, BB) -> block_dbgloc_map(BB) end, BBs) - end, - - OldFuns = aeb_fate_code:functions(FateCode), - DbglocMap = maps:map(DbglocMapFromBBs, OldFuns), - NewFuns = maps:map(RemoveDbglocFromFuns, OldFuns), - {aeb_fate_code:update_functions(FateCode, NewFuns), DbglocMap}. + {FateCode2, get_variables_registers()}. make_function_id(X) -> aeb_fate_code:symbol_identifier(make_function_name(X)). @@ -184,16 +137,6 @@ get_variables_registers() -> Vs -> Vs end. -get_instructions_locations() -> - case get(instructions_locations) of - undefined -> #{}; - IL -> IL - end. - -add_instructions_locations(Contract, Map) -> - Old = get_instructions_locations(), - put(instructions_locations, Old#{Contract => Map}). - add_variables_register(Env = #env{saved_fresh_names = SavedFreshNames}, Name, Register) -> Olds = get_variables_registers(), RealName = maps:get(Name, SavedFreshNames, Name), @@ -291,7 +234,7 @@ serialize_contract_code(Env, C) -> Options = Env#env.options, SavedFreshNames = Env#env.saved_fresh_names, FCode = maps:get(C, Env#env.child_contracts), - {FateCode, _, _} = compile1(Env#env.child_contracts, FCode, SavedFreshNames, Options), + {FateCode, _} = compile1(Env#env.child_contracts, FCode, SavedFreshNames, Options), ByteCode = aeb_fate_code:serialize(FateCode, []), {ok, Version} = aeso_compiler:version(), OriginalSourceCode = proplists:get_value(original_src, Options, ""),