Merge pull request #9243 from ethereum/jumpTypesForYul

Jump types for yul functions.
This commit is contained in:
chriseth
2020-07-07 12:21:14 +02:00
committed by GitHub
14 changed files with 151 additions and 35 deletions
+5 -3
View File
@@ -36,7 +36,8 @@ Binary representation:
Text representation:
/* "yul_stack_opt/input.sol":495:500 */
tag_1
jump(tag_2)
tag_2
jump // in
tag_1:
/* "yul_stack_opt/input.sol":425:500 */
pop
@@ -56,7 +57,8 @@ tag_1:
pop
/* "yul_stack_opt/input.sol":572:577 */
tag_3
jump(tag_2)
tag_2
jump // in
tag_3:
/* "yul_stack_opt/input.sol":502:577 */
pop
@@ -198,5 +200,5 @@ tag_5:
swap14
swap15
swap16
jump
jump // out
tag_4:
+24
View File
@@ -182,6 +182,30 @@ BOOST_AUTO_TEST_CASE(location_test)
checkAssemblyLocations(items, locations);
}
BOOST_AUTO_TEST_CASE(jump_type)
{
auto sourceCode = make_shared<CharStream>(R"(
contract C {
function f(uint a) public pure returns (uint t) {
assembly {
function g(x) -> y { if x { leave } y := 8 }
t := g(a)
}
}
}
)", "");
AssemblyItems items = compileContract(sourceCode);
string jumpTypes;
for (AssemblyItem const& item: items)
if (item.getJumpType() != AssemblyItem::JumpType::Ordinary)
jumpTypes += item.getJumpTypeAsString() + "\n";
BOOST_CHECK_EQUAL(jumpTypes, "[in]\n[out]\n[in]\n[out]\n");
}
BOOST_AUTO_TEST_SUITE_END()
} // end namespaces
@@ -13,12 +13,12 @@ object "Contract" {
// tag_2:
// /* "source":46:48 */
// tag_3:
// jump
// jump // out
// /* "source":53:68 */
// tag_4:
// /* "source":66:68 */
// tag_5:
// jump
// jump // out
// tag_1:
// /* "source":83:84 */
// 0x01
@@ -28,4 +28,4 @@ object "Contract" {
// sstore
// Bytecode: 6009565b5b565b5b565b6001600055
// Opcodes: PUSH1 0x9 JUMP JUMPDEST JUMPDEST JUMP JUMPDEST JUMPDEST JUMP JUMPDEST PUSH1 0x1 PUSH1 0x0 SSTORE
// SourceMappings: 33:15:0:-:0;;;46:2;;53:15;66:2;;;83:1;80;73:12
// SourceMappings: 33:15:0:-:0;;;46:2;:::o;53:15::-;66:2;:::o;:::-;83:1;80;73:12
+64
View File
@@ -0,0 +1,64 @@
object "Contract" {
code {
function f() { g(1) }
function g(x) { if x { leave } g(add(x, 2)) }
g(1)
}
}
// ----
// Assembly:
// /* "source":33:54 */
// jump(tag_1)
// tag_2:
// /* "source":48:52 */
// tag_4
// /* "source":50:51 */
// 0x01
// /* "source":48:52 */
// tag_5
// jump // in
// tag_4:
// /* "source":46:54 */
// tag_3:
// jump // out
// /* "source":59:104 */
// tag_5:
// /* "source":78:79 */
// dup1
// /* "source":75:77 */
// iszero
// tag_7
// jumpi
// /* "source":82:87 */
// jump(tag_6)
// /* "source":75:77 */
// tag_7:
// /* "source":90:102 */
// tag_8
// /* "source":99:100 */
// 0x02
// /* "source":96:97 */
// dup3
// /* "source":92:101 */
// add
// /* "source":90:102 */
// tag_5
// jump // in
// tag_8:
// /* "source":73:104 */
// tag_6:
// pop
// jump // out
// tag_1:
// /* "source":109:113 */
// tag_9
// /* "source":111:112 */
// 0x01
// /* "source":109:113 */
// tag_5
// jump // in
// tag_9:
// Bytecode: 6025565b600b6001600e565b5b565b80156017576022565b602160028201600e565b5b50565b602d6001600e565b
// Opcodes: PUSH1 0x25 JUMP JUMPDEST PUSH1 0xB PUSH1 0x1 PUSH1 0xE JUMP JUMPDEST JUMPDEST JUMP JUMPDEST DUP1 ISZERO PUSH1 0x17 JUMPI PUSH1 0x22 JUMP JUMPDEST PUSH1 0x21 PUSH1 0x2 DUP3 ADD PUSH1 0xE JUMP JUMPDEST JUMPDEST POP JUMP JUMPDEST PUSH1 0x2D PUSH1 0x1 PUSH1 0xE JUMP JUMPDEST
// SourceMappings: 33:21:0:-:0;;;48:4;50:1;48:4;:::i;:::-;46:8;:::o;59:45::-;78:1;75:2;;;82:5;;75:2;90:12;99:1;96;92:9;90:12;:::i;:::-;73:31;;:::o;:::-;109:4;111:1;109:4;:::i;:::-