mirror of
https://github.com/ziglang/zig.git
synced 2026-01-04 04:25:05 +00:00
stage2 wasm: codegen mul op
This commit is contained in:
parent
d1244d3608
commit
869fc06c57
@ -221,6 +221,7 @@ pub const Context = struct {
|
||||
.dbg_stmt => WValue.none,
|
||||
.load => self.genLoad(inst.castTag(.load).?),
|
||||
.loop => self.genLoop(inst.castTag(.loop).?),
|
||||
.mul => self.genMul(inst.castTag(.mul).?),
|
||||
.not => self.genNot(inst.castTag(.not).?),
|
||||
.ret => self.genRet(inst.castTag(.ret).?),
|
||||
.retvoid => WValue.none,
|
||||
@ -344,6 +345,25 @@ pub const Context = struct {
|
||||
return .none;
|
||||
}
|
||||
|
||||
fn genMul(self: *Context, inst: *Inst.BinOp) InnerError!WValue {
|
||||
const lhs = self.resolveInst(inst.lhs);
|
||||
const rhs = self.resolveInst(inst.rhs);
|
||||
|
||||
try self.emitWValue(lhs);
|
||||
try self.emitWValue(rhs);
|
||||
|
||||
const opcode: wasm.Opcode = switch (inst.base.ty.tag()) {
|
||||
.u32, .i32 => .i32_mul,
|
||||
.u64, .i64 => .i64_mul,
|
||||
.f32 => .f32_mul,
|
||||
.f64 => .f64_mul,
|
||||
else => return self.fail(inst.base.src, "TODO - Implement wasm genMul for type '{s}'", .{inst.base.ty.tag()}),
|
||||
};
|
||||
|
||||
try self.code.append(wasm.opcode(opcode));
|
||||
return .none;
|
||||
}
|
||||
|
||||
fn emitConstant(self: *Context, inst: *Inst.Constant) InnerError!void {
|
||||
const writer = self.code.writer();
|
||||
switch (inst.base.ty.tag()) {
|
||||
|
||||
@ -141,6 +141,18 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
\\ return y - x;
|
||||
\\}
|
||||
, "8\n");
|
||||
|
||||
case.addCompareOutput(
|
||||
\\export fn _start() u32 {
|
||||
\\ var i: u32 = 5;
|
||||
\\ i *= 7;
|
||||
\\ var result: u32 = foo(i, 10);
|
||||
\\ return result;
|
||||
\\}
|
||||
\\fn foo(x: u32, y: u32) u32 {
|
||||
\\ return x * y;
|
||||
\\}
|
||||
, "350\n");
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user