From 6467ef6d3b5648d47c13b877d3d4fe6a5b5efb7d Mon Sep 17 00:00:00 2001 From: jacob gw Date: Mon, 1 Mar 2021 11:25:50 -0500 Subject: cbe: add error comparison support --- src/codegen.zig | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/codegen.zig') diff --git a/src/codegen.zig b/src/codegen.zig index c3cd64cf73..cfe605b567 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -2237,6 +2237,8 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { // No side effects, so if it's unreferenced, do nothing. if (inst.base.isUnused()) return MCValue{ .dead = {} }; + if (inst.lhs.ty.zigTypeTag() == .ErrorSet or inst.rhs.ty.zigTypeTag() == .ErrorSet) + return self.fail(inst.base.src, "TODO implement cmp for errors", .{}); switch (arch) { .x86_64 => { try self.code.ensureCapacity(self.code.items.len + 8); -- cgit v1.2.3 From bdb917006c9920f2a0d2091cb0f3d52454e039f0 Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Sun, 7 Mar 2021 00:25:21 +0100 Subject: stage2 tzir: Add wrapping integer arithmetic instructions --- src/codegen.zig | 30 ++++++++++++++++++++++++++++++ src/ir.zig | 6 ++++++ src/zir.zig | 6 ++++++ src/zir_sema.zig | 11 +++++++---- 4 files changed, 49 insertions(+), 4 deletions(-) (limited to 'src/codegen.zig') diff --git a/src/codegen.zig b/src/codegen.zig index c3cd64cf73..e21626bdb6 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -865,6 +865,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { fn genFuncInst(self: *Self, inst: *ir.Inst) !MCValue { switch (inst.tag) { .add => return self.genAdd(inst.castTag(.add).?), + .addwrap => return self.genAddWrap(inst.castTag(.addwrap).?), .alloc => return self.genAlloc(inst.castTag(.alloc).?), .arg => return self.genArg(inst.castTag(.arg).?), .assembly => return self.genAsm(inst.castTag(.assembly).?), @@ -900,12 +901,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { .loop => return self.genLoop(inst.castTag(.loop).?), .not => return self.genNot(inst.castTag(.not).?), .mul => return self.genMul(inst.castTag(.mul).?), + .mulwrap => return self.genMulWrap(inst.castTag(.mulwrap).?), .ptrtoint => return self.genPtrToInt(inst.castTag(.ptrtoint).?), .ref => return self.genRef(inst.castTag(.ref).?), .ret => return self.genRet(inst.castTag(.ret).?), .retvoid => return self.genRetVoid(inst.castTag(.retvoid).?), .store => return self.genStore(inst.castTag(.store).?), .sub => return self.genSub(inst.castTag(.sub).?), + .subwrap => return self.genSubWrap(inst.castTag(.subwrap).?), .switchbr => return self.genSwitch(inst.castTag(.switchbr).?), .unreach => return MCValue{ .unreach = {} }, .optional_payload => return self.genOptionalPayload(inst.castTag(.optional_payload).?), @@ -1129,6 +1132,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { } } + fn genAddWrap(self: *Self, inst: *ir.Inst.BinOp) !MCValue { + // No side effects, so if it's unreferenced, do nothing. + if (inst.base.isUnused()) + return MCValue.dead; + switch (arch) { + else => return self.fail(inst.base.src, "TODO implement addwrap for {}", .{self.target.cpu.arch}), + } + } + fn genMul(self: *Self, inst: *ir.Inst.BinOp) !MCValue { // No side effects, so if it's unreferenced, do nothing. if (inst.base.isUnused()) @@ -1139,6 +1151,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { } } + fn genMulWrap(self: *Self, inst: *ir.Inst.BinOp) !MCValue { + // No side effects, so if it's unreferenced, do nothing. + if (inst.base.isUnused()) + return MCValue.dead; + switch (arch) { + else => return self.fail(inst.base.src, "TODO implement mulwrap for {}", .{self.target.cpu.arch}), + } + } + fn genBitAnd(self: *Self, inst: *ir.Inst.BinOp) !MCValue { // No side effects, so if it's unreferenced, do nothing. if (inst.base.isUnused()) @@ -1392,6 +1413,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { } } + fn genSubWrap(self: *Self, inst: *ir.Inst.BinOp) !MCValue { + // No side effects, so if it's unreferenced, do nothing. + if (inst.base.isUnused()) + return MCValue.dead; + switch (arch) { + else => return self.fail(inst.base.src, "TODO implement subwrap for {}", .{self.target.cpu.arch}), + } + } + fn genArmBinOp(self: *Self, inst: *ir.Inst, op_lhs: *ir.Inst, op_rhs: *ir.Inst, op: ir.Inst.Tag) !MCValue { const lhs = try self.resolveInst(op_lhs); const rhs = try self.resolveInst(op_rhs); diff --git a/src/ir.zig b/src/ir.zig index 996f3b9782..95896d523b 100644 --- a/src/ir.zig +++ b/src/ir.zig @@ -53,6 +53,7 @@ pub const Inst = struct { pub const Tag = enum { add, + addwrap, alloc, arg, assembly, @@ -105,8 +106,10 @@ pub const Inst = struct { /// Write a value to a pointer. LHS is pointer, RHS is value. store, sub, + subwrap, unreach, mul, + mulwrap, not, floatcast, intcast, @@ -165,8 +168,11 @@ pub const Inst = struct { => UnOp, .add, + .addwrap, .sub, + .subwrap, .mul, + .mulwrap, .cmp_lt, .cmp_lte, .cmp_eq, diff --git a/src/zir.zig b/src/zir.zig index cb1f4561bf..0b9df55624 100644 --- a/src/zir.zig +++ b/src/zir.zig @@ -1680,8 +1680,11 @@ const DumpTzir = struct { }, .add, + .addwrap, .sub, + .subwrap, .mul, + .mulwrap, .cmp_lt, .cmp_lte, .cmp_eq, @@ -1803,8 +1806,11 @@ const DumpTzir = struct { }, .add, + .addwrap, .sub, + .subwrap, .mul, + .mulwrap, .cmp_lt, .cmp_lte, .cmp_eq, diff --git a/src/zir_sema.zig b/src/zir_sema.zig index 9cbdfd07dd..2df32709c5 100644 --- a/src/zir_sema.zig +++ b/src/zir_sema.zig @@ -2179,10 +2179,13 @@ fn zirArithmetic(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError! } const b = try mod.requireRuntimeBlock(scope, inst.base.src); - const ir_tag = switch (inst.base.tag) { - .add => Inst.Tag.add, - .sub => Inst.Tag.sub, - .mul => Inst.Tag.mul, + const ir_tag: Inst.Tag = switch (inst.base.tag) { + .add => .add, + .addwrap => .addwrap, + .sub => .sub, + .subwrap => .subwrap, + .mul => .mul, + .mulwrap => .mulwrap, else => return mod.fail(scope, inst.base.src, "TODO implement arithmetic for operand '{s}''", .{@tagName(inst.base.tag)}), }; -- cgit v1.2.3