| author | |
| committer | |
| log | 4b854b75d2d0add085ac202c611bbe10fa79b51c |
| tree | 01a192666ff8fde99b9d74b22f21755187886bba |
| parent | 803f9e5dd02afc36014c292f3ebcf7ea5cd065ee |
| signature |
2 files changed, 37 insertions(+), 2 deletions(-)
src/codegen/wasm.zig+2-2| ... | @@ -207,8 +207,8 @@ pub const Context = struct { | ... | @@ -207,8 +207,8 @@ pub const Context = struct { |
| 207 | .add => self.genAdd(inst.castTag(.add).?), | 207 | .add => self.genAdd(inst.castTag(.add).?), |
| 208 | .alloc => self.genAlloc(inst.castTag(.alloc).?), | 208 | .alloc => self.genAlloc(inst.castTag(.alloc).?), |
| 209 | .arg => self.genArg(inst.castTag(.arg).?), | 209 | .arg => self.genArg(inst.castTag(.arg).?), |
| 210 | .breakpoint => self.genBreakpoint(inst.castTag(.breakpoint).?), | ||
| 211 | .block => self.genBlock(inst.castTag(.block).?), | 210 | .block => self.genBlock(inst.castTag(.block).?), |
| 211 | .breakpoint => self.genBreakpoint(inst.castTag(.breakpoint).?), | ||
| 212 | .br => self.genBr(inst.castTag(.br).?), | 212 | .br => self.genBr(inst.castTag(.br).?), |
| 213 | .call => self.genCall(inst.castTag(.call).?), | 213 | .call => self.genCall(inst.castTag(.call).?), |
| 214 | .cmp_eq => self.genCmp(inst.castTag(.cmp_eq).?, .eq), | 214 | .cmp_eq => self.genCmp(inst.castTag(.cmp_eq).?, .eq), |
| ... | @@ -546,7 +546,7 @@ pub const Context = struct { | ... | @@ -546,7 +546,7 @@ pub const Context = struct { |
| 546 | try writer.writeByte(wasm.opcode(.i32_const)); | 546 | try writer.writeByte(wasm.opcode(.i32_const)); |
| 547 | try leb.writeILEB128(writer, @as(i32, 0)); | 547 | try leb.writeILEB128(writer, @as(i32, 0)); |
| 548 | 548 | ||
| 549 | try self.code.append(wasm.opcode(.i32_ne)); | 549 | try writer.writeByte(wasm.opcode(.i32_eq)); |
| 550 | 550 | ||
| 551 | return WValue{ .code_offset = offset }; | 551 | return WValue{ .code_offset = offset }; |
| 552 | } | 552 | } |
test/stage2/wasm.zig+35| ... | @@ -175,6 +175,41 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -175,6 +175,41 @@ pub fn addCases(ctx: *TestContext) !void { |
| 175 | \\ return i; | 175 | \\ return i; |
| 176 | \\} | 176 | \\} |
| 177 | , "31\n"); | 177 | , "31\n"); |
| 178 | |||
| 179 | case.addCompareOutput( | ||
| 180 | \\export fn _start() void { | ||
| 181 | \\ assert(foo(true) != @as(i32, 30)); | ||
| 182 | \\} | ||
| 183 | \\ | ||
| 184 | \\fn assert(ok: bool) void { | ||
| 185 | \\ if (!ok) unreachable; | ||
| 186 | \\} | ||
| 187 | \\ | ||
| 188 | \\fn foo(ok: bool) i32 { | ||
| 189 | \\ const x = if(ok) @as(i32, 20) else @as(i32, 10); | ||
| 190 | \\ return x; | ||
| 191 | \\} | ||
| 192 | , ""); | ||
| 193 | |||
| 194 | case.addCompareOutput( | ||
| 195 | \\export fn _start() void { | ||
| 196 | \\ assert(foo(false) == @as(i32, 20)); | ||
| 197 | \\ assert(foo(true) == @as(i32, 30)); | ||
| 198 | \\} | ||
| 199 | \\ | ||
| 200 | \\fn assert(ok: bool) void { | ||
| 201 | \\ if (!ok) unreachable; | ||
| 202 | \\} | ||
| 203 | \\ | ||
| 204 | \\fn foo(ok: bool) i32 { | ||
| 205 | \\ const val: i32 = blk: { | ||
| 206 | \\ var x: i32 = 1; | ||
| 207 | \\ if (!ok) break :blk x + @as(i32, 9); | ||
| 208 | \\ break :blk x + @as(i32, 19); | ||
| 209 | \\ }; | ||
| 210 | \\ return val + 10; | ||
| 211 | \\} | ||
| 212 | , ""); | ||
| 178 | } | 213 | } |
| 179 | 214 | ||
| 180 | { | 215 | { |