Merge pull request #6241 from ethereum/yul-bc-codegen

Yul codegen for break & continue statements
This commit is contained in:
chriseth
2019-03-28 14:48:50 +01:00
committed by GitHub
6 changed files with 75 additions and 4 deletions
@@ -0,0 +1,13 @@
contract C {
function f() public returns (uint i) {
assembly {
for {} lt(i, 10) { i := add(i, 1) }
{
if eq(i, 6) { break }
i := add(i, 1)
}
}
}
}
// ----
// f() -> 6
@@ -0,0 +1,13 @@
contract C {
function f() public returns (uint k) {
assembly {
for {let i := 0} lt(i, 10) { i := add(i, 1) }
{
if eq(mod(i, 2), 0) { continue }
k := add(k, 1)
}
}
}
}
// ----
// f() -> 5
@@ -0,0 +1,20 @@
contract C {
function f(uint x) public returns (uint i) {
assembly {
for {} lt(i, 10) { i := add(i, 1) }
{
if eq(x, 0) { i := 2 break }
for {} lt(x, 3) { i := 17 x := 9 } {
if eq(x, 1) { continue }
if eq(x, 2) { break }
}
if eq(x, 4) { i := 90 }
}
}
}
}
// ----
// f(uint256): 0 -> 2
// f(uint256): 1 -> 18
// f(uint256): 2 -> 10
// f(uint256): 4 -> 91