Add DBG_DEF and DBG_UNDEF

This commit is contained in:
Gaith Hallak 2022-12-23 20:13:20 +03:00
parent 7898ab3946
commit 9619bb6071
3 changed files with 31 additions and 8 deletions

View File

@ -2,7 +2,7 @@
{erl_opts, [debug_info]}. {erl_opts, [debug_info]}.
{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref, "da64e6c"}}} {deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref, "dd6ec9b"}}}
, {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"}}}

View File

@ -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,"da64e6ce5157b1231f764820e1c0d83917d34488"}}, {ref,"dd6ec9bc9ba7017f10538fd61abd9b89d7a5d8a3"}},
0}, 0},
{<<"aeserialization">>, {<<"aeserialization">>,
{git,"https://github.com/aeternity/aeserialization.git", {git,"https://github.com/aeternity/aeserialization.git",

View File

@ -128,7 +128,8 @@ function_to_scode(ChildContracts, ContractName, Functions, Name, Attrs0, Args, B
[ add_variables_register(Env, Arg, Register) || [ add_variables_register(Env, Arg, Register) ||
proplists:get_value(debug_info, Options, false), proplists:get_value(debug_info, Options, false),
{Arg, Register} <- Env#env.vars ], {Arg, Register} <- Env#env.vars ],
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}. {Attrs, {ArgTypes, ResType1}, SCode}.
get_variables_registers() -> get_variables_registers() ->
@ -355,13 +356,13 @@ to_scode1(Env, {op, Ann, Op, Args}) ->
to_scode1(Env, {'let', Ann, X, {var, _, Y}, Body}) -> to_scode1(Env, {'let', Ann, X, {var, _, Y}, Body}) ->
Env1 = bind_var(X, lookup_var(Env, Y), Env), Env1 = bind_var(X, lookup_var(Env, Y), Env),
[ dbgloc(Env, Ann) | to_scode(Env1, Body) ]; [ dbgloc(Env, Ann) | dbg_scoped_var(Env1, X, to_scode(Env1, Body)) ];
to_scode1(Env, {'let', Ann, X, Expr, Body}) -> to_scode1(Env, {'let', Ann, X, Expr, Body}) ->
{I, Env1} = bind_local(X, Env), {I, Env1} = bind_local(X, Env),
[ dbgloc(Env, Ann), SCode = [ to_scode(notail(Env), Expr),
to_scode(notail(Env), Expr),
aeb_fate_ops:store({var, I}, {stack, 0}), aeb_fate_ops:store({var, I}, {stack, 0}),
to_scode(Env1, Body) ]; to_scode(Env1, Body) ],
[ dbgloc(Env, Ann) | dbg_scoped_var(Env1, X, SCode) ];
to_scode1(Env = #env{ current_function = Fun, tailpos = true }, {def, Ann, Fun, Args}) -> to_scode1(Env = #env{ current_function = Fun, tailpos = true }, {def, Ann, Fun, Args}) ->
%% Tail-call to current function, f(e0..en). Compile to %% Tail-call to current function, f(e0..en). Compile to
@ -774,6 +775,26 @@ dbgloc(Env, Ann) ->
end end
end. end.
dbg_scoped_vars(_Env, [], SCode) ->
SCode;
dbg_scoped_vars(Env, [Var | Rest], SCode) ->
dbg_scoped_vars(Env, Rest, dbg_scoped_var(Env, Var, SCode)).
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 ->
Def = [{'DBG_DEF', {immediate, VarName}, Register}],
Undef = [{'DBG_UNDEF', {immediate, VarName}, Register}],
Def ++ SCode ++ Undef
end
end.
%% -- Phase II --------------------------------------------------------------- %% -- Phase II ---------------------------------------------------------------
%% Optimize %% Optimize
@ -910,6 +931,8 @@ attributes(I) ->
switch_body -> Pure(none, []); switch_body -> Pure(none, []);
'RETURN' -> Impure(pc, []); 'RETURN' -> Impure(pc, []);
{'DBGLOC', _, _, _} -> Pure(none, []); {'DBGLOC', _, _, _} -> Pure(none, []);
{'DBG_DEF', _, _} -> Pure(none, []);
{'DBG_UNDEF', _, _} -> Pure(none, []);
{'RETURNR', A} -> Impure(pc, A); {'RETURNR', A} -> Impure(pc, A);
{'CALL', A} -> Impure(?a, [A]); {'CALL', A} -> Impure(?a, [A]);
{'CALL_R', A, _, B, C, D} -> Impure(?a, [A, B, C, D]); {'CALL_R', A, _, B, C, D} -> Impure(?a, [A, B, C, D]);