C backend: implement trunc instruction

Note that there is not any test coverage yet for integer
truncation involving non-power-of-two integers.
This commit is contained in:
Andrew Kelley
2021-10-28 17:41:45 -07:00
parent 5479c0f9ac
commit 98009a2f66
5 changed files with 462 additions and 467 deletions

View File

@@ -1089,7 +1089,6 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
.call => try airCall(f, inst),
.dbg_stmt => try airDbgStmt(f, inst),
.intcast => try airIntCast(f, inst),
.trunc => try airTrunc(f, inst),
.bool_to_int => try airBoolToInt(f, inst),
.load => try airLoad(f, inst),
.ret => try airRet(f, inst),
@@ -1117,6 +1116,7 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
.float_to_int,
.fptrunc,
.fpext,
.trunc,
=> try airSimpleCast(f, inst),
.ptrtoint => try airPtrToInt(f, inst),
@@ -1366,16 +1366,6 @@ fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue {
return local;
}
fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {
if (f.liveness.isUnused(inst))
return CValue.none;
const ty_op = f.air.instructions.items(.data)[inst].ty_op;
const operand = try f.resolveInst(ty_op.operand);
_ = operand;
return f.fail("TODO: C backend: airTrunc", .{});
}
fn airBoolToInt(f: *Function, inst: Air.Inst.Index) !CValue {
if (f.liveness.isUnused(inst))
return CValue.none;

View File

@@ -3153,8 +3153,7 @@ pub const FuncGen = struct {
}
fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
if (self.liveness.isUnused(inst))
return null;
if (self.liveness.isUnused(inst)) return null;
const ty_op = self.air.instructions.items(.data)[inst].ty_op;
const operand = try self.resolveInst(ty_op.operand);