mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move generation of builtin functions to helper.
This commit is contained in:
parent
7de150924c
commit
9a387380b3
@ -35,18 +35,40 @@ using namespace std;
|
||||
using namespace dev;
|
||||
using namespace yul;
|
||||
|
||||
EVMDialect::EVMDialect(AsmFlavour _flavour, bool _objectAccess, langutil::EVMVersion _evmVersion):
|
||||
Dialect{_flavour}, m_objectAccess(_objectAccess), m_evmVersion(_evmVersion)
|
||||
namespace
|
||||
{
|
||||
// The EVM instructions will be moved to builtins at some point.
|
||||
if (!m_objectAccess)
|
||||
return;
|
||||
pair<YulString, BuiltinFunctionForEVM> createFunction(
|
||||
string _name,
|
||||
size_t _params,
|
||||
size_t _returns,
|
||||
bool _movable,
|
||||
bool _sideEffectFree,
|
||||
bool _literalArguments,
|
||||
std::function<void(FunctionCall const&, AbstractAssembly&, BuiltinContext&, std::function<void()>)> _generateCode
|
||||
)
|
||||
{
|
||||
YulString name{std::move(_name)};
|
||||
BuiltinFunctionForEVM f;
|
||||
f.name = name;
|
||||
f.parameters.resize(_params);
|
||||
f.returns.resize(_returns);
|
||||
f.movable = _movable;
|
||||
f.literalArguments = _literalArguments;
|
||||
f.sideEffectFree = _sideEffectFree;
|
||||
f.generateCode = std::move(_generateCode);
|
||||
return {name, f};
|
||||
}
|
||||
|
||||
addFunction("datasize", 1, 1, true, true, true, [](
|
||||
map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion, bool _objectAccess)
|
||||
{
|
||||
map<YulString, BuiltinFunctionForEVM> builtins;
|
||||
if (_objectAccess)
|
||||
{
|
||||
builtins.emplace(createFunction("datasize", 1, 1, true, true, true, [](
|
||||
FunctionCall const& _call,
|
||||
AbstractAssembly& _assembly,
|
||||
BuiltinContext& _context,
|
||||
std::function<void()>
|
||||
function<void()>
|
||||
) {
|
||||
yulAssert(_context.currentObject, "No object available.");
|
||||
yulAssert(_call.arguments.size() == 1, "");
|
||||
@ -62,8 +84,8 @@ EVMDialect::EVMDialect(AsmFlavour _flavour, bool _objectAccess, langutil::EVMVer
|
||||
);
|
||||
_assembly.appendDataSize(_context.subIDs.at(dataName));
|
||||
}
|
||||
});
|
||||
addFunction("dataoffset", 1, 1, true, true, true, [](
|
||||
}));
|
||||
builtins.emplace(createFunction("dataoffset", 1, 1, true, true, true, [](
|
||||
FunctionCall const& _call,
|
||||
AbstractAssembly& _assembly,
|
||||
BuiltinContext& _context,
|
||||
@ -83,8 +105,8 @@ EVMDialect::EVMDialect(AsmFlavour _flavour, bool _objectAccess, langutil::EVMVer
|
||||
);
|
||||
_assembly.appendDataOffset(_context.subIDs.at(dataName));
|
||||
}
|
||||
});
|
||||
addFunction("datacopy", 3, 0, false, false, false, [](
|
||||
}));
|
||||
builtins.emplace(createFunction("datacopy", 3, 0, false, false, false, [](
|
||||
FunctionCall const&,
|
||||
AbstractAssembly& _assembly,
|
||||
BuiltinContext&,
|
||||
@ -92,7 +114,19 @@ EVMDialect::EVMDialect(AsmFlavour _flavour, bool _objectAccess, langutil::EVMVer
|
||||
) {
|
||||
_visitArguments();
|
||||
_assembly.appendInstruction(dev::eth::Instruction::CODECOPY);
|
||||
});
|
||||
}));
|
||||
}
|
||||
return builtins;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
EVMDialect::EVMDialect(AsmFlavour _flavour, bool _objectAccess, langutil::EVMVersion _evmVersion):
|
||||
Dialect{_flavour},
|
||||
m_objectAccess(_objectAccess),
|
||||
m_evmVersion(_evmVersion),
|
||||
m_functions(createBuiltins(_evmVersion, _objectAccess))
|
||||
{
|
||||
}
|
||||
|
||||
BuiltinFunctionForEVM const* EVMDialect::builtin(YulString _name) const
|
||||
@ -123,24 +157,3 @@ shared_ptr<yul::EVMDialect> EVMDialect::yulForEVM(langutil::EVMVersion _version)
|
||||
{
|
||||
return make_shared<EVMDialect>(AsmFlavour::Yul, false, _version);
|
||||
}
|
||||
|
||||
void EVMDialect::addFunction(
|
||||
string _name,
|
||||
size_t _params,
|
||||
size_t _returns,
|
||||
bool _movable,
|
||||
bool _sideEffectFree,
|
||||
bool _literalArguments,
|
||||
std::function<void(FunctionCall const&, AbstractAssembly&, BuiltinContext&, std::function<void()>)> _generateCode
|
||||
)
|
||||
{
|
||||
YulString name{std::move(_name)};
|
||||
BuiltinFunctionForEVM& f = m_functions[name];
|
||||
f.name = name;
|
||||
f.parameters.resize(_params);
|
||||
f.returns.resize(_returns);
|
||||
f.movable = _movable;
|
||||
f.sideEffectFree = _sideEffectFree;
|
||||
f.literalArguments = _literalArguments;
|
||||
f.generateCode = std::move(_generateCode);
|
||||
}
|
||||
|
@ -76,18 +76,8 @@ struct EVMDialect: public Dialect
|
||||
bool providesObjectAccess() const { return m_objectAccess; }
|
||||
|
||||
protected:
|
||||
void addFunction(
|
||||
std::string _name,
|
||||
size_t _params,
|
||||
size_t _returns,
|
||||
bool _movable,
|
||||
bool _sideEffectFree,
|
||||
bool _literalArguments,
|
||||
std::function<void(FunctionCall const&, AbstractAssembly&, BuiltinContext&, std::function<void()>)> _generateCode
|
||||
);
|
||||
|
||||
bool m_objectAccess;
|
||||
langutil::EVMVersion m_evmVersion;
|
||||
bool const m_objectAccess;
|
||||
langutil::EVMVersion const m_evmVersion;
|
||||
std::map<YulString, BuiltinFunctionForEVM> m_functions;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user