Return mapping from variables to registers in fate compilation #902
@ -115,7 +115,7 @@ from_string1(ContractString, Options) ->
|
|||||||
, fcode_env := #{child_con_env := ChildContracts}
|
, fcode_env := #{child_con_env := ChildContracts}
|
||||||
, folded_typed_ast := FoldedTypedAst
|
, folded_typed_ast := FoldedTypedAst
|
||||||
, warnings := Warnings } = string_to_code(ContractString, Options),
|
, warnings := Warnings } = string_to_code(ContractString, Options),
|
||||||
FateCode = aeso_fcode_to_fate:compile(ChildContracts, FCode, Options),
|
{FateCode, VarsRegs} = aeso_fcode_to_fate:compile(ChildContracts, FCode, Options),
|
||||||
pp_assembler(FateCode, Options),
|
pp_assembler(FateCode, Options),
|
||||||
ByteCode = aeb_fate_code:serialize(FateCode, []),
|
ByteCode = aeb_fate_code:serialize(FateCode, []),
|
||||||
{ok, Version} = version(),
|
{ok, Version} = version(),
|
||||||
@ -126,6 +126,7 @@ from_string1(ContractString, Options) ->
|
|||||||
fate_code => FateCode,
|
fate_code => FateCode,
|
||||||
abi_version => aeb_fate_abi:abi_version(),
|
abi_version => aeb_fate_abi:abi_version(),
|
||||||
payable => maps:get(payable, FCode),
|
payable => maps:get(payable, FCode),
|
||||||
|
variables_registers => VarsRegs,
|
||||||
warnings => Warnings
|
warnings => Warnings
|
||||||
},
|
},
|
||||||
{ok, maybe_generate_aci(Res, FoldedTypedAst, Options)}.
|
{ok, maybe_generate_aci(Res, FoldedTypedAst, Options)}.
|
||||||
@ -185,7 +186,7 @@ check_call1(ContractString0, FunName, Args, Options) ->
|
|||||||
#{fcode := OrgFcode
|
#{fcode := OrgFcode
|
||||||
, fcode_env := #{child_con_env := ChildContracts}
|
, fcode_env := #{child_con_env := ChildContracts}
|
||||||
, ast := Ast} = string_to_code(ContractString0, Options),
|
, ast := Ast} = string_to_code(ContractString0, Options),
|
||||||
FateCode = aeso_fcode_to_fate:compile(ChildContracts, OrgFcode, []),
|
{FateCode, _VarsRegs} = aeso_fcode_to_fate:compile(ChildContracts, OrgFcode, []),
|
||||||
%% collect all hashes and compute the first name without hash collision to
|
%% collect all hashes and compute the first name without hash collision to
|
||||||
SymbolHashes = maps:keys(aeb_fate_code:symbols(FateCode)),
|
SymbolHashes = maps:keys(aeb_fate_code:symbols(FateCode)),
|
||||||
CallName = first_none_match(?CALL_NAME, SymbolHashes,
|
CallName = first_none_match(?CALL_NAME, SymbolHashes,
|
||||||
|
@ -76,13 +76,18 @@ compile(FCode, Options) ->
|
|||||||
compile(ChildContracts, FCode, Options) ->
|
compile(ChildContracts, FCode, Options) ->
|
||||||
#{ contract_name := ContractName,
|
#{ contract_name := ContractName,
|
||||||
functions := Functions } = FCode,
|
functions := Functions } = FCode,
|
||||||
SFuns = functions_to_scode(ChildContracts, ContractName, Functions, Options),
|
try
|
||||||
SFuns1 = optimize_scode(SFuns, Options),
|
SFuns = functions_to_scode(ChildContracts, ContractName, Functions, Options),
|
||||||
FateCode = to_basic_blocks(SFuns1),
|
SFuns1 = optimize_scode(SFuns, Options),
|
||||||
?debug(compile, Options, "~s\n", [aeb_fate_asm:pp(FateCode)]),
|
FateCode = to_basic_blocks(SFuns1),
|
||||||
case proplists:get_value(include_child_contract_symbols, Options, false) of
|
?debug(compile, Options, "~s\n", [aeb_fate_asm:pp(FateCode)]),
|
||||||
false -> FateCode;
|
FateCode1 = case proplists:get_value(include_child_contract_symbols, Options, false) of
|
||||||
true -> add_child_symbols(ChildContracts, FateCode)
|
false -> FateCode;
|
||||||
|
true -> add_child_symbols(ChildContracts, FateCode)
|
||||||
|
end,
|
||||||
|
{FateCode1, get_variables_registers()}
|
||||||
|
after
|
||||||
|
put(variables_registers, undefined)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
make_function_id(X) ->
|
make_function_id(X) ->
|
||||||
@ -110,9 +115,21 @@ function_to_scode(ChildContracts, ContractName, Functions, Name, Attrs0, Args, B
|
|||||||
{ArgTypes, ResType1} = typesig_to_scode(Args, ResType),
|
{ArgTypes, ResType1} = typesig_to_scode(Args, ResType),
|
||||||
Attrs = Attrs0 -- [stateful], %% Only track private and payable from here.
|
Attrs = Attrs0 -- [stateful], %% Only track private and payable from here.
|
||||||
Env = init_env(ChildContracts, ContractName, Functions, Name, Args, Options),
|
Env = init_env(ChildContracts, ContractName, Functions, Name, Args, Options),
|
||||||
|
[ add_variables_register(Env, Arg, Register) || {Arg, Register} <- Env#env.vars ],
|
||||||
SCode = to_scode(Env, Body),
|
SCode = to_scode(Env, Body),
|
||||||
{Attrs, {ArgTypes, ResType1}, SCode}.
|
{Attrs, {ArgTypes, ResType1}, SCode}.
|
||||||
|
|
||||||
|
get_variables_registers() ->
|
||||||
|
case get(variables_registers) of
|
||||||
|
undefined -> [];
|
||||||
|
Vs -> Vs
|
||||||
|
end.
|
||||||
|
|
||||||
|
add_variables_register(Env, Name, Register) ->
|
||||||
|
Olds = get_variables_registers(),
|
||||||
|
New = {Env#env.contract, Env#env.current_function, Name, Register},
|
||||||
|
put(variables_registers, [New | Olds]).
|
||||||
|
|
||||||
-define(tvars, '$tvars').
|
-define(tvars, '$tvars').
|
||||||
|
|
||||||
typesig_to_scode(Args, Res) ->
|
typesig_to_scode(Args, Res) ->
|
||||||
@ -170,6 +187,7 @@ next_var(#env{ vars = Vars }) ->
|
|||||||
1 + lists:max([-1 | [J || {_, {var, J}} <- Vars]]).
|
1 + lists:max([-1 | [J || {_, {var, J}} <- Vars]]).
|
||||||
|
|
||||||
bind_var(Name, Var, Env = #env{ vars = Vars }) ->
|
bind_var(Name, Var, Env = #env{ vars = Vars }) ->
|
||||||
|
add_variables_register(Env, Name, Var),
|
||||||
Env#env{ vars = [{Name, Var} | Vars] }.
|
Env#env{ vars = [{Name, Var} | Vars] }.
|
||||||
|
|
||||||
bind_local(Name, Env) ->
|
bind_local(Name, Env) ->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user