Make api function for exposing gas costs of ops
This commit is contained in:
parent
5e16b85ae2
commit
69912db2b6
@ -210,6 +210,7 @@ generate_opcodes_ops(Modulename, HrlFile, SrcDir, Ops) ->
|
|||||||
EndBB = lists:flatten([gen_bb(Op) || Op <- Ops]),
|
EndBB = lists:flatten([gen_bb(Op) || Op <- Ops]),
|
||||||
InAuth = lists:flatten([gen_in_auth(Op) || Op <- Ops]),
|
InAuth = lists:flatten([gen_in_auth(Op) || Op <- Ops]),
|
||||||
Offchain = lists:flatten([gen_allowed_offchain(Op) || Op <- Ops]),
|
Offchain = lists:flatten([gen_allowed_offchain(Op) || Op <- Ops]),
|
||||||
|
GasCost = lists:flatten([gen_gas_cost(Op) || Op <- Ops]),
|
||||||
|
|
||||||
io:format(File, "~s", [prelude("Provides opcode primitives.\n")]),
|
io:format(File, "~s", [prelude("Provides opcode primitives.\n")]),
|
||||||
io:format(File, "~s", [ops_exports(Modulename, HrlFile,
|
io:format(File, "~s", [ops_exports(Modulename, HrlFile,
|
||||||
@ -219,6 +220,7 @@ generate_opcodes_ops(Modulename, HrlFile, SrcDir, Ops) ->
|
|||||||
" , allowed_offchain/1\n"
|
" , allowed_offchain/1\n"
|
||||||
" , mnemonic/1\n"
|
" , mnemonic/1\n"
|
||||||
" , m_to_op/1\n"
|
" , m_to_op/1\n"
|
||||||
|
" , gas_cost/1\n"
|
||||||
])]),
|
])]),
|
||||||
|
|
||||||
io:format(File, "%% FATE mnemonics\n~s", [Mnemonic]),
|
io:format(File, "%% FATE mnemonics\n~s", [Mnemonic]),
|
||||||
@ -239,6 +241,9 @@ generate_opcodes_ops(Modulename, HrlFile, SrcDir, Ops) ->
|
|||||||
io:format(File, "%% Is FATE Op allowed in a state channel offchain context?\n~s", [Offchain]),
|
io:format(File, "%% Is FATE Op allowed in a state channel offchain context?\n~s", [Offchain]),
|
||||||
io:format(File, "allowed_offchain(_) -> false.\n\n", []),
|
io:format(File, "allowed_offchain(_) -> false.\n\n", []),
|
||||||
|
|
||||||
|
io:format(File, "%% Base cost of operation\n~s", [GasCost]),
|
||||||
|
io:format(File, "gas_cost(Op) -> exit({bad_opcode, Op}).\n\n", []),
|
||||||
|
|
||||||
file:close(File).
|
file:close(File).
|
||||||
|
|
||||||
generate_code_ops(Modulename, SrcDir, Ops) ->
|
generate_code_ops(Modulename, SrcDir, Ops) ->
|
||||||
@ -382,6 +387,10 @@ gen_allowed_offchain(#{macro := Macro, offchain := Offchain}) ->
|
|||||||
lists:flatten(io_lib:format("allowed_offchain(~24s) -> ~w ;\n",
|
lists:flatten(io_lib:format("allowed_offchain(~24s) -> ~w ;\n",
|
||||||
[Macro, Offchain])).
|
[Macro, Offchain])).
|
||||||
|
|
||||||
|
gen_gas_cost(#{macro := Macro, gas := Gas}) ->
|
||||||
|
lists:flatten(io_lib:format("gas_cost(~24s) -> ~w ;\n",
|
||||||
|
[Macro, Gas])).
|
||||||
|
|
||||||
prelude(Doc) ->
|
prelude(Doc) ->
|
||||||
"%%%-------------------------------------------------------------------\n"
|
"%%%-------------------------------------------------------------------\n"
|
||||||
"%%% @copyright (C) 2019, Aeternity Anstalt\n"
|
"%%% @copyright (C) 2019, Aeternity Anstalt\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user