Add default init function in fcode pass instead of in assembler

This commit is contained in:
Ulf Norell
2019-08-21 11:41:19 +02:00
parent cfd036b199
commit cbc8909954
2 changed files with 29 additions and 29 deletions
+1 -18
View File
@@ -130,12 +130,10 @@ debug(Tag, Options, Fmt, Args) ->
%% @doc Main entry point.
compile(FCode, Options) ->
#{ contract_name := ContractName,
state_type := StateType,
functions := Functions } = FCode,
SFuns = functions_to_scode(ContractName, Functions, Options),
SFuns1 = optimize_scode(SFuns, Options),
SFuns2 = add_default_init_function(SFuns1, StateType),
FateCode = to_basic_blocks(SFuns2),
FateCode = to_basic_blocks(SFuns1),
debug(compile, Options, "~s\n", [aeb_fate_asm:pp(FateCode)]),
FateCode.
@@ -196,21 +194,6 @@ type_to_scode({tvar, X}) ->
J -> {tvar, J}
end.
add_default_init_function(SFuns, StateType) when StateType /= {tuple, []} ->
%% Only add default if the type is unit.
SFuns;
add_default_init_function(SFuns, {tuple, []}) ->
%% Only add default if the init function is not present
InitName = make_function_name({entrypoint, <<"init">>}),
case maps:find(InitName, SFuns) of
{ok, _} ->
SFuns;
error ->
Sig = {[], {tuple, []}},
Body = [tuple(0)],
SFuns#{ InitName => {[], Sig, Body} }
end.
%% -- Phase I ----------------------------------------------------------------
%% Icode to structured assembly