Commit 4b854b75d2
src/codegen/wasm.zig
@@ -207,8 +207,8 @@ pub const Context = struct {
.add => self.genAdd(inst.castTag(.add).?),
.alloc => self.genAlloc(inst.castTag(.alloc).?),
.arg => self.genArg(inst.castTag(.arg).?),
- .breakpoint => self.genBreakpoint(inst.castTag(.breakpoint).?),
.block => self.genBlock(inst.castTag(.block).?),
+ .breakpoint => self.genBreakpoint(inst.castTag(.breakpoint).?),
.br => self.genBr(inst.castTag(.br).?),
.call => self.genCall(inst.castTag(.call).?),
.cmp_eq => self.genCmp(inst.castTag(.cmp_eq).?, .eq),
@@ -546,7 +546,7 @@ pub const Context = struct {
try writer.writeByte(wasm.opcode(.i32_const));
try leb.writeILEB128(writer, @as(i32, 0));
- try self.code.append(wasm.opcode(.i32_ne));
+ try writer.writeByte(wasm.opcode(.i32_eq));
return WValue{ .code_offset = offset };
}
test/stage2/wasm.zig
@@ -175,6 +175,41 @@ pub fn addCases(ctx: *TestContext) !void {
\\ return i;
\\}
, "31\n");
+
+ case.addCompareOutput(
+ \\export fn _start() void {
+ \\ assert(foo(true) != @as(i32, 30));
+ \\}
+ \\
+ \\fn assert(ok: bool) void {
+ \\ if (!ok) unreachable;
+ \\}
+ \\
+ \\fn foo(ok: bool) i32 {
+ \\ const x = if(ok) @as(i32, 20) else @as(i32, 10);
+ \\ return x;
+ \\}
+ , "");
+
+ case.addCompareOutput(
+ \\export fn _start() void {
+ \\ assert(foo(false) == @as(i32, 20));
+ \\ assert(foo(true) == @as(i32, 30));
+ \\}
+ \\
+ \\fn assert(ok: bool) void {
+ \\ if (!ok) unreachable;
+ \\}
+ \\
+ \\fn foo(ok: bool) i32 {
+ \\ const val: i32 = blk: {
+ \\ var x: i32 = 1;
+ \\ if (!ok) break :blk x + @as(i32, 9);
+ \\ break :blk x + @as(i32, 19);
+ \\ };
+ \\ return val + 10;
+ \\}
+ , "");
}
{