Add `.address and .selector` in inside assembly for external function pointers

This commit is contained in:
Marenz
2021-10-04 18:05:57 +02:00
committed by Mathias Baumann
parent 529087be6c
commit 98dd78362e
16 changed files with 211 additions and 5 deletions
+20
View File
@@ -823,6 +823,16 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
if (suffix == "length")
stackDiff--;
}
else if (
auto const* functionType = dynamic_cast<FunctionType const*>(variable->type());
functionType && functionType->kind() == FunctionType::Kind::External
)
{
solAssert(suffix == "selector" || suffix == "address", "");
solAssert(variable->type()->sizeOnStack() == 2, "");
if (suffix == "selector")
stackDiff--;
}
else
solAssert(false, "");
}
@@ -889,6 +899,16 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
solAssert(suffix.empty(), "");
}
}
else if (
auto const* functionType = dynamic_cast<FunctionType const*>(variable->type());
functionType && functionType->kind() == FunctionType::Kind::External
)
{
solAssert(suffix == "selector" || suffix == "address", "");
solAssert(variable->type()->sizeOnStack() == 2, "");
if (suffix == "selector")
stackDiff--;
}
else
solAssert(suffix.empty(), "");
@@ -188,6 +188,18 @@ private:
solAssert(suffix == "offset" || suffix == "length", "");
value = IRVariable{*varDecl}.part(suffix).name();
}
else if (
auto const* functionType = dynamic_cast<FunctionType const*>(varDecl->type());
functionType && functionType->kind() == FunctionType::Kind::External
)
{
solAssert(suffix == "selector" || suffix == "address", "");
solAssert(varDecl->type()->sizeOnStack() == 2, "");
if (suffix == "selector")
value = IRVariable{*varDecl}.part("functionSelector").name();
else
value = IRVariable{*varDecl}.part("address").name();
}
else
solAssert(false, "");