From c1bf0630938ed5bee38aaf3ec4b4851b410dd3df Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Sat, 24 Dec 2022 17:52:32 +0300 Subject: [PATCH] Fix dbg_undef for args --- rebar.config | 2 +- rebar.lock | 2 +- src/aeso_fcode_to_fate.erl | 40 ++++++++++++++++++++++++++++++-------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/rebar.config b/rebar.config index 61b8900..82c9b38 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, "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"}}} diff --git a/rebar.lock b/rebar.lock index 31addd9..131b465 100644 --- a/rebar.lock +++ b/rebar.lock @@ -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", diff --git a/src/aeso_fcode_to_fate.erl b/src/aeso_fcode_to_fate.erl index bc6e948..2ecde9e 100644 --- a/src/aeso_fcode_to_fate.erl +++ b/src/aeso_fcode_to_fate.erl @@ -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 -> - Def = [{'DBG_DEF', {immediate, VarName}, Register}], - Undef = [{'DBG_UNDEF', {immediate, VarName}, Register}], - Def ++ SCode ++ Undef + Register = lookup_var(Env, Var), + Def = [{'DBG_DEF', {immediate, VarName}, Register}], + Undef = [{'DBG_UNDEF', {immediate, VarName}, Register}], + 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