mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 16:24:51 +00:00
stage2: Add .div to ir.zig
This commit is contained in:
parent
bcc371618f
commit
4c71942f84
@ -3540,6 +3540,7 @@ fn analyzeArithmetic(
|
||||
.subwrap => .subwrap,
|
||||
.mul => .mul,
|
||||
.mulwrap => .mulwrap,
|
||||
.div => .div,
|
||||
else => return sema.mod.fail(&block.base, src, "TODO implement arithmetic for operand '{s}''", .{@tagName(zir_tag)}),
|
||||
};
|
||||
|
||||
|
||||
@ -855,6 +855,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
|
||||
.not => return self.genNot(inst.castTag(.not).?),
|
||||
.mul => return self.genMul(inst.castTag(.mul).?),
|
||||
.mulwrap => return self.genMulWrap(inst.castTag(.mulwrap).?),
|
||||
.div => return self.genDiv(inst.castTag(.div).?),
|
||||
.ptrtoint => return self.genPtrToInt(inst.castTag(.ptrtoint).?),
|
||||
.ref => return self.genRef(inst.castTag(.ref).?),
|
||||
.ret => return self.genRet(inst.castTag(.ret).?),
|
||||
@ -1092,6 +1093,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
|
||||
}
|
||||
}
|
||||
|
||||
fn genDiv(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 div 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())
|
||||
|
||||
@ -582,6 +582,9 @@ pub fn genBody(o: *Object, body: ir.Body) error{ AnalysisFail, OutOfMemory }!voi
|
||||
.mul => try genBinOp(o, inst.castTag(.sub).?, " * "),
|
||||
// TODO make this do wrapping multiplication for signed ints
|
||||
.mulwrap => try genBinOp(o, inst.castTag(.sub).?, " * "),
|
||||
// TODO use a different strategy for div that communicates to the optimizer
|
||||
// that wrapping is UB.
|
||||
.div => try genBinOp(o, inst.castTag(.div).?, " / "),
|
||||
|
||||
.constant => unreachable, // excluded from function bodies
|
||||
.alloc => try genAlloc(o, inst.castTag(.alloc).?),
|
||||
|
||||
@ -115,6 +115,7 @@ pub const Inst = struct {
|
||||
unreach,
|
||||
mul,
|
||||
mulwrap,
|
||||
div,
|
||||
not,
|
||||
floatcast,
|
||||
intcast,
|
||||
@ -181,6 +182,7 @@ pub const Inst = struct {
|
||||
.subwrap,
|
||||
.mul,
|
||||
.mulwrap,
|
||||
.div,
|
||||
.cmp_lt,
|
||||
.cmp_lte,
|
||||
.cmp_eq,
|
||||
@ -752,6 +754,7 @@ const DumpTzir = struct {
|
||||
.subwrap,
|
||||
.mul,
|
||||
.mulwrap,
|
||||
.div,
|
||||
.cmp_lt,
|
||||
.cmp_lte,
|
||||
.cmp_eq,
|
||||
@ -891,6 +894,7 @@ const DumpTzir = struct {
|
||||
.subwrap,
|
||||
.mul,
|
||||
.mulwrap,
|
||||
.div,
|
||||
.cmp_lt,
|
||||
.cmp_lte,
|
||||
.cmp_eq,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user