Save debug locations for child contracts

This commit is contained in:
Gaith Hallak 2022-12-04 12:18:46 +03:00
parent 801231d628
commit 793a6829f6

View File

@ -84,7 +84,8 @@ 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) ->
@ -98,12 +99,13 @@ compile1(ChildContracts, FCode, SavedFreshNames, Options) ->
true -> remove_dbgloc(FateCode); true -> remove_dbgloc(FateCode);
false -> {FateCode, #{}} false -> {FateCode, #{}}
end, 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(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 -> FateCode1;
true -> add_child_symbols(ChildContracts, FateCode1) true -> add_child_symbols(ChildContracts, FateCode1)
end, end,
{FateCode2, get_variables_registers(), DbglocMap}. {FateCode2, get_variables_registers(), get_instructions_locations()}.
-spec block_dbgloc_map(bcode()) -> DbglocMap when -spec block_dbgloc_map(bcode()) -> DbglocMap when
DbglocMap :: #{integer() => {aeso_syntax:ann_file(), aeso_syntax:ann_line(), aeso_syntax:ann_col()}}. DbglocMap :: #{integer() => {aeso_syntax:ann_file(), aeso_syntax:ann_line(), aeso_syntax:ann_col()}}.
@ -182,6 +184,16 @@ 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),