Fix source location of builtin function calls.

This commit is contained in:
chriseth
2021-07-06 16:54:29 +02:00
parent 09578e7e22
commit 8d5e82b406
28 changed files with 81 additions and 60 deletions
+4 -6
View File
@@ -237,16 +237,14 @@ void CodeTransform::operator()(FunctionCall const& _call)
{
yulAssert(m_scope, "");
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_call.debugData));
if (BuiltinFunctionForEVM const* builtin = m_dialect.builtin(_call.functionName.name))
builtin->generateCode(_call, m_assembly, m_builtinContext, [&](Expression const& _expression) {
visitExpression(_expression);
});
else
{
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_call.debugData));
AbstractAssembly::LabelID returnLabel(numeric_limits<AbstractAssembly::LabelID>::max()); // only used for evm 1.0
returnLabel = m_assembly.newLabelId();
AbstractAssembly::LabelID returnLabel = m_assembly.newLabelId();
m_assembly.appendLabelReference(returnLabel);
Scope::Function* function = nullptr;
@@ -320,8 +318,6 @@ void CodeTransform::operator()(If const& _if)
void CodeTransform::operator()(Switch const& _switch)
{
//@TODO use JUMPV in EVM1.5?
visitExpression(*_switch.expression);
int expressionHeight = m_assembly.stackHeight();
map<Case const*, AbstractAssembly::LabelID> caseBodies;
@@ -416,6 +412,8 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
subTransform.setupReturnVariablesAndFunctionExit();
subTransform(_function.body);
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_function.debugData));
if (!subTransform.m_stackErrors.empty())
{
m_assembly.markAsInvalid();
+6
View File
@@ -163,6 +163,7 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
) {
yulAssert(_call.arguments.size() == 1, "");
Expression const& arg = _call.arguments.front();
_assembly.setSourceLocation(_call.debugData->location);
_assembly.appendLinkerSymbol(std::get<Literal>(arg).value.str());
}));
@@ -192,6 +193,7 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
yulAssert(_call.arguments.size() == 1, "");
Expression const& arg = _call.arguments.front();
YulString dataName = std::get<Literal>(arg).value;
_assembly.setSourceLocation(_call.debugData->location);
if (_context.currentObject->name == dataName)
_assembly.appendAssemblySize();
else
@@ -214,6 +216,7 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
yulAssert(_call.arguments.size() == 1, "");
Expression const& arg = _call.arguments.front();
YulString dataName = std::get<Literal>(arg).value;
_assembly.setSourceLocation(_call.debugData->location);
if (_context.currentObject->name == dataName)
_assembly.appendConstant(0);
else
@@ -276,6 +279,7 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
std::function<void(Expression const&)>
) {
yulAssert(_call.arguments.size() == 1, "");
_assembly.setSourceLocation(_call.debugData->location);
_assembly.appendImmutable(std::get<Literal>(_call.arguments.front()).value.str());
}
));
@@ -382,6 +386,8 @@ BuiltinFunctionForEVM const* EVMDialect::verbatimFunction(size_t _arguments, siz
for (Expression const& arg: _call.arguments | ranges::views::tail | ranges::views::reverse)
_visitExpression(arg);
Expression const& bytecode = _call.arguments.front();
_assembly.setSourceLocation(_call.debugData->location);
_assembly.appendVerbatim(
asBytes(std::get<Literal>(bytecode).value.str()),
_arguments,