Note function entry points.

This commit is contained in:
chriseth
2021-05-04 17:15:13 +02:00
parent faca036837
commit f9c94d7c42
33 changed files with 252 additions and 26 deletions
+18 -2
View File
@@ -148,7 +148,7 @@ void CompilerContext::callYulFunction(
m_externallyUsedYulFunctions.insert(_name);
auto const retTag = pushNewTag();
CompilerUtils(*this).moveIntoStack(_inArgs);
appendJumpTo(namedTag(_name), evmasm::AssemblyItem::JumpType::IntoFunction);
appendJumpTo(namedTag(_name, _inArgs, _outArgs, {}), evmasm::AssemblyItem::JumpType::IntoFunction);
adjustStackOffset(static_cast<int>(_outArgs) - 1 - static_cast<int>(_inArgs));
*this << retTag.tag();
}
@@ -596,7 +596,23 @@ evmasm::AssemblyItem CompilerContext::FunctionCompilationQueue::entryLabel(
auto res = m_entryLabels.find(&_declaration);
if (res == m_entryLabels.end())
{
evmasm::AssemblyItem tag(_context.newTag());
size_t params = 0;
size_t returns = 0;
if (auto const* function = dynamic_cast<FunctionDefinition const*>(&_declaration))
{
FunctionType functionType(*function, FunctionType::Kind::Internal);
params = CompilerUtils::sizeOnStack(functionType.parameterTypes());
returns = CompilerUtils::sizeOnStack(functionType.returnParameterTypes());
}
// some name that cannot clash with yul function names.
string labelName = "@" + _declaration.name() + "_" + to_string(_declaration.id());
evmasm::AssemblyItem tag = _context.namedTag(
labelName,
params,
returns,
_declaration.id()
);
m_entryLabels.insert(make_pair(&_declaration, tag));
m_functionsToCompile.push(&_declaration);
return tag.tag();
+4 -1
View File
@@ -216,7 +216,10 @@ public:
/// @returns a new tag without pushing any opcodes or data
evmasm::AssemblyItem newTag() { return m_asm->newTag(); }
/// @returns a new tag identified by name.
evmasm::AssemblyItem namedTag(std::string const& _name) { return m_asm->namedTag(_name); }
evmasm::AssemblyItem namedTag(std::string const& _name, size_t _params, size_t _returns, std::optional<uint64_t> _sourceID)
{
return m_asm->namedTag(_name, _params, _returns, _sourceID);
}
/// Adds a subroutine to the code (in the data section) and pushes its size (via a tag)
/// on the stack. @returns the pushsub assembly item.
evmasm::AssemblyItem addSubroutine(evmasm::AssemblyPointer const& _assembly) { return m_asm->appendSubroutine(_assembly); }