mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow inserting low-level functions without calling them.
This commit is contained in:
parent
390bebaaf9
commit
d9fbb83861
@ -70,19 +70,30 @@ void CompilerContext::callLowLevelFunction(
|
|||||||
eth::AssemblyItem retTag = pushNewTag();
|
eth::AssemblyItem retTag = pushNewTag();
|
||||||
CompilerUtils(*this).moveIntoStack(_inArgs);
|
CompilerUtils(*this).moveIntoStack(_inArgs);
|
||||||
|
|
||||||
|
*this << lowLevelFunctionTag(_name, _inArgs, _outArgs, _generator);
|
||||||
|
|
||||||
|
appendJump(eth::AssemblyItem::JumpType::IntoFunction);
|
||||||
|
adjustStackOffset(int(_outArgs) - 1 - _inArgs);
|
||||||
|
*this << retTag.tag();
|
||||||
|
}
|
||||||
|
|
||||||
|
eth::AssemblyItem CompilerContext::lowLevelFunctionTag(
|
||||||
|
string const& _name,
|
||||||
|
unsigned _inArgs,
|
||||||
|
unsigned _outArgs,
|
||||||
|
function<void(CompilerContext&)> const& _generator
|
||||||
|
)
|
||||||
|
{
|
||||||
auto it = m_lowLevelFunctions.find(_name);
|
auto it = m_lowLevelFunctions.find(_name);
|
||||||
if (it == m_lowLevelFunctions.end())
|
if (it == m_lowLevelFunctions.end())
|
||||||
{
|
{
|
||||||
eth::AssemblyItem tag = newTag().pushTag();
|
eth::AssemblyItem tag = newTag().pushTag();
|
||||||
m_lowLevelFunctions.insert(make_pair(_name, tag));
|
m_lowLevelFunctions.insert(make_pair(_name, tag));
|
||||||
m_lowLevelFunctionGenerationQueue.push(make_tuple(_name, _inArgs, _outArgs, _generator));
|
m_lowLevelFunctionGenerationQueue.push(make_tuple(_name, _inArgs, _outArgs, _generator));
|
||||||
*this << tag;
|
return tag;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*this << it->second;
|
return it->second;
|
||||||
appendJump(eth::AssemblyItem::JumpType::IntoFunction);
|
|
||||||
adjustStackOffset(int(_outArgs) - 1 - _inArgs);
|
|
||||||
*this << retTag.tag();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerContext::appendMissingLowLevelFunctions()
|
void CompilerContext::appendMissingLowLevelFunctions()
|
||||||
|
@ -104,6 +104,16 @@ public:
|
|||||||
unsigned _outArgs,
|
unsigned _outArgs,
|
||||||
std::function<void(CompilerContext&)> const& _generator
|
std::function<void(CompilerContext&)> const& _generator
|
||||||
);
|
);
|
||||||
|
/// Returns the tag of the named low-level function and inserts the generator into the
|
||||||
|
/// list of low-level-functions to be generated, unless it already exists.
|
||||||
|
/// Note that the generator should not assume that objects are still alive when it is called,
|
||||||
|
/// unless they are guaranteed to be alive for the whole run of the compiler (AST nodes, for example).
|
||||||
|
eth::AssemblyItem lowLevelFunctionTag(
|
||||||
|
std::string const& _name,
|
||||||
|
unsigned _inArgs,
|
||||||
|
unsigned _outArgs,
|
||||||
|
std::function<void(CompilerContext&)> const& _generator
|
||||||
|
);
|
||||||
/// Generates the code for missing low-level functions, i.e. calls the generators passed above.
|
/// Generates the code for missing low-level functions, i.e. calls the generators passed above.
|
||||||
void appendMissingLowLevelFunctions();
|
void appendMissingLowLevelFunctions();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user