Merge pull request #7604 from ethereum/datasizeOffsetSingle

[WASM] datasize and dataoffset only return a single value.
This commit is contained in:
chriseth
2019-11-01 15:39:50 +01:00
committed by GitHub
3 changed files with 53 additions and 28 deletions
+2 -2
View File
@@ -63,8 +63,8 @@ WasmDialect::WasmDialect():
m_functions["unreachable"_yulstring].sideEffects.invalidatesStorage = false;
m_functions["unreachable"_yulstring].sideEffects.invalidatesMemory = false;
addFunction("datasize", 1, 4, true, true);
addFunction("dataoffset", 1, 4, true, true);
addFunction("datasize", 1, 1, true, true);
addFunction("dataoffset", 1, 1, true, true);
addEthereumExternals();
}
@@ -87,6 +87,30 @@ void WordSizeTransform::operator()(Block& _block)
if (_s.type() == typeid(VariableDeclaration))
{
VariableDeclaration& varDecl = boost::get<VariableDeclaration>(_s);
// Special handling for datasize and dataoffset - they will only need one variable.
if (varDecl.value && varDecl.value->type() == typeid(FunctionCall))
if (BuiltinFunction const* f = m_inputDialect.builtin(boost::get<FunctionCall>(*varDecl.value).functionName.name))
if (f->literalArguments)
{
yulAssert(f->name == "datasize"_yulstring || f->name == "dataoffset"_yulstring, "");
yulAssert(varDecl.variables.size() == 1, "");
auto newLhs = generateU64IdentifierNames(varDecl.variables[0].name);
vector<Statement> ret;
for (int i = 0; i < 3; i++)
ret.push_back(VariableDeclaration{
varDecl.location,
{TypedName{varDecl.location, newLhs[i], "u64"_yulstring}},
make_unique<Expression>(Literal{locationOf(*varDecl.value), LiteralKind::Number, "0"_yulstring, "u64"_yulstring})
});
ret.push_back(VariableDeclaration{
varDecl.location,
{TypedName{varDecl.location, newLhs[3], "u64"_yulstring}},
std::move(varDecl.value)
});
return {std::move(ret)};
}
if (
!varDecl.value ||
varDecl.value->type() == typeid(FunctionalInstruction) ||
@@ -123,6 +147,30 @@ void WordSizeTransform::operator()(Block& _block)
{
Assignment& assignment = boost::get<Assignment>(_s);
yulAssert(assignment.value, "");
// Special handling for datasize and dataoffset - they will only need one variable.
if (assignment.value->type() == typeid(FunctionCall))
if (BuiltinFunction const* f = m_inputDialect.builtin(boost::get<FunctionCall>(*assignment.value).functionName.name))
if (f->literalArguments)
{
yulAssert(f->name == "datasize"_yulstring || f->name == "dataoffset"_yulstring, "");
yulAssert(assignment.variableNames.size() == 1, "");
auto newLhs = generateU64IdentifierNames(assignment.variableNames[0].name);
vector<Statement> ret;
for (int i = 0; i < 3; i++)
ret.push_back(Assignment{
assignment.location,
{Identifier{assignment.location, newLhs[i]}},
make_unique<Expression>(Literal{locationOf(*assignment.value), LiteralKind::Number, "0"_yulstring, "u64"_yulstring})
});
ret.push_back(Assignment{
assignment.location,
{Identifier{assignment.location, newLhs[3]}},
std::move(assignment.value)
});
return {std::move(ret)};
}
if (
assignment.value->type() == typeid(FunctionalInstruction) ||
assignment.value->type() == typeid(FunctionCall)