mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add eWasm externals.
This commit is contained in:
@@ -65,6 +65,8 @@ WasmDialect::WasmDialect():
|
||||
|
||||
addFunction("datasize", 1, 4, true, true);
|
||||
addFunction("dataoffset", 1, 4, true, true);
|
||||
|
||||
addEthereumExternals();
|
||||
}
|
||||
|
||||
BuiltinFunction const* WasmDialect::builtin(YulString _name) const
|
||||
@@ -85,6 +87,69 @@ WasmDialect const& WasmDialect::instance()
|
||||
return *dialect;
|
||||
}
|
||||
|
||||
void WasmDialect::addEthereumExternals()
|
||||
{
|
||||
// These are not YulStrings because that would be too complicated with regards
|
||||
// to the YulStringRepository reset.
|
||||
static string const i64{"i64"};
|
||||
static string const i32{"i32"};
|
||||
static string const i32ptr{"i32"}; // Uses "i32" on purpose.
|
||||
struct External { string name; vector<string> parameters; vector<string> returns; };
|
||||
static vector<External> externals{
|
||||
{"getAddress", {i32ptr}, {}},
|
||||
{"getExternalBalance", {i32ptr, i32ptr}, {}},
|
||||
{"getBlockHash", {i64, i32ptr}, {i32}},
|
||||
{"call", {i64, i32ptr, i32ptr, i32ptr, i32}, {i32}},
|
||||
{"callDataCopy", {i32ptr, i32, i32}, {}},
|
||||
{"getCallDataSize", {}, {i32}},
|
||||
{"callCode", {i64, i32ptr, i32ptr, i32ptr, i32}, {i32}},
|
||||
{"callDelegate", {i64, i32ptr, i32ptr, i32}, {i32}},
|
||||
{"callStatic", {i64, i32ptr, i32ptr, i32}, {i32}},
|
||||
{"storageStore", {i32ptr, i32ptr}, {}},
|
||||
{"storageLoad", {i32ptr, i32ptr}, {}},
|
||||
{"getCaller", {i32ptr}, {}},
|
||||
{"getCallValue", {i32ptr}, {}},
|
||||
{"codeCopy", {i32ptr, i32, i32}, {}},
|
||||
{"getCodeSize", {i32ptr}, {}},
|
||||
{"getBlockCoinbase", {i32ptr}, {}},
|
||||
{"create", {i32ptr, i32ptr, i32, i32ptr}, {i32}},
|
||||
{"getBlockDifficulty", {i32ptr}, {}},
|
||||
{"externalCodeCopy", {i32ptr, i32ptr, i32, i32}, {}},
|
||||
{"getExternalCodeSize", {i32ptr}, {i32}},
|
||||
{"getGasLeft", {}, {i64}},
|
||||
{"getBlockGasLimit", {}, {i64}},
|
||||
{"getTxGasPrice", {i32ptr}, {}},
|
||||
{"log", {i32ptr, i32, i32, i32ptr, i32ptr, i32ptr, i32ptr}, {}},
|
||||
{"getBlockNumber", {}, {i64}},
|
||||
{"getTxOrigin", {i32ptr}, {}},
|
||||
{"finish", {i32ptr, i32}, {}},
|
||||
{"revert", {i32ptr, i32}, {}},
|
||||
{"getReturnDataSize", {}, {i32}},
|
||||
{"returnDataCopy", {i32ptr, i32, i32}, {}},
|
||||
{"selfDestruct", {i32ptr}, {}},
|
||||
{"getBlockTimestamp", {}, {i64}}
|
||||
};
|
||||
for (External const& ext: externals)
|
||||
{
|
||||
YulString name{"eth." + ext.name};
|
||||
BuiltinFunction& f = m_functions[name];
|
||||
f.name = name;
|
||||
for (string const& p: ext.parameters)
|
||||
f.parameters.emplace_back(YulString(p));
|
||||
for (string const& p: ext.returns)
|
||||
f.returns.emplace_back(YulString(p));
|
||||
f.movable = false;
|
||||
// TODO some of them are side effect free.
|
||||
f.sideEffectFree = false;
|
||||
f.sideEffectFreeIfNoMSize = false;
|
||||
f.isMSize = false;
|
||||
f.invalidatesStorage = (ext.name == "storageStore");
|
||||
// TODO some of them do not invalidate memory
|
||||
f.invalidatesMemory = true;
|
||||
f.literalArguments = false;
|
||||
}
|
||||
}
|
||||
|
||||
void WasmDialect::addFunction(
|
||||
string _name,
|
||||
size_t _params,
|
||||
|
||||
Reference in New Issue
Block a user