| ... | ... | @@ -225,6 +225,7 @@ pub const Context = struct { |
| 225 | 225 | .ret => self.genRet(inst.castTag(.ret).?), |
| 226 | 226 | .retvoid => WValue.none, |
| 227 | 227 | .store => self.genStore(inst.castTag(.store).?), |
| 228 | .sub => self.genSub(inst.castTag(.sub).?), |
| 228 | 229 | .unreach => self.genUnreachable(inst.castTag(.unreach).?), |
| 229 | 230 | else => self.fail(inst.src, "TODO: Implement wasm inst: {s}", .{inst.tag}), |
| 230 | 231 | }; |
| ... | ... | @@ -324,6 +325,25 @@ pub const Context = struct { |
| 324 | 325 | return .none; |
| 325 | 326 | } |
| 326 | 327 | |
| 328 | fn genSub(self: *Context, inst: *Inst.BinOp) InnerError!WValue { |
| 329 | const lhs = self.resolveInst(inst.lhs); |
| 330 | const rhs = self.resolveInst(inst.rhs); |
| 331 | |
| 332 | try self.emitWValue(lhs); |
| 333 | try self.emitWValue(rhs); |
| 334 | |
| 335 | const opcode: wasm.Opcode = switch (inst.base.ty.tag()) { |
| 336 | .u32, .i32 => .i32_sub, |
| 337 | .u64, .i64 => .i64_sub, |
| 338 | .f32 => .f32_sub, |
| 339 | .f64 => .f64_sub, |
| 340 | else => return self.fail(inst.base.src, "TODO - Implement wasm genSub for type '{s}'", .{inst.base.ty.tag()}), |
| 341 | }; |
| 342 | |
| 343 | try self.code.append(wasm.opcode(opcode)); |
| 344 | return .none; |
| 345 | } |
| 346 | |
| 327 | 347 | fn emitConstant(self: *Context, inst: *Inst.Constant) InnerError!void { |
| 328 | 348 | const writer = self.code.writer(); |
| 329 | 349 | switch (inst.base.ty.tag()) { |