Include DBGLOC instructions in the compiler output
This commit is contained in:
parent
793a6829f6
commit
141eea74fd
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
{erl_opts, [debug_info]}.
|
{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"}
|
, {getopt, "1.0.1"}
|
||||||
, {eblake2, "1.0.0"}
|
, {eblake2, "1.0.0"}
|
||||||
, {jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "2.8.0"}}}
|
, {jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "2.8.0"}}}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{"1.2.0",
|
{"1.2.0",
|
||||||
[{<<"aebytecode">>,
|
[{<<"aebytecode">>,
|
||||||
{git,"https://github.com/aeternity/aebytecode.git",
|
{git,"https://github.com/aeternity/aebytecode.git",
|
||||||
{ref,"2a0a397afad6b45da52572170f718194018bf33c"}},
|
{ref,"0939e29448b5d0cdba6a4b0c56e4785ea7026087"}},
|
||||||
0},
|
0},
|
||||||
{<<"aeserialization">>,
|
{<<"aeserialization">>,
|
||||||
{git,"https://github.com/aeternity/aeserialization.git",
|
{git,"https://github.com/aeternity/aeserialization.git",
|
||||||
|
@ -119,7 +119,7 @@ from_string1(ContractString, Options) ->
|
|||||||
, warnings := Warnings } = string_to_code(ContractString, Options),
|
, warnings := Warnings } = string_to_code(ContractString, Options),
|
||||||
#{ child_con_env := ChildContracts } = FCodeEnv,
|
#{ child_con_env := ChildContracts } = FCodeEnv,
|
||||||
SavedFreshNames = maps:get(saved_fresh_names, 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),
|
pp_assembler(FateCode, Options),
|
||||||
ByteCode = aeb_fate_code:serialize(FateCode, []),
|
ByteCode = aeb_fate_code:serialize(FateCode, []),
|
||||||
{ok, Version} = version(),
|
{ok, Version} = version(),
|
||||||
@ -132,8 +132,7 @@ from_string1(ContractString, Options) ->
|
|||||||
payable => maps:get(payable, FCode),
|
payable => maps:get(payable, FCode),
|
||||||
warnings => Warnings
|
warnings => Warnings
|
||||||
},
|
},
|
||||||
ResDbg = Res#{ variables_registers => VarsRegs,
|
ResDbg = Res#{ variables_registers => VarsRegs },
|
||||||
instructions_lines => DbglocMap },
|
|
||||||
FinalRes =
|
FinalRes =
|
||||||
case proplists:get_value(debug_info, Options, false) of
|
case proplists:get_value(debug_info, Options, false) of
|
||||||
true -> ResDbg;
|
true -> ResDbg;
|
||||||
@ -205,7 +204,7 @@ add_extra_call(Contract0, Call, Options) ->
|
|||||||
#{fcode := OrgFcode
|
#{fcode := OrgFcode
|
||||||
, fcode_env := #{child_con_env := ChildContracts}
|
, fcode_env := #{child_con_env := ChildContracts}
|
||||||
, ast := Ast} = string_to_code(Contract0, Options),
|
, 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
|
%% collect all hashes and compute the first name without hash collision to
|
||||||
SymbolHashes = maps:keys(aeb_fate_code:symbols(FateCode)),
|
SymbolHashes = maps:keys(aeb_fate_code:symbols(FateCode)),
|
||||||
CallName = first_none_match(?CALL_NAME, SymbolHashes,
|
CallName = first_none_match(?CALL_NAME, SymbolHashes,
|
||||||
|
@ -84,8 +84,7 @@ compile(ChildContracts, FCode, SavedFreshNames, Options) ->
|
|||||||
try
|
try
|
||||||
compile1(ChildContracts, FCode, SavedFreshNames, Options)
|
compile1(ChildContracts, FCode, SavedFreshNames, Options)
|
||||||
after
|
after
|
||||||
put(variables_registers, undefined),
|
put(variables_registers, undefined)
|
||||||
put(instructions_locations, undefined)
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
compile1(ChildContracts, FCode, SavedFreshNames, Options) ->
|
compile1(ChildContracts, FCode, SavedFreshNames, Options) ->
|
||||||
@ -94,58 +93,12 @@ compile1(ChildContracts, FCode, SavedFreshNames, Options) ->
|
|||||||
SFuns = functions_to_scode(ChildContracts, ContractName, Functions, SavedFreshNames, Options),
|
SFuns = functions_to_scode(ChildContracts, ContractName, Functions, SavedFreshNames, Options),
|
||||||
SFuns1 = optimize_scode(SFuns, Options),
|
SFuns1 = optimize_scode(SFuns, Options),
|
||||||
FateCode = to_basic_blocks(SFuns1),
|
FateCode = to_basic_blocks(SFuns1),
|
||||||
{FateCode1, DbglocMap} =
|
?debug(compile, Options, "~s\n", [aeb_fate_asm:pp(FateCode)]),
|
||||||
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)]),
|
|
||||||
FateCode2 = case proplists:get_value(include_child_contract_symbols, Options, false) of
|
FateCode2 = case proplists:get_value(include_child_contract_symbols, Options, false) of
|
||||||
false -> FateCode1;
|
false -> FateCode;
|
||||||
true -> add_child_symbols(ChildContracts, FateCode1)
|
true -> add_child_symbols(ChildContracts, FateCode)
|
||||||
end,
|
end,
|
||||||
{FateCode2, get_variables_registers(), get_instructions_locations()}.
|
{FateCode2, get_variables_registers()}.
|
||||||
|
|
||||||
-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}.
|
|
||||||
|
|
||||||
make_function_id(X) ->
|
make_function_id(X) ->
|
||||||
aeb_fate_code:symbol_identifier(make_function_name(X)).
|
aeb_fate_code:symbol_identifier(make_function_name(X)).
|
||||||
@ -184,16 +137,6 @@ get_variables_registers() ->
|
|||||||
Vs -> Vs
|
Vs -> Vs
|
||||||
end.
|
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) ->
|
add_variables_register(Env = #env{saved_fresh_names = SavedFreshNames}, Name, Register) ->
|
||||||
Olds = get_variables_registers(),
|
Olds = get_variables_registers(),
|
||||||
RealName = maps:get(Name, SavedFreshNames, Name),
|
RealName = maps:get(Name, SavedFreshNames, Name),
|
||||||
@ -291,7 +234,7 @@ serialize_contract_code(Env, C) ->
|
|||||||
Options = Env#env.options,
|
Options = Env#env.options,
|
||||||
SavedFreshNames = Env#env.saved_fresh_names,
|
SavedFreshNames = Env#env.saved_fresh_names,
|
||||||
FCode = maps:get(C, Env#env.child_contracts),
|
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, []),
|
ByteCode = aeb_fate_code:serialize(FateCode, []),
|
||||||
{ok, Version} = aeso_compiler:version(),
|
{ok, Version} = aeso_compiler:version(),
|
||||||
OriginalSourceCode = proplists:get_value(original_src, Options, ""),
|
OriginalSourceCode = proplists:get_value(original_src, Options, ""),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user