mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #8867 from ethereum/solYulCreationCode
[Sol->Yul] Implement .creationCode.
This commit is contained in:
commit
34e4fce46b
@ -1304,7 +1304,20 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
|
||||
solAssert(false, "Blockhash has been removed.");
|
||||
else if (member == "creationCode" || member == "runtimeCode")
|
||||
{
|
||||
solUnimplementedAssert(false, "");
|
||||
solUnimplementedAssert(member != "runtimeCode", "");
|
||||
TypePointer arg = dynamic_cast<MagicType const&>(*_memberAccess.expression().annotation().type).typeArgument();
|
||||
ContractDefinition const& contract = dynamic_cast<ContractType const&>(*arg).contractDefinition();
|
||||
m_context.subObjectsCreated().insert(&contract);
|
||||
m_code << Whiskers(R"(
|
||||
let <size> := datasize("<objectName>")
|
||||
let <result> := <allocationFunction>(add(<size>, 32))
|
||||
mstore(<result>, <size>)
|
||||
datacopy(add(<result>, 32), dataoffset("<objectName>"), <size>)
|
||||
)")
|
||||
("allocationFunction", m_utils.allocationFunction())
|
||||
("size", m_context.newYulVariable())
|
||||
("objectName", m_context.creationObjectName(contract))
|
||||
("result", IRVariable(_memberAccess).commaSeparatedList()).render();
|
||||
}
|
||||
else if (member == "name")
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ contract C {
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >homestead
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint256), 2000 ether: 0 -> true
|
||||
// f(uint256), 2000 ether: 100 -> false
|
||||
|
@ -22,5 +22,7 @@ contract C {
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 7
|
||||
|
@ -0,0 +1,27 @@
|
||||
contract D {
|
||||
uint256 x;
|
||||
|
||||
constructor() public {
|
||||
x = 7;
|
||||
}
|
||||
|
||||
function f() public view returns (uint256) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract C {
|
||||
function test() public returns (uint256) {
|
||||
D d = new D();
|
||||
bytes32 hash;
|
||||
assembly { hash := extcodehash(d) }
|
||||
assert(hash == keccak256(type(D).runtimeCode));
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// EVMVersion: >=constantinople
|
||||
// ----
|
||||
// test() -> 42
|
Loading…
Reference in New Issue
Block a user