Fix dbg_undef for args

This commit is contained in:
Gaith Hallak 2022-12-24 17:52:32 +03:00
parent 6b7bc06c38
commit c1bf063093
3 changed files with 34 additions and 10 deletions

View File

@ -2,7 +2,7 @@
{erl_opts, [debug_info]}.
{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref, "dd6ec9b"}}}
{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref, "3446cd3"}}}
, {getopt, "1.0.1"}
, {eblake2, "1.0.0"}
, {jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "2.8.0"}}}

View File

@ -1,7 +1,7 @@
{"1.2.0",
[{<<"aebytecode">>,
{git,"https://github.com/aeternity/aebytecode.git",
{ref,"dd6ec9bc9ba7017f10538fd61abd9b89d7a5d8a3"}},
{ref,"3446cd3df6d0a2592f331999fe518f3ee083d4c1"}},
0},
{<<"aeserialization">>,
{git,"https://github.com/aeternity/aeserialization.git",

View File

@ -128,9 +128,8 @@ function_to_scode(ChildContracts, ContractName, Functions, Name, Attrs0, Args, B
[ add_variables_register(Env, Arg, Register) ||
proplists:get_value(debug_info, Options, false),
{Arg, Register} <- Env#env.vars ],
%ArgsNames = [ X || {X, _} <- lists:reverse(Env#env.vars) ],
%SCode = dbg_scoped_vars(Env, ArgsNames, to_scode(Env, Body)),
SCode = to_scode(Env, Body),
ArgsNames = [ X || {X, _} <- lists:reverse(Env#env.vars) ],
SCode = dbg_scoped_vars(Env, ArgsNames, to_scode(Env, Body)),
{Attrs, {ArgTypes, ResType1}, SCode}.
get_variables_registers() ->
@ -772,7 +771,7 @@ dbgloc(Env, Ann) ->
case {Line, Col} of
{undefined, _} -> [];
{_, undefined} -> [];
{Line, Col} -> [{'DBGLOC', {immediate, File}, {immediate, Line}, {immediate, Col}}]
{_, _} -> [{'DBGLOC', {immediate, File}, {immediate, Line}, {immediate, Col}}]
end
end.
@ -785,17 +784,42 @@ dbg_scoped_var(Env = #env{saved_fresh_names = SavedFreshNames}, Var, SCode) ->
case proplists:get_value(debug_info, Env#env.options, false) of
false -> SCode;
true ->
Register = lookup_var(Env, Var),
case maps:get(Var, SavedFreshNames, Var) of
"%" ++ _ -> SCode;
"_" -> SCode;
VarName ->
Register = lookup_var(Env, Var),
Def = [{'DBG_DEF', {immediate, VarName}, Register}],
Undef = [{'DBG_UNDEF', {immediate, VarName}, Register}],
Def ++ SCode ++ Undef
Def ++ dbg_undef(Undef, SCode)
end
end.
dbg_undef(_Undef, missing) ->
missing;
dbg_undef(Undef, loop) ->
[Undef, loop];
dbg_undef(Undef, switch_body) ->
[switch_body, Undef];
dbg_undef(Undef, {switch, Arg, Type, Alts, Catch}) ->
NewAlts = [ dbg_undef(Undef, Alt) || Alt <- Alts ],
NewCatch = dbg_undef(Undef, Catch),
NewSwitch = {switch, Arg, Type, NewAlts, NewCatch},
NewSwitch;
dbg_undef(Undef, SCode) when is_list(SCode) ->
lists:droplast(SCode) ++ [dbg_undef(Undef, lists:last(SCode))];
dbg_undef(Undef, SCode) when is_tuple(SCode); is_atom(SCode) ->
[Mnemonic | _] =
case is_tuple(SCode) of
true -> tuple_to_list(SCode);
false -> [SCode]
end,
Op = aeb_fate_opcodes:m_to_op(Mnemonic),
case aeb_fate_opcodes:end_bb(Op) of
true -> [Undef, SCode];
false -> [SCode, Undef]
end.
%% -- Phase II ---------------------------------------------------------------
%% Optimize