aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.zig
diff options
context:
space:
mode:
authorTadeo Kondrak <me@tadeo.ca>2020-10-17 18:04:53 -0600
committerVeikka Tuominen <git@vexu.eu>2020-11-19 18:59:21 +0200
commit25ec2dbc1e2302d1138749262b588d3e438fcd55 (patch)
tree34187fbd88b2e9b046f50cea93f482a191bc3248 /src/codegen.zig
parent2b7781d82ad8d2234b89257676670957e005f214 (diff)
downloadzig-25ec2dbc1e2302d1138749262b588d3e438fcd55.tar.gz
zig-25ec2dbc1e2302d1138749262b588d3e438fcd55.zip
Add builtin.Signedness, use it instead of is_signed
Diffstat (limited to 'src/codegen.zig')
-rw-r--r--src/codegen.zig24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/codegen.zig b/src/codegen.zig
index 804a9b2029..48fda6f0d5 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -203,7 +203,7 @@ pub fn generateSymbol(
.Int => {
// TODO populate .debug_info for the integer
const info = typed_value.ty.intInfo(bin_file.options.target);
- if (info.bits == 8 and !info.signed) {
+ if (info.bits == 8 and info.signedness == .unsigned) {
const x = typed_value.val.toUnsignedInt();
try code.append(@intCast(u8, x));
return Result{ .appended = {} };
@@ -920,7 +920,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
const operand = try self.resolveInst(inst.operand);
const info_a = inst.operand.ty.intInfo(self.target.*);
const info_b = inst.base.ty.intInfo(self.target.*);
- if (info_a.signed != info_b.signed)
+ if (info_a.signedness != info_b.signedness)
return self.fail(inst.base.src, "TODO gen intcast sign safety in semantic analysis", .{});
if (info_a.bits == info_b.bits)
@@ -1780,7 +1780,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
fn genCmp(self: *Self, inst: *ir.Inst.BinOp, op: math.CompareOperator) !MCValue {
// No side effects, so if it's unreferenced, do nothing.
if (inst.base.isUnused())
- return MCValue.dead;
+ return MCValue{ .dead = {} };
switch (arch) {
.x86_64 => {
try self.code.ensureCapacity(self.code.items.len + 8);
@@ -1800,11 +1800,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
try self.genX8664BinMathCode(inst.base.src, inst.base.ty, dst_mcv, src_mcv, 7, 0x38);
const info = inst.lhs.ty.intInfo(self.target.*);
- if (info.signed) {
- return MCValue{ .compare_flags_signed = op };
- } else {
- return MCValue{ .compare_flags_unsigned = op };
- }
+ return switch (info.signedness) {
+ .signed => MCValue{ .compare_flags_signed = op },
+ .unsigned => MCValue{ .compare_flags_unsigned = op },
+ };
},
else => return self.fail(inst.base.src, "TODO implement cmp for {}", .{self.target.cpu.arch}),
}
@@ -2904,12 +2903,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
switch (mcv) {
.immediate => |imm| {
// This immediate is unsigned.
- const U = @Type(.{
- .Int = .{
- .bits = ti.bits - @boolToInt(ti.is_signed),
- .is_signed = false,
- },
- });
+ const U = std.meta.Int(.unsigned, ti.bits - @boolToInt(ti.signedness == .signed));
if (imm >= math.maxInt(U)) {
return MCValue{ .register = try self.copyToTmpRegister(inst.src, mcv) };
}
@@ -2949,7 +2943,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
},
.Int => {
const info = typed_value.ty.intInfo(self.target.*);
- if (info.bits > ptr_bits or info.signed) {
+ if (info.bits > ptr_bits or info.signedness == .signed) {
return self.fail(src, "TODO const int bigger than ptr and signed int", .{});
}
return MCValue{ .immediate = typed_value.val.toUnsignedInt() };