From 4c2288274d0103c451fb1aebe98742bbd4346afd Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Mon, 29 Apr 2019 12:40:19 +0200 Subject: [PATCH] no-op fcode optimization pass --- src/aeso_ast_to_fcode.erl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/aeso_ast_to_fcode.erl b/src/aeso_ast_to_fcode.erl index 916d70a..ccc4baa 100644 --- a/src/aeso_ast_to_fcode.erl +++ b/src/aeso_ast_to_fcode.erl @@ -116,7 +116,7 @@ %% and produces Fate intermediate code. -spec ast_to_fcode(aeso_syntax:ast(), [option()]) -> fcode(). ast_to_fcode(Code, Options) -> - to_fcode(init_env(Options), Code). + optimize_fcode(to_fcode(init_env(Options), Code)). %% -- Environment ------------------------------------------------------------ @@ -657,10 +657,18 @@ stmts_to_fcode(Env, [Expr]) -> %% - Translate && and || to ifte %% - Deadcode elimination %% - Unused variable analysis (replace by _) -%% - Simplified case trees (FATE has special instructions for shallow matching) %% - Case specialization %% - Constant propagation +-spec optimize_fcode(fcode()) -> fcode(). +optimize_fcode(Code = #{ functions := Funs }) -> + Code#{ functions := maps:map(fun(Name, Def) -> optimize_fun(Code, Name, Def) end, Funs) }. + +-spec optimize_fun(fcode(), fun_name(), fun_def()) -> fun_def(). +optimize_fun(_Fcode, _Fun, Def = #{ body := _Body }) -> + %% io:format("Optimizing ~p =\n~s\n", [Fun, prettypr:format(pp_fexpr(Body))]), + Def. + %% -- Helper functions ------------------------------------------------------- %% -- Types --