[Sol->Yul] Supporting .runtimeCode

This commit is contained in:
Djordje Mijovic 2020-07-15 17:26:51 +02:00
parent 6f97e6153c
commit 546e9af24d
3 changed files with 9 additions and 9 deletions

View File

@ -1491,7 +1491,6 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
solAssert(false, "Blockhash has been removed."); solAssert(false, "Blockhash has been removed.");
else if (member == "creationCode" || member == "runtimeCode") else if (member == "creationCode" || member == "runtimeCode")
{ {
solUnimplementedAssert(member != "runtimeCode", "");
TypePointer arg = dynamic_cast<MagicType const&>(*_memberAccess.expression().annotation().type).typeArgument(); TypePointer arg = dynamic_cast<MagicType const&>(*_memberAccess.expression().annotation().type).typeArgument();
ContractDefinition const& contract = dynamic_cast<ContractType const&>(*arg).contractDefinition(); ContractDefinition const& contract = dynamic_cast<ContractType const&>(*arg).contractDefinition();
m_context.subObjectsCreated().insert(&contract); m_context.subObjectsCreated().insert(&contract);
@ -1503,7 +1502,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
)") )")
("allocationFunction", m_utils.allocationFunction()) ("allocationFunction", m_utils.allocationFunction())
("size", m_context.newYulVariable()) ("size", m_context.newYulVariable())
("objectName", IRNames::creationObject(contract)) ("objectName", IRNames::creationObject(contract) + (member == "runtimeCode" ? "." + IRNames::runtimeObject(contract) : ""))
("result", IRVariable(_memberAccess).commaSeparatedList()).render(); ("result", IRVariable(_memberAccess).commaSeparatedList()).render();
} }
else if (member == "name") else if (member == "name")

View File

@ -36,7 +36,8 @@ contract C {
return true; return true;
} }
} }
// ====
// compileViaYul: also
// ---- // ----
// testRuntime() -> true // testRuntime() -> true
// testCreation() -> true // testCreation() -> true

View File

@ -10,18 +10,18 @@ contract D {
} }
} }
contract C { contract C {
function test() public returns (uint256) { function test() public returns (uint256) {
D d = new D(); D d = new D();
bytes32 hash; bytes32 hash;
assembly { hash := extcodehash(d) } assembly { hash := extcodehash(d) }
assert(hash == keccak256(type(D).runtimeCode)); assert(hash == keccak256(type(D).runtimeCode));
return 42; return 42;
} }
} }
// ==== // ====
// EVMVersion: >=constantinople // EVMVersion: >=constantinople
// compileViaYul: also
// ---- // ----
// test() -> 42 // test() -> 42