Nicer debug printing
This commit is contained in:
parent
e224aadff7
commit
185487afda
@ -184,15 +184,29 @@ flatten_s(I) -> I.
|
|||||||
optimize_fun(_Funs, Name, {{Args, Res}, Code}, Options) ->
|
optimize_fun(_Funs, Name, {{Args, Res}, Code}, Options) ->
|
||||||
Code0 = flatten(Code),
|
Code0 = flatten(Code),
|
||||||
debug(Options, "Optimizing ~s\n", [Name]),
|
debug(Options, "Optimizing ~s\n", [Name]),
|
||||||
debug(Options, " original : ~p\n", [Code0]),
|
|
||||||
ACode = annotate_code(Code0),
|
ACode = annotate_code(Code0),
|
||||||
debug(Options, " annotated : ~p\n", [ACode]),
|
debug(Options, " original:\n~s\n", [pp_ann(" ", ACode)]),
|
||||||
Code1 = simplify(ACode),
|
Code1 = simplify(ACode),
|
||||||
debug(Options, " simplified: ~p\n", [Code1]),
|
debug(Options, " optimized:\n~s\n", [pp_ann(" ", Code1)]),
|
||||||
Code2 = desugar(Code1),
|
Code2 = desugar(Code1),
|
||||||
debug(Options, " desugared : ~p\n", [Code2]),
|
|
||||||
{{Args, Res}, Code2}.
|
{{Args, Res}, Code2}.
|
||||||
|
|
||||||
|
pp_ann(Ind, [{ifte, Then, Else} | Code]) ->
|
||||||
|
[Ind, "IF-THEN\n",
|
||||||
|
pp_ann(" " ++ Ind, Then),
|
||||||
|
Ind, "ELSE\n",
|
||||||
|
pp_ann(" " ++ Ind, Else),
|
||||||
|
pp_ann(Ind, Code)];
|
||||||
|
pp_ann(Ind, [{#{ live_in := In, live_out := Out }, I} | Code]) ->
|
||||||
|
Fmt = fun([]) -> "()";
|
||||||
|
(Xs) -> string:join([lists:concat(["var", N]) || {var, N} <- Xs], " ")
|
||||||
|
end,
|
||||||
|
Op = [Ind, aeb_fate_pp:format_op(I, #{})],
|
||||||
|
Ann = [[" % ", Fmt(In), " -> ", Fmt(Out)] || In ++ Out /= []],
|
||||||
|
[io_lib:format("~-40s~s\n", [Op, Ann]),
|
||||||
|
pp_ann(Ind, Code)];
|
||||||
|
pp_ann(_, []) -> [].
|
||||||
|
|
||||||
%% -- Analysis --
|
%% -- Analysis --
|
||||||
|
|
||||||
annotate_code(Code) ->
|
annotate_code(Code) ->
|
||||||
@ -436,7 +450,6 @@ simpl_top2(I = {Ann, {Op, R = {var, _}, A, B}}, Code) when ?IsBinOp(Op) ->
|
|||||||
%% Subtle: we still have to pop the stack if any of the arguments
|
%% Subtle: we still have to pop the stack if any of the arguments
|
||||||
%% came from there. In this case we pop to R, which we know is
|
%% came from there. In this case we pop to R, which we know is
|
||||||
%% unused.
|
%% unused.
|
||||||
io:format("Removing write to dead var: ~p\n", [I]),
|
|
||||||
lists:foldr(fun simpl_top/2, Code,
|
lists:foldr(fun simpl_top/2, Code,
|
||||||
[{Ann, {'POP', R}} || X <- [A, B], X == ?a]);
|
[{Ann, {'POP', R}} || X <- [A, B], X == ?a]);
|
||||||
true -> [I | Code]
|
true -> [I | Code]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user