Fix getNot and add test cases

This commit is contained in:
Luuk de Gram 2021-02-06 13:10:30 +01:00
parent 803f9e5dd0
commit 4b854b75d2
No known key found for this signature in database
GPG Key ID: A002B174963DBB7D
2 changed files with 37 additions and 2 deletions

View File

@ -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 };
}

View File

@ -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;
\\}
, "");
}
{