Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 6 additions & 2 deletions src/s2wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -952,12 +952,16 @@ class S2WasmBuilder {
bstack.pop_back();
} else if (match("br")) {
auto curr = allocator.alloc<Break>();
bool hasCondition = false;
if (*s == '_') {
mustMatch("_if");
curr->condition = getInput();
skipComma();
hasCondition = true;
}
curr->name = getBranchLabel(getInt());
if (hasCondition) {
skipComma();
curr->condition = getInput();
}
addToBlock(curr);
} else if (match("call")) {
makeCall(none);
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,12 @@ assert(0);
o << int8_t(curr->condition ? BinaryConsts::BrIf : BinaryConsts::Br);
int offset = getBreakIndex(curr->name);
o << int8_t(offset);
if (curr->condition) recurse(curr->condition);
if (curr->value) {
recurse(curr->value);
} else {
visitNop(nullptr);
}
if (curr->condition) recurse(curr->condition);
}
void visitSwitch(Switch *curr) {
if (debug) std::cerr << "zz node: Switch" << std::endl;
Expand Down Expand Up @@ -1356,8 +1356,8 @@ class WasmBinaryBuilder {
if (debug) std::cerr << "zz node: Break" << std::endl;
auto offset = getInt8();
curr->name = getBreakName(offset);
if (code == BinaryConsts::BrIf) readExpression(curr->condition);
readExpression(curr->value);
if (code == BinaryConsts::BrIf) readExpression(curr->condition);
}
void visitSwitch(Switch *curr) {
if (debug) std::cerr << "zz node: Switch" << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,13 @@ class Loop : public Expression {

class Break : public Expression {
public:
Break() : Expression(BreakId), condition(nullptr), value(nullptr) {
Break() : Expression(BreakId), value(nullptr), condition(nullptr) {
type = unreachable;
}

Expression *condition;
Name name;
Expression *value;
Expression *condition;

std::ostream& doPrint(std::ostream &o, unsigned indent) {
if (condition) {
Expand Down
6 changes: 3 additions & 3 deletions test/dot_s/basics.s
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ main: # @main
i32.ne $push10=, $pop8, $pop9
block
block
br_if $pop10, 0
br_if 0, $pop10
.LBB0_1: # %.preheader
# =>This Inner Loop Header: Depth=1
loop
Expand All @@ -32,7 +32,7 @@ main: # @main
i32.const $push16=, 3
i32.ne $push17=, $pop15, $pop16
block
br_if $pop17, 0
br_if 0, $pop17
# BB#2: # in Loop: Header=.LBB0_1 Depth=1
i32.const $push18=, 111
i32.rem_s $push19=, $0, $pop18
Expand All @@ -42,7 +42,7 @@ main: # @main
i32.rem_s $push21=, $0, $pop20
i32.const $push22=, 0
i32.eq $push23=, $pop21, $pop22
br_if $pop23, 2
br_if 2, $pop23
br 0
end_loop
end_block
Expand Down
34 changes: 17 additions & 17 deletions test/dot_s/bcp-1.s
Original file line number Diff line number Diff line change
Expand Up @@ -238,89 +238,89 @@ main: # @main
block
i32.load $push0=, bad_t0($0)
i32.call_indirect $push1=, $pop0
br_if $pop1, 0 # 0: down to label0
br_if 0, $pop1 # 0: down to label0
# BB#1: # %for.cond
i32.load $push2=, bad_t0+4($0)
i32.call_indirect $push3=, $pop2
br_if $pop3, 0 # 0: down to label0
br_if 0, $pop3 # 0: down to label0
# BB#2: # %for.cond.1
i32.load $push4=, bad_t0+8($0)
i32.call_indirect $push5=, $pop4
br_if $pop5, 0 # 0: down to label0
br_if 0, $pop5 # 0: down to label0
# BB#3: # %for.cond.2
i32.load $push6=, bad_t0+12($0)
i32.call_indirect $push7=, $pop6
br_if $pop7, 0 # 0: down to label0
br_if 0, $pop7 # 0: down to label0
# BB#4: # %for.cond.3
i32.load $push8=, bad_t0+16($0)
i32.call_indirect $push9=, $pop8
br_if $pop9, 0 # 0: down to label0
br_if 0, $pop9 # 0: down to label0
# BB#5: # %for.cond.4
i32.load $push10=, bad_t0+20($0)
i32.call_indirect $push11=, $pop10
br_if $pop11, 0 # 0: down to label0
br_if 0, $pop11 # 0: down to label0
# BB#6: # %for.cond.5
i32.load $1=, bad_t1($0)
i32.const $2=, 1
block
i32.call_indirect $push12=, $1, $2
br_if $pop12, 0 # 0: down to label1
br_if 0, $pop12 # 0: down to label1
# BB#7: # %for.cond1
i32.load $push13=, bad_t1+4($0)
i32.call_indirect $push14=, $pop13, $2
br_if $pop14, 0 # 0: down to label1
br_if 0, $pop14 # 0: down to label1
# BB#8: # %for.cond1.1
i32.load $push15=, bad_t1+8($0)
i32.call_indirect $push16=, $pop15, $2
br_if $pop16, 0 # 0: down to label1
br_if 0, $pop16 # 0: down to label1
# BB#9: # %for.cond1.2
i32.load $1=, bad_t2($0)
i32.const $2=, .L.str
block
i32.call_indirect $push17=, $1, $2
br_if $pop17, 0 # 0: down to label2
br_if 0, $pop17 # 0: down to label2
# BB#10: # %for.cond12
i32.load $push18=, bad_t2+4($0)
i32.call_indirect $push19=, $pop18, $2
br_if $pop19, 0 # 0: down to label2
br_if 0, $pop19 # 0: down to label2
# BB#11: # %for.cond12.1
block
i32.load $push20=, good_t0($0)
i32.call_indirect $push21=, $pop20
i32.const $push32=, 0
i32.eq $push33=, $pop21, $pop32
br_if $pop33, 0 # 0: down to label3
br_if 0, $pop33 # 0: down to label3
# BB#12: # %for.cond23
i32.load $push22=, good_t0+4($0)
i32.call_indirect $push23=, $pop22
i32.const $push34=, 0
i32.eq $push35=, $pop23, $pop34
br_if $pop35, 0 # 0: down to label3
br_if 0, $pop35 # 0: down to label3
# BB#13: # %for.cond23.1
i32.load $push24=, good_t0+8($0)
i32.call_indirect $push25=, $pop24
i32.const $push36=, 0
i32.eq $push37=, $pop25, $pop36
br_if $pop37, 0 # 0: down to label3
br_if 0, $pop37 # 0: down to label3
# BB#14: # %for.cond23.2
block
i32.load $push26=, opt_t0($0)
i32.call_indirect $push27=, $pop26
i32.const $push38=, 0
i32.eq $push39=, $pop27, $pop38
br_if $pop39, 0 # 0: down to label4
br_if 0, $pop39 # 0: down to label4
# BB#15: # %for.cond34
i32.load $push28=, opt_t0+4($0)
i32.call_indirect $push29=, $pop28
i32.const $push40=, 0
i32.eq $push41=, $pop29, $pop40
br_if $pop41, 0 # 0: down to label4
br_if 0, $pop41 # 0: down to label4
# BB#16: # %for.cond34.1
i32.load $push30=, opt_t0+8($0)
i32.call_indirect $push31=, $pop30
i32.const $push42=, 0
i32.eq $push43=, $pop31, $pop42
br_if $pop43, 0 # 0: down to label4
br_if 0, $pop43 # 0: down to label4
# BB#17: # %for.cond34.2
call exit@FUNCTION, $0
unreachable
Expand Down
6 changes: 3 additions & 3 deletions test/dot_s/memops.s
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ main: # @main
i32.const $3=, 1048576
i32.ne $push2=, $4, $3
copy_local $5=, $1
br_if $pop2, 0
br_if 0, $pop2
end_loop
loop
i32.const $11=, 0
Expand All @@ -57,7 +57,7 @@ main: # @main
i32.add $6=, $pop5, $6
i32.add $5=, $5, $2
i32.ne $push6=, $5, $3
br_if $pop6, 0
br_if 0, $pop6
end_loop
i32.const $push7=, 3
i32.mul $push8=, $6, $pop7
Expand All @@ -71,7 +71,7 @@ main: # @main
i32.add $0=, $0, $2
i32.const $push15=, 100
i32.ne $push16=, $0, $pop15
br_if $pop16, 0
br_if 0, $pop16
end_loop
call _Z6reporti@FUNCTION, $6
i32.const $push17=, 0
Expand Down
9 changes: 3 additions & 6 deletions test/emcc_O2_hello_world.wast.fromBinary
Original file line number Diff line number Diff line change
Expand Up @@ -4657,12 +4657,11 @@
)
)
)
(br_if
(br_if $label$165
(i32.ne
(get_local $var$62)
(i32.const 0)
)
$label$165
)
)
)
Expand Down Expand Up @@ -6657,7 +6656,7 @@
(get_local $var$62)
(i32.const 7)
)
(br_if
(br_if $label$236
(i32.lt_u
(i32.shr_u
(i32.add
Expand All @@ -6671,7 +6670,6 @@
(i32.const 0)
)
)
$label$236
)
)
)
Expand Down Expand Up @@ -7355,12 +7353,11 @@
(i32.const 1)
)
)
(br_if
(br_if $label$256
(i32.ne
(get_local $var$4)
(i32.const 32)
)
$label$256
)
)
)
Expand Down
3 changes: 1 addition & 2 deletions test/emcc_hello_world.wast.fromBinary
Original file line number Diff line number Diff line change
Expand Up @@ -2448,12 +2448,11 @@
(i32.const 4)
)
)
(br_if
(br_if $label$2
(i32.lt_s
(get_local $var$46)
(get_local $var$49)
)
$label$2
)
)
)
Expand Down
Loading