diff --git a/rebar.config b/rebar.config index 5b606e9..61b8900 100644 --- a/rebar.config +++ b/rebar.config @@ -2,7 +2,7 @@ {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"} , {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 257efe8..31addd9 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,7 +1,7 @@ {"1.2.0", [{<<"aebytecode">>, {git,"https://github.com/aeternity/aebytecode.git", - {ref,"da64e6ce5157b1231f764820e1c0d83917d34488"}}, + {ref,"dd6ec9bc9ba7017f10538fd61abd9b89d7a5d8a3"}}, 0}, {<<"aeserialization">>, {git,"https://github.com/aeternity/aeserialization.git", diff --git a/src/aeso_fcode_to_fate.erl b/src/aeso_fcode_to_fate.erl index ae53e42..c463485 100644 --- a/src/aeso_fcode_to_fate.erl +++ b/src/aeso_fcode_to_fate.erl @@ -128,7 +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 ], - 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() -> @@ -355,13 +356,13 @@ to_scode1(Env, {op, Ann, Op, Args}) -> to_scode1(Env, {'let', Ann, X, {var, _, Y}, Body}) -> 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}) -> {I, Env1} = bind_local(X, Env), - [ dbgloc(Env, Ann), - to_scode(notail(Env), Expr), - aeb_fate_ops:store({var, I}, {stack, 0}), - to_scode(Env1, Body) ]; + SCode = [ to_scode(notail(Env), Expr), + aeb_fate_ops:store({var, I}, {stack, 0}), + 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}) -> %% Tail-call to current function, f(e0..en). Compile to @@ -774,6 +775,26 @@ dbgloc(Env, Ann) -> 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 --------------------------------------------------------------- %% Optimize @@ -910,6 +931,8 @@ attributes(I) -> switch_body -> Pure(none, []); 'RETURN' -> Impure(pc, []); {'DBGLOC', _, _, _} -> Pure(none, []); + {'DBG_DEF', _, _} -> Pure(none, []); + {'DBG_UNDEF', _, _} -> Pure(none, []); {'RETURNR', A} -> Impure(pc, A); {'CALL', A} -> Impure(?a, [A]); {'CALL_R', A, _, B, C, D} -> Impure(?a, [A, B, C, D]);