aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-01-25 07:30:45 -0800
committerGitHub <noreply@github.com>2025-01-25 07:30:45 -0800
commitd0d5ca2b6c8253c27e945ed8d973a90c28a3cbf5 (patch)
treed89ef781d3e729f684fa4baf20452f037f66b772 /src/codegen
parent8ba3812eeedec643dd045e0fecb8a6697f6253db (diff)
parentc7433212d1bf96adbfc6f3d706404436c0c98c20 (diff)
downloadzig-d0d5ca2b6c8253c27e945ed8d973a90c28a3cbf5.tar.gz
zig-d0d5ca2b6c8253c27e945ed8d973a90c28a3cbf5.zip
Merge pull request #22581 from jacobly0/x86_64-rewrite
x86_64: rewrite `@abs` on floats
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig196
-rw-r--r--src/codegen/c/Type.zig444
2 files changed, 486 insertions, 154 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 5364b0432d..6244bd2324 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -706,7 +706,7 @@ pub const DeclGen = struct {
const uav_ty = uav_val.typeOf(zcu);
// Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
- const ptr_ty = Type.fromInterned(uav.orig_ty);
+ const ptr_ty: Type = .fromInterned(uav.orig_ty);
if (ptr_ty.isPtrAtRuntime(zcu) and !uav_ty.isFnOrHasRuntimeBits(zcu)) {
return dg.writeCValue(writer, .{ .undef = ptr_ty });
}
@@ -782,7 +782,7 @@ pub const DeclGen = struct {
};
// Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
- const nav_ty = Type.fromInterned(ip.getNav(owner_nav).typeOf(ip));
+ const nav_ty: Type = .fromInterned(ip.getNav(owner_nav).typeOf(ip));
const ptr_ty = try pt.navPtrType(owner_nav);
if (!nav_ty.isFnOrHasRuntimeBits(zcu)) {
return dg.writeCValue(writer, .{ .undef = ptr_ty });
@@ -819,7 +819,7 @@ pub const DeclGen = struct {
.comptime_alloc_ptr, .comptime_field_ptr => unreachable,
.int => |int| {
const ptr_ctype = try dg.ctypeFromType(int.ptr_ty, .complete);
- const addr_val = try pt.intValue(Type.usize, int.addr);
+ const addr_val = try pt.intValue(.usize, int.addr);
try writer.writeByte('(');
try dg.renderCType(writer, ptr_ctype);
try writer.print("){x}", .{try dg.fmtIntLiteral(addr_val, .Other)});
@@ -859,7 +859,7 @@ pub const DeclGen = struct {
try writer.writeByte('(');
try dg.renderCType(writer, ptr_ctype);
try writer.writeByte(')');
- const offset_val = try pt.intValue(Type.usize, byte_offset);
+ const offset_val = try pt.intValue(.usize, byte_offset);
try writer.writeAll("((char *)");
try dg.renderPointer(writer, field.parent.*, location);
try writer.print(" + {})", .{try dg.fmtIntLiteral(offset_val, .Other)});
@@ -875,7 +875,7 @@ pub const DeclGen = struct {
try writer.writeByte(')');
try dg.renderPointer(writer, elem.parent.*, location);
} else {
- const index_val = try pt.intValue(Type.usize, elem.elem_idx);
+ const index_val = try pt.intValue(.usize, elem.elem_idx);
// We want to do pointer arithmetic on a pointer to the element type.
// We might have a pointer-to-array. In this case, we must cast first.
const result_ctype = try dg.ctypeFromType(elem.result_ptr_ty, .complete);
@@ -904,7 +904,7 @@ pub const DeclGen = struct {
if (oac.byte_offset == 0) {
try dg.renderPointer(writer, oac.parent.*, location);
} else {
- const offset_val = try pt.intValue(Type.usize, oac.byte_offset);
+ const offset_val = try pt.intValue(.usize, oac.byte_offset);
try writer.writeAll("((char *)");
try dg.renderPointer(writer, oac.parent.*, location);
try writer.print(" + {})", .{try dg.fmtIntLiteral(offset_val, .Other)});
@@ -984,7 +984,7 @@ pub const DeclGen = struct {
try writer.writeAll("((");
try dg.renderCType(writer, ctype);
try writer.print("){x})", .{try dg.fmtIntLiteral(
- try pt.intValue(Type.usize, val.toUnsignedInt(zcu)),
+ try pt.intValue(.usize, val.toUnsignedInt(zcu)),
.Other,
)});
},
@@ -1153,7 +1153,7 @@ pub const DeclGen = struct {
else => |payload| switch (ip.indexToKey(payload)) {
.undef => |err_ty| try dg.renderUndefValue(
writer,
- Type.fromInterned(err_ty),
+ .fromInterned(err_ty),
location,
),
.err => |err| try dg.renderErrorName(writer, err.name),
@@ -1204,7 +1204,7 @@ pub const DeclGen = struct {
),
},
.ptr => try writer.writeAll("NULL"),
- .len => try dg.renderUndefValue(writer, Type.usize, initializer_type),
+ .len => try dg.renderUndefValue(writer, .usize, initializer_type),
else => unreachable,
}
}
@@ -1219,7 +1219,7 @@ pub const DeclGen = struct {
try writer.writeByte(')');
}
const ai = ty.arrayInfo(zcu);
- if (ai.elem_type.eql(Type.u8, zcu)) {
+ if (ai.elem_type.eql(.u8, zcu)) {
var literal = stringLiteral(writer, ty.arrayLenIncludingSentinel(zcu));
try literal.start();
var index: usize = 0;
@@ -1263,7 +1263,7 @@ pub const DeclGen = struct {
for (0..tuple.types.len) |field_index| {
const comptime_val = tuple.values.get(ip)[field_index];
if (comptime_val != .none) continue;
- const field_ty = Type.fromInterned(tuple.types.get(ip)[field_index]);
+ const field_ty: Type = .fromInterned(tuple.types.get(ip)[field_index]);
if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
if (!empty) try writer.writeByte(',');
@@ -1298,7 +1298,7 @@ pub const DeclGen = struct {
var field_it = loaded_struct.iterateRuntimeOrder(ip);
var need_comma = false;
while (field_it.next()) |field_index| {
- const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
+ const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
if (need_comma) try writer.writeByte(',');
@@ -1325,7 +1325,7 @@ pub const DeclGen = struct {
var eff_num_fields: usize = 0;
for (0..loaded_struct.field_types.len) |field_index| {
- const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
+ const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
eff_num_fields += 1;
}
@@ -1346,7 +1346,7 @@ pub const DeclGen = struct {
var eff_index: usize = 0;
var needs_closing_paren = false;
for (0..loaded_struct.field_types.len) |field_index| {
- const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
+ const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
@@ -1382,7 +1382,7 @@ pub const DeclGen = struct {
// a << a_off | b << b_off | c << c_off
var empty = true;
for (0..loaded_struct.field_types.len) |field_index| {
- const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
+ const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
if (!empty) try writer.writeAll(" | ");
@@ -1466,7 +1466,7 @@ pub const DeclGen = struct {
}
const field_index = zcu.unionTagFieldIndex(loaded_union, Value.fromInterned(un.tag)).?;
- const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
+ const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index];
if (loaded_union.flagsUnordered(ip).layout == .@"packed") {
if (field_ty.hasRuntimeBits(zcu)) {
@@ -1509,7 +1509,7 @@ pub const DeclGen = struct {
);
try writer.writeByte(' ');
} else for (0..loaded_union.field_types.len) |inner_field_index| {
- const inner_field_ty = Type.fromInterned(
+ const inner_field_ty: Type = .fromInterned(
loaded_union.field_types.get(ip)[inner_field_index],
);
if (!inner_field_ty.hasRuntimeBits(zcu)) continue;
@@ -1592,7 +1592,7 @@ pub const DeclGen = struct {
try writer.writeAll("((");
try dg.renderCType(writer, ctype);
return writer.print("){x})", .{
- try dg.fmtIntLiteral(try pt.undefValue(Type.usize), .Other),
+ try dg.fmtIntLiteral(try pt.undefValue(.usize), .Other),
});
},
.slice => {
@@ -1606,14 +1606,14 @@ pub const DeclGen = struct {
const ptr_ty = ty.slicePtrFieldType(zcu);
try dg.renderType(writer, ptr_ty);
return writer.print("){x}, {0x}}}", .{
- try dg.fmtIntLiteral(try dg.pt.undefValue(Type.usize), .Other),
+ try dg.fmtIntLiteral(try dg.pt.undefValue(.usize), .Other),
});
},
},
.opt_type => |child_type| switch (ctype.info(ctype_pool)) {
.basic, .pointer => try dg.renderUndefValue(
writer,
- Type.fromInterned(if (ctype.isBool()) .bool_type else child_type),
+ .fromInterned(if (ctype.isBool()) .bool_type else child_type),
location,
),
.aligned, .array, .vector, .fwd_decl, .function => unreachable,
@@ -1622,7 +1622,7 @@ pub const DeclGen = struct {
.is_null, .payload => {},
.ptr, .len => return dg.renderUndefValue(
writer,
- Type.fromInterned(child_type),
+ .fromInterned(child_type),
location,
),
else => unreachable,
@@ -1635,7 +1635,7 @@ pub const DeclGen = struct {
try writer.writeByte('{');
for (0..aggregate.fields.len) |field_index| {
if (field_index > 0) try writer.writeByte(',');
- try dg.renderUndefValue(writer, Type.fromInterned(
+ try dg.renderUndefValue(writer, .fromInterned(
switch (aggregate.fields.at(field_index, ctype_pool).name.index) {
.is_null => .bool_type,
.payload => child_type,
@@ -1660,7 +1660,7 @@ pub const DeclGen = struct {
var field_it = loaded_struct.iterateRuntimeOrder(ip);
var need_comma = false;
while (field_it.next()) |field_index| {
- const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
+ const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
if (need_comma) try writer.writeByte(',');
@@ -1685,7 +1685,7 @@ pub const DeclGen = struct {
var need_comma = false;
for (0..tuple_info.types.len) |field_index| {
if (tuple_info.values.get(ip)[field_index] != .none) continue;
- const field_ty = Type.fromInterned(tuple_info.types.get(ip)[field_index]);
+ const field_ty: Type = .fromInterned(tuple_info.types.get(ip)[field_index]);
if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
if (need_comma) try writer.writeByte(',');
@@ -1715,13 +1715,13 @@ pub const DeclGen = struct {
.payload) {
.tag => try dg.renderUndefValue(
writer,
- Type.fromInterned(loaded_union.enum_tag_ty),
+ .fromInterned(loaded_union.enum_tag_ty),
initializer_type,
),
.payload => {
try writer.writeByte('{');
for (0..loaded_union.field_types.len) |inner_field_index| {
- const inner_field_ty = Type.fromInterned(
+ const inner_field_ty: Type = .fromInterned(
loaded_union.field_types.get(ip)[inner_field_index],
);
if (!inner_field_ty.hasRuntimeBits(pt.zcu)) continue;
@@ -1747,7 +1747,7 @@ pub const DeclGen = struct {
.error_union_type => |error_union_type| switch (ctype.info(ctype_pool)) {
.basic => try dg.renderUndefValue(
writer,
- Type.fromInterned(error_union_type.error_set_type),
+ .fromInterned(error_union_type.error_set_type),
location,
),
.pointer, .aligned, .array, .vector, .fwd_decl, .function => unreachable,
@@ -1762,7 +1762,7 @@ pub const DeclGen = struct {
if (field_index > 0) try writer.writeByte(',');
try dg.renderUndefValue(
writer,
- Type.fromInterned(
+ .fromInterned(
switch (aggregate.fields.at(field_index, ctype_pool).name.index) {
.@"error" => error_union_type.error_set_type,
.payload => error_union_type.payload_type,
@@ -1777,7 +1777,7 @@ pub const DeclGen = struct {
},
.array_type, .vector_type => {
const ai = ty.arrayInfo(zcu);
- if (ai.elem_type.eql(Type.u8, zcu)) {
+ if (ai.elem_type.eql(.u8, zcu)) {
const c_len = ty.arrayLenIncludingSentinel(zcu);
var literal = stringLiteral(writer, c_len);
try literal.start();
@@ -1981,8 +1981,8 @@ pub const DeclGen = struct {
const src_is_ptr = src_ty.isPtrAtRuntime(pt.zcu);
const src_eff_ty: Type = if (src_is_ptr) switch (dest_int_info.signedness) {
- .unsigned => Type.usize,
- .signed => Type.isize,
+ .unsigned => .usize,
+ .signed => .isize,
} else src_ty;
const src_bits = src_eff_ty.bitSize(zcu);
@@ -2022,8 +2022,8 @@ pub const DeclGen = struct {
const src_is_ptr = src_ty.isPtrAtRuntime(zcu);
const src_eff_ty: Type = if (src_is_ptr) switch (dest_int_info.signedness) {
- .unsigned => Type.usize,
- .signed => Type.isize,
+ .unsigned => .usize,
+ .signed => .isize,
} else src_ty;
const src_bits = src_eff_ty.bitSize(zcu);
@@ -2249,7 +2249,7 @@ pub const DeclGen = struct {
if (flags.is_threadlocal and !dg.mod.single_threaded) try fwd.writeAll("zig_threadlocal ");
try dg.renderTypeAndName(
fwd,
- Type.fromInterned(nav.typeOf(ip)),
+ .fromInterned(nav.typeOf(ip)),
.{ .nav = nav_index },
CQualifiers.init(.{ .@"const" = flags.is_const }),
nav.getAlignment(),
@@ -2321,7 +2321,7 @@ pub const DeclGen = struct {
if (is_big) try writer.print(", {}", .{int_info.signedness == .signed});
try writer.print(", {}", .{try dg.fmtIntLiteral(
- try pt.intValue(if (is_big) Type.u16 else Type.u8, int_info.bits),
+ try pt.intValue(if (is_big) .u16 else .u8, int_info.bits),
.FunctionArgument,
)});
}
@@ -2657,7 +2657,7 @@ pub fn genTypeDecl(
},
.index => |index| if (!found_existing) {
const ip = &zcu.intern_pool;
- const ty = Type.fromInterned(index);
+ const ty: Type = .fromInterned(index);
_ = try renderTypePrefix(.flush, global_ctype_pool, zcu, writer, global_ctype, .suffix, .{});
try writer.writeByte(';');
const file_scope = ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip);
@@ -2772,7 +2772,7 @@ pub fn genErrDecls(o: *Object) !void {
if (val > 1) try writer.writeAll(", ");
try writer.print("{{" ++ name_prefix ++ "{}, {}}}", .{
fmtIdent(name),
- try o.dg.fmtIntLiteral(try pt.intValue(Type.usize, name.len), .StaticInitializer),
+ try o.dg.fmtIntLiteral(try pt.intValue(.usize, name.len), .StaticInitializer),
});
}
try writer.writeAll("};\n");
@@ -2788,8 +2788,8 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
const val = lazy_fn.value_ptr;
switch (key) {
.tag_name => |enum_ty_ip| {
- const enum_ty = Type.fromInterned(enum_ty_ip);
- const name_slice_ty = Type.slice_const_u8_sentinel_0;
+ const enum_ty: Type = .fromInterned(enum_ty_ip);
+ const name_slice_ty: Type = .slice_const_u8_sentinel_0;
try w.writeAll("static ");
try o.dg.renderType(w, name_slice_ty);
@@ -2822,7 +2822,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
try o.dg.renderType(w, name_slice_ty);
try w.print("){{{}, {}}};\n", .{
fmtIdent("name"),
- try o.dg.fmtIntLiteral(try pt.intValue(Type.usize, tag_name_len), .Other),
+ try o.dg.fmtIntLiteral(try pt.intValue(.usize, tag_name_len), .Other),
});
try w.writeAll(" }\n");
@@ -2966,7 +2966,7 @@ pub fn genDecl(o: *Object) !void {
const zcu = pt.zcu;
const ip = &zcu.intern_pool;
const nav = ip.getNav(o.dg.pass.nav);
- const nav_ty = Type.fromInterned(nav.typeOf(ip));
+ const nav_ty: Type = .fromInterned(nav.typeOf(ip));
if (!nav_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return;
switch (ip.indexToKey(nav.status.fully_resolved.val)) {
@@ -3717,7 +3717,7 @@ fn airArg(f: *Function, inst: Air.Inst.Index) !CValue {
if (f.liveness.isUnused(inst)) {
const writer = f.object.writer();
try writer.writeByte('(');
- try f.renderType(writer, Type.void);
+ try f.renderType(writer, .void);
try writer.writeByte(')');
try f.writeCValue(writer, result, .Other);
try writer.writeAll(";\n");
@@ -3735,7 +3735,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
const ptr_ty = f.typeOf(ty_op.operand);
const ptr_scalar_ty = ptr_ty.scalarType(zcu);
const ptr_info = ptr_scalar_ty.ptrInfo(zcu);
- const src_ty = Type.fromInterned(ptr_info.child);
+ const src_ty: Type = .fromInterned(ptr_info.child);
if (!src_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
try reap(f, inst, &.{ty_op.operand});
@@ -3953,7 +3953,7 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {
.signed => {
const c_bits = toCIntBits(scalar_int_info.bits) orelse
return f.fail("TODO: C backend: implement integer types larger than 128 bits", .{});
- const shift_val = try pt.intValue(Type.u8, c_bits - dest_bits);
+ const shift_val = try pt.intValue(.u8, c_bits - dest_bits);
try writer.writeAll("zig_shr_");
try f.object.dg.renderTypeForBuiltinFnName(writer, scalar_ty);
@@ -4019,7 +4019,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
try writer.writeAll("memset(");
try f.writeCValue(writer, ptr_val, .FunctionArgument);
try writer.writeAll(", 0xaa, sizeof(");
- try f.renderType(writer, Type.fromInterned(ptr_info.child));
+ try f.renderType(writer, .fromInterned(ptr_info.child));
try writer.writeAll("));\n");
}
return .none;
@@ -4029,7 +4029,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
ptr_info.flags.alignment.order(src_ty.abiAlignment(zcu)).compare(.gte)
else
true;
- const is_array = lowersToArray(Type.fromInterned(ptr_info.child), pt);
+ const is_array = lowersToArray(.fromInterned(ptr_info.child), pt);
const need_memcpy = !is_aligned or is_array;
const src_val = try f.resolveInst(bin_op.rhs);
@@ -4040,7 +4040,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
if (need_memcpy) {
// For this memcpy to safely work we need the rhs to have the same
// underlying type as the lhs (i.e. they must both be arrays of the same underlying type).
- assert(src_ty.eql(Type.fromInterned(ptr_info.child), zcu));
+ assert(src_ty.eql(.fromInterned(ptr_info.child), zcu));
// If the source is a constant, writeCValue will emit a brace initialization
// so work around this by initializing into new local.
@@ -4120,7 +4120,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
if (src_ty.isPtrAtRuntime(zcu)) {
try writer.writeByte('(');
- try f.renderType(writer, Type.usize);
+ try f.renderType(writer, .usize);
try writer.writeByte(')');
}
try f.writeCValue(writer, src_val, .Other);
@@ -4343,8 +4343,8 @@ fn airEquality(
try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
const writer = f.object.writer();
- const local = try f.allocLocal(inst, Type.bool);
- const a = try Assignment.start(f, writer, CType.bool);
+ const local = try f.allocLocal(inst, .bool);
+ const a = try Assignment.start(f, writer, .bool);
try f.writeCValue(writer, local, .Other);
try a.assign(f, writer);
@@ -4401,7 +4401,7 @@ fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue {
try reap(f, inst, &.{un_op});
const writer = f.object.writer();
- const local = try f.allocLocal(inst, Type.bool);
+ const local = try f.allocLocal(inst, .bool);
try f.writeCValue(writer, local, .Other);
try writer.writeAll(" = ");
try f.writeCValue(writer, operand, .Other);
@@ -4517,7 +4517,7 @@ fn airSlice(f: *Function, inst: Air.Inst.Index) !CValue {
try a.end(f, writer);
}
{
- const a = try Assignment.start(f, writer, CType.usize);
+ const a = try Assignment.start(f, writer, .usize);
try f.writeCValueMember(writer, local, .{ .identifier = "len" });
try a.assign(f, writer);
try f.writeCValue(writer, len, .Initializer);
@@ -4585,9 +4585,9 @@ fn airCall(
else => unreachable,
};
const fn_info = zcu.typeToFunc(if (callee_is_ptr) callee_ty.childType(zcu) else callee_ty).?;
- const ret_ty = Type.fromInterned(fn_info.return_type);
+ const ret_ty: Type = .fromInterned(fn_info.return_type);
const ret_ctype: CType = if (ret_ty.isNoReturn(zcu))
- CType.void
+ .void
else
try f.ctypeFromType(ret_ty, .parameter);
@@ -4599,7 +4599,7 @@ fn airCall(
break :result .none;
} else if (f.liveness.isUnused(inst)) {
try writer.writeByte('(');
- try f.renderCType(writer, CType.void);
+ try f.renderCType(writer, .void);
try writer.writeByte(')');
break :result .none;
} else {
@@ -5081,20 +5081,20 @@ fn airBreakpoint(writer: anytype) !CValue {
fn airRetAddr(f: *Function, inst: Air.Inst.Index) !CValue {
const writer = f.object.writer();
- const local = try f.allocLocal(inst, Type.usize);
+ const local = try f.allocLocal(inst, .usize);
try f.writeCValue(writer, local, .Other);
try writer.writeAll(" = (");
- try f.renderType(writer, Type.usize);
+ try f.renderType(writer, .usize);
try writer.writeAll(")zig_return_address();\n");
return local;
}
fn airFrameAddress(f: *Function, inst: Air.Inst.Index) !CValue {
const writer = f.object.writer();
- const local = try f.allocLocal(inst, Type.usize);
+ const local = try f.allocLocal(inst, .usize);
try f.writeCValue(writer, local, .Other);
try writer.writeAll(" = (");
- try f.renderType(writer, Type.usize);
+ try f.renderType(writer, .usize);
try writer.writeAll(")zig_frame_address();\n");
return local;
}
@@ -5179,10 +5179,10 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index, is_dispatch_loop: bool) !void
try writer.writeAll("switch (");
- const lowered_condition_ty = if (condition_ty.toIntern() == .bool_type)
- Type.u1
+ const lowered_condition_ty: Type = if (condition_ty.toIntern() == .bool_type)
+ .u1
else if (condition_ty.isPtrAtRuntime(zcu))
- Type.usize
+ .usize
else
condition_ty;
if (condition_ty.toIntern() != lowered_condition_ty.toIntern()) {
@@ -5219,7 +5219,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index, is_dispatch_loop: bool) !void
}
if (condition_ty.isPtrAtRuntime(zcu)) {
try writer.writeByte('(');
- try f.renderType(writer, Type.usize);
+ try f.renderType(writer, .usize);
try writer.writeByte(')');
}
try f.object.dg.renderValue(writer, (try f.air.value(item, pt)).?, .Other);
@@ -5604,8 +5604,8 @@ fn airIsNull(
const operand = try f.resolveInst(un_op);
try reap(f, inst, &.{un_op});
- const local = try f.allocLocal(inst, Type.bool);
- const a = try Assignment.start(f, writer, CType.bool);
+ const local = try f.allocLocal(inst, .bool);
+ const a = try Assignment.start(f, writer, .bool);
try f.writeCValue(writer, local, .Other);
try a.assign(f, writer);
@@ -5750,7 +5750,7 @@ fn fieldLocation(
} {
const zcu = pt.zcu;
const ip = &zcu.intern_pool;
- const container_ty = Type.fromInterned(ip.indexToKey(container_ptr_ty.toIntern()).ptr_type.child);
+ const container_ty: Type = .fromInterned(ip.indexToKey(container_ptr_ty.toIntern()).ptr_type.child);
switch (ip.indexToKey(container_ty.toIntern())) {
.struct_type => {
const loaded_struct = ip.loadStructType(container_ty.toIntern());
@@ -5781,7 +5781,7 @@ fn fieldLocation(
const loaded_union = ip.loadUnionType(container_ty.toIntern());
switch (loaded_union.flagsUnordered(ip).layout) {
.auto, .@"extern" => {
- const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
+ const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu))
return if (loaded_union.hasTag(ip) and !container_ty.unionHasAllZeroBitFieldTypes(zcu))
.{ .field = .{ .identifier = "payload" } }
@@ -5850,7 +5850,7 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
switch (fieldLocation(container_ptr_ty, field_ptr_ty, extra.field_index, pt)) {
.begin => try f.writeCValue(writer, field_ptr_val, .Initializer),
.field => |field| {
- const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, Type.u8);
+ const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, .u8);
try writer.writeAll("((");
try f.renderType(writer, u8_ptr_ty);
@@ -5863,14 +5863,14 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
try writer.writeAll("))");
},
.byte_offset => |byte_offset| {
- const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, Type.u8);
+ const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, .u8);
try writer.writeAll("((");
try f.renderType(writer, u8_ptr_ty);
try writer.writeByte(')');
try f.writeCValue(writer, field_ptr_val, .Other);
try writer.print(" - {})", .{
- try f.fmtIntLiteral(try pt.intValue(Type.usize, byte_offset)),
+ try f.fmtIntLiteral(try pt.intValue(.usize, byte_offset)),
});
},
}
@@ -5908,14 +5908,14 @@ fn fieldPtr(
try f.writeCValueDerefMember(writer, container_ptr_val, field);
},
.byte_offset => |byte_offset| {
- const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, Type.u8);
+ const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, .u8);
try writer.writeAll("((");
try f.renderType(writer, u8_ptr_ty);
try writer.writeByte(')');
try f.writeCValue(writer, container_ptr_val, .Other);
try writer.print(" + {})", .{
- try f.fmtIntLiteral(try pt.intValue(Type.usize, byte_offset)),
+ try f.fmtIntLiteral(try pt.intValue(.usize, byte_offset)),
});
},
}
@@ -6158,7 +6158,7 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue {
const writer = f.object.writer();
const local = try f.allocLocal(inst, inst_ty);
{
- const a = try Assignment.start(f, writer, CType.bool);
+ const a = try Assignment.start(f, writer, .bool);
try f.writeCValueMember(writer, local, .{ .identifier = "is_null" });
try a.assign(f, writer);
try writer.writeAll("false");
@@ -6322,12 +6322,12 @@ fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const
const operand = try f.resolveInst(un_op);
try reap(f, inst, &.{un_op});
const operand_ty = f.typeOf(un_op);
- const local = try f.allocLocal(inst, Type.bool);
+ const local = try f.allocLocal(inst, .bool);
const err_union_ty = if (is_ptr) operand_ty.childType(zcu) else operand_ty;
const payload_ty = err_union_ty.errorUnionPayload(zcu);
const error_ty = err_union_ty.errorUnionSet(zcu);
- const a = try Assignment.start(f, writer, CType.bool);
+ const a = try Assignment.start(f, writer, .bool);
try f.writeCValue(writer, local, .Other);
try a.assign(f, writer);
const err_int_ty = try pt.errorIntType();
@@ -6385,17 +6385,17 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
if (operand_child_ctype.info(ctype_pool) == .array) {
try writer.writeByte('&');
try f.writeCValueDeref(writer, operand);
- try writer.print("[{}]", .{try f.fmtIntLiteral(try pt.intValue(Type.usize, 0))});
+ try writer.print("[{}]", .{try f.fmtIntLiteral(try pt.intValue(.usize, 0))});
} else try f.writeCValue(writer, operand, .Initializer);
}
try a.end(f, writer);
}
{
- const a = try Assignment.start(f, writer, CType.usize);
+ const a = try Assignment.start(f, writer, .usize);
try f.writeCValueMember(writer, local, .{ .identifier = "len" });
try a.assign(f, writer);
try writer.print("{}", .{
- try f.fmtIntLiteral(try pt.intValue(Type.usize, array_ty.arrayLen(zcu))),
+ try f.fmtIntLiteral(try pt.intValue(.usize, array_ty.arrayLen(zcu))),
});
try a.end(f, writer);
}
@@ -6627,7 +6627,7 @@ fn airCmpBuiltinCall(
try writer.writeByte(')');
if (!ref_ret) try writer.print("{s}{}", .{
compareOperatorC(operator),
- try f.fmtIntLiteral(try pt.intValue(Type.i32, 0)),
+ try f.fmtIntLiteral(try pt.intValue(.i32, 0)),
});
try writer.writeAll(";\n");
try v.end(f, inst, writer);
@@ -6707,7 +6707,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
try a.end(f, writer);
}
{
- const a = try Assignment.start(f, writer, CType.bool);
+ const a = try Assignment.start(f, writer, .bool);
try f.writeCValueMember(writer, local, .{ .identifier = "is_null" });
try a.assign(f, writer);
try writer.print("zig_cmpxchg_{s}((zig_atomic(", .{flavor});
@@ -6935,12 +6935,12 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
},
});
- const index = try f.allocLocal(inst, Type.usize);
+ const index = try f.allocLocal(inst, .usize);
try writer.writeAll("for (");
try f.writeCValue(writer, index, .Other);
try writer.writeAll(" = ");
- try f.object.dg.renderValue(writer, try pt.intValue(Type.usize, 0), .Initializer);
+ try f.object.dg.renderValue(writer, try pt.intValue(.usize, 0), .Initializer);
try writer.writeAll("; ");
try f.writeCValue(writer, index, .Other);
try writer.writeAll(" != ");
@@ -6976,7 +6976,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
return .none;
}
- const bitcasted = try bitcast(f, Type.u8, value, elem_ty);
+ const bitcasted = try bitcast(f, .u8, value, elem_ty);
try writer.writeAll("memset(");
switch (dest_ty.ptrSize(zcu)) {
@@ -7038,7 +7038,7 @@ fn writeArrayLen(f: *Function, writer: ArrayListWriter, dest_ptr: CValue, dest_t
const zcu = pt.zcu;
switch (dest_ty.ptrSize(zcu)) {
.one => try writer.print("{}", .{
- try f.fmtIntLiteral(try pt.intValue(Type.usize, dest_ty.childType(zcu).arrayLen(zcu))),
+ try f.fmtIntLiteral(try pt.intValue(.usize, dest_ty.childType(zcu).arrayLen(zcu))),
}),
.many, .c => unreachable,
.slice => try f.writeCValueMember(writer, dest_ptr, .{ .identifier = "len" }),
@@ -7200,11 +7200,11 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
for (0..extra.mask_len) |index| {
try f.writeCValue(writer, local, .Other);
try writer.writeByte('[');
- try f.object.dg.renderValue(writer, try pt.intValue(Type.usize, index), .Other);
+ try f.object.dg.renderValue(writer, try pt.intValue(.usize, index), .Other);
try writer.writeAll("] = ");
const mask_elem = (try mask.elemValue(pt, index)).toSignedInt(zcu);
- const src_val = try pt.intValue(Type.usize, @as(u64, @intCast(mask_elem ^ mask_elem >> 63)));
+ const src_val = try pt.intValue(.usize, @as(u64, @intCast(mask_elem ^ mask_elem >> 63)));
try f.writeCValue(writer, if (mask_elem >= 0) lhs else rhs, .Other);
try writer.writeByte('[');
@@ -7377,7 +7377,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
switch (ip.indexToKey(inst_ty.toIntern())) {
inline .array_type, .vector_type => |info, tag| {
const a: Assignment = .{
- .ctype = try f.ctypeFromType(Type.fromInterned(info.child), .complete),
+ .ctype = try f.ctypeFromType(.fromInterned(info.child), .complete),
};
for (resolved_elements, 0..) |element, i| {
try a.restart(f, writer);
@@ -7402,7 +7402,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
.auto, .@"extern" => {
var field_it = loaded_struct.iterateRuntimeOrder(ip);
while (field_it.next()) |field_index| {
- const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
+ const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
const a = try Assignment.start(f, writer, try f.ctypeFromType(field_ty, .complete));
@@ -7466,8 +7466,8 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
if (field_ty.isPtrAtRuntime(zcu)) {
try writer.writeByte('(');
try f.renderType(writer, switch (int_info.signedness) {
- .unsigned => Type.usize,
- .signed => Type.isize,
+ .unsigned => .usize,
+ .signed => .isize,
});
try writer.writeByte(')');
}
@@ -7501,7 +7501,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
},
.tuple_type => |tuple_info| for (0..tuple_info.types.len) |field_index| {
if (tuple_info.values.get(ip)[field_index] != .none) continue;
- const field_ty = Type.fromInterned(tuple_info.types.get(ip)[field_index]);
+ const field_ty: Type = .fromInterned(tuple_info.types.get(ip)[field_index]);
if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
const a = try Assignment.start(f, writer, try f.ctypeFromType(field_ty, .complete));
@@ -8141,13 +8141,13 @@ fn formatIntLiteral(
} = switch (data.ctype.info(ctype_pool)) {
.basic => |basic_info| switch (basic_info) {
else => .{
- .ctype = CType.void,
+ .ctype = .void,
.count = 1,
.endian = .little,
.homogeneous = true,
},
.zig_u128, .zig_i128 => .{
- .ctype = CType.u64,
+ .ctype = .u64,
.count = 2,
.endian = .big,
.homogeneous = false,
@@ -8253,7 +8253,7 @@ fn formatIntLiteral(
.int_info = c_limb_int_info,
.kind = data.kind,
.ctype = c_limb_ctype,
- .val = try pt.intValue_big(Type.comptime_int, c_limb_mut.toConst()),
+ .val = try pt.intValue_big(.comptime_int, c_limb_mut.toConst()),
}, fmt, options, writer);
}
}
@@ -8330,15 +8330,15 @@ const Vectorize = struct {
const pt = f.object.dg.pt;
const zcu = pt.zcu;
return if (ty.zigTypeTag(zcu) == .vector) index: {
- const local = try f.allocLocal(inst, Type.usize);
+ const local = try f.allocLocal(inst, .usize);
try writer.writeAll("for (");
try f.writeCValue(writer, local, .Other);
- try writer.print(" = {d}; ", .{try f.fmtIntLiteral(try pt.intValue(Type.usize, 0))});
+ try writer.print(" = {d}; ", .{try f.fmtIntLiteral(try pt.intValue(.usize, 0))});
try f.writeCValue(writer, local, .Other);
- try writer.print(" < {d}; ", .{try f.fmtIntLiteral(try pt.intValue(Type.usize, ty.vectorLen(zcu)))});
+ try writer.print(" < {d}; ", .{try f.fmtIntLiteral(try pt.intValue(.usize, ty.vectorLen(zcu)))});
try f.writeCValue(writer, local, .Other);
- try writer.print(" += {d}) {{\n", .{try f.fmtIntLiteral(try pt.intValue(Type.usize, 1))});
+ try writer.print(" += {d}) {{\n", .{try f.fmtIntLiteral(try pt.intValue(.usize, 1))});
f.object.indent_writer.pushIndent();
break :index .{ .index = local };
diff --git a/src/codegen/c/Type.zig b/src/codegen/c/Type.zig
index 2673576b90..53e8a6be82 100644
--- a/src/codegen/c/Type.zig
+++ b/src/codegen/c/Type.zig
@@ -1289,26 +1289,26 @@ pub const Pool = struct {
kind: Kind,
) !CType {
switch (int_info.bits) {
- 0 => return CType.void,
+ 0 => return .void,
1...8 => switch (int_info.signedness) {
- .signed => return CType.i8,
- .unsigned => return CType.u8,
+ .signed => return .i8,
+ .unsigned => return .u8,
},
9...16 => switch (int_info.signedness) {
- .signed => return CType.i16,
- .unsigned => return CType.u16,
+ .signed => return .i16,
+ .unsigned => return .u16,
},
17...32 => switch (int_info.signedness) {
- .signed => return CType.i32,
- .unsigned => return CType.u32,
+ .signed => return .i32,
+ .unsigned => return .u32,
},
33...64 => switch (int_info.signedness) {
- .signed => return CType.i64,
- .unsigned => return CType.u64,
+ .signed => return .i64,
+ .unsigned => return .u64,
},
65...128 => switch (int_info.signedness) {
- .signed => return CType.i128,
- .unsigned => return CType.u128,
+ .signed => return .i128,
+ .unsigned => return .u128,
},
else => {
const target = &mod.resolved_target.result;
@@ -1357,19 +1357,19 @@ pub const Pool = struct {
.null_type,
.undefined_type,
.enum_literal_type,
- => return CType.void,
- .u1_type, .u8_type => return CType.u8,
- .i8_type => return CType.i8,
- .u16_type => return CType.u16,
- .i16_type => return CType.i16,
- .u29_type, .u32_type => return CType.u32,
- .i32_type => return CType.i32,
- .u64_type => return CType.u64,
- .i64_type => return CType.i64,
- .u80_type, .u128_type => return CType.u128,
- .i128_type => return CType.i128,
- .usize_type => return CType.usize,
- .isize_type => return CType.isize,
+ => return .void,
+ .u1_type, .u8_type => return .u8,
+ .i8_type => return .i8,
+ .u16_type => return .u16,
+ .i16_type => return .i16,
+ .u29_type, .u32_type => return .u32,
+ .i32_type => return .i32,
+ .u64_type => return .u64,
+ .i64_type => return .i64,
+ .u80_type, .u128_type => return .u128,
+ .i128_type => return .i128,
+ .usize_type => return .usize,
+ .isize_type => return .isize,
.c_char_type => return .{ .index = .char },
.c_short_type => return .{ .index = .short },
.c_ushort_type => return .{ .index = .@"unsigned short" },
@@ -1380,12 +1380,12 @@ pub const Pool = struct {
.c_longlong_type => return .{ .index = .@"long long" },
.c_ulonglong_type => return .{ .index = .@"unsigned long long" },
.c_longdouble_type => return .{ .index = .@"long double" },
- .f16_type => return CType.f16,
- .f32_type => return CType.f32,
- .f64_type => return CType.f64,
- .f80_type => return CType.f80,
- .f128_type => return CType.f128,
- .bool_type, .optional_noreturn_type => return CType.bool,
+ .f16_type => return .f16,
+ .f32_type => return .f32,
+ .f64_type => return .f64,
+ .f80_type => return .f80,
+ .f128_type => return .f128,
+ .bool_type, .optional_noreturn_type => return .bool,
.noreturn_type,
.anyframe_type,
.generic_poison_type,
@@ -1397,19 +1397,20 @@ pub const Pool = struct {
.signedness = .unsigned,
.bits = pt.zcu.errorSetBits(),
}, mod, kind),
+
.manyptr_u8_type,
=> return pool.getPointer(allocator, .{
- .elem_ctype = CType.u8,
+ .elem_ctype = .u8,
}),
.manyptr_const_u8_type,
.manyptr_const_u8_sentinel_0_type,
=> return pool.getPointer(allocator, .{
- .elem_ctype = CType.u8,
+ .elem_ctype = .u8,
.@"const" = true,
}),
.single_const_pointer_to_comptime_int_type,
=> return pool.getPointer(allocator, .{
- .elem_ctype = CType.void,
+ .elem_ctype = .void,
.@"const" = true,
}),
.slice_const_u8_type,
@@ -1420,14 +1421,14 @@ pub const Pool = struct {
.{
.name = .{ .index = .ptr },
.ctype = try pool.getPointer(allocator, .{
- .elem_ctype = CType.u8,
+ .elem_ctype = .u8,
.@"const" = true,
}),
.alignas = AlignAs.fromAbiAlignment(Type.ptrAbiAlignment(target.*)),
},
.{
.name = .{ .index = .len },
- .ctype = CType.usize,
+ .ctype = .usize,
.alignas = AlignAs.fromAbiAlignment(
Type.intAbiAlignment(target.ptrBitWidth(), target.*),
),
@@ -1436,6 +1437,337 @@ pub const Pool = struct {
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
+ .vector_16_i8_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .i8,
+ .len = 16,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.i8.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_32_i8_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .i8,
+ .len = 32,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.i8.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_16_u8_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .u8,
+ .len = 16,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.u8.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_32_u8_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .u8,
+ .len = 32,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.u8.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_8_i16_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .i16,
+ .len = 8,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.i16.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_16_i16_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .i16,
+ .len = 16,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.i16.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_8_u16_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .u16,
+ .len = 8,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.u16.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_16_u16_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .u16,
+ .len = 16,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.u16.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_4_i32_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .i32,
+ .len = 4,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.i32.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_8_i32_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .i32,
+ .len = 8,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.i32.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_4_u32_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .u32,
+ .len = 4,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.u32.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_8_u32_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .u32,
+ .len = 8,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.u32.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_2_i64_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .i64,
+ .len = 2,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.i64.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_4_i64_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .i64,
+ .len = 4,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.i64.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_2_u64_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .u64,
+ .len = 2,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.u64.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_4_u64_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .u64,
+ .len = 4,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.u64.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_4_f16_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .f16,
+ .len = 4,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.f16.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_8_f16_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .f16,
+ .len = 8,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.f16.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_4_f32_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .f32,
+ .len = 4,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.f32.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_8_f32_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .f32,
+ .len = 8,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.f32.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_2_f64_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .f64,
+ .len = 2,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.f64.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+ .vector_4_f64_type => {
+ const vector_ctype = try pool.getVector(allocator, .{
+ .elem_ctype = .f64,
+ .len = 4,
+ });
+ if (!kind.isParameter()) return vector_ctype;
+ var fields = [_]Info.Field{
+ .{
+ .name = .{ .index = .array },
+ .ctype = vector_ctype,
+ .alignas = AlignAs.fromAbiAlignment(Type.f64.abiAlignment(zcu)),
+ },
+ };
+ return pool.fromFields(allocator, .@"struct", &fields, kind);
+ },
+
.undef,
.zero,
.zero_usize,
@@ -1521,7 +1853,7 @@ pub const Pool = struct {
},
.{
.name = .{ .index = .len },
- .ctype = CType.usize,
+ .ctype = .usize,
.alignas = AlignAs.fromAbiAlignment(
Type.intAbiAlignment(target.ptrBitWidth(), target.*),
),
@@ -1532,7 +1864,7 @@ pub const Pool = struct {
},
.array_type => |array_info| {
const len = array_info.lenIncludingSentinel();
- if (len == 0) return CType.void;
+ if (len == 0) return .void;
const elem_type = Type.fromInterned(array_info.child);
const elem_ctype = try pool.fromType(
allocator,
@@ -1542,7 +1874,7 @@ pub const Pool = struct {
mod,
kind.noParameter(),
);
- if (elem_ctype.index == .void) return CType.void;
+ if (elem_ctype.index == .void) return .void;
const array_ctype = try pool.getArray(allocator, .{
.elem_ctype = elem_ctype,
.len = len,
@@ -1558,7 +1890,7 @@ pub const Pool = struct {
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
.vector_type => |vector_info| {
- if (vector_info.len == 0) return CType.void;
+ if (vector_info.len == 0) return .void;
const elem_type = Type.fromInterned(vector_info.child);
const elem_ctype = try pool.fromType(
allocator,
@@ -1568,7 +1900,7 @@ pub const Pool = struct {
mod,
kind.noParameter(),
);
- if (elem_ctype.index == .void) return CType.void;
+ if (elem_ctype.index == .void) return .void;
const vector_ctype = try pool.getVector(allocator, .{
.elem_ctype = elem_ctype,
.len = vector_info.len,
@@ -1584,7 +1916,7 @@ pub const Pool = struct {
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
.opt_type => |payload_type| {
- if (ip.isNoReturn(payload_type)) return CType.void;
+ if (ip.isNoReturn(payload_type)) return .void;
const payload_ctype = try pool.fromType(
allocator,
scratch,
@@ -1593,7 +1925,7 @@ pub const Pool = struct {
mod,
kind.noParameter(),
);
- if (payload_ctype.index == .void) return CType.bool;
+ if (payload_ctype.index == .void) return .bool;
switch (payload_type) {
.anyerror_type => return payload_ctype,
else => switch (ip.indexToKey(payload_type)) {
@@ -1606,7 +1938,7 @@ pub const Pool = struct {
var fields = [_]Info.Field{
.{
.name = .{ .index = .is_null },
- .ctype = CType.bool,
+ .ctype = .bool,
.alignas = AlignAs.fromAbiAlignment(.@"1"),
},
.{
@@ -1666,7 +1998,7 @@ pub const Pool = struct {
if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(zcu))
fwd_decl
else
- CType.void;
+ .void;
const scratch_top = scratch.items.len;
defer scratch.shrinkRetainingCapacity(scratch_top);
try scratch.ensureUnusedCapacity(
@@ -1710,7 +2042,7 @@ pub const Pool = struct {
scratch.items.len - scratch_top,
@typeInfo(Field).@"struct".fields.len,
));
- if (fields_len == 0) return CType.void;
+ if (fields_len == 0) return .void;
try pool.ensureUnusedCapacity(allocator, 1);
const extra_index = try pool.addHashedExtra(allocator, &hasher, Aggregate, .{
.fwd_decl = fwd_decl.index,
@@ -1762,7 +2094,7 @@ pub const Pool = struct {
scratch.items.len - scratch_top,
@typeInfo(Field).@"struct".fields.len,
));
- if (fields_len == 0) return CType.void;
+ if (fields_len == 0) return .void;
if (kind.isForward()) {
try pool.ensureUnusedCapacity(allocator, 1);
const extra_index = try pool.addHashedExtra(
@@ -1801,7 +2133,7 @@ pub const Pool = struct {
if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(zcu))
fwd_decl
else
- CType.void;
+ .void;
const loaded_tag = loaded_union.loadTagType(ip);
const scratch_top = scratch.items.len;
defer scratch.shrinkRetainingCapacity(scratch_top);
@@ -1848,7 +2180,7 @@ pub const Pool = struct {
@typeInfo(Field).@"struct".fields.len,
));
if (!has_tag) {
- if (fields_len == 0) return CType.void;
+ if (fields_len == 0) return .void;
try pool.ensureUnusedCapacity(allocator, 1);
const extra_index = try pool.addHashedExtra(
allocator,
@@ -1915,7 +2247,7 @@ pub const Pool = struct {
struct_fields_len += 1;
}
}
- if (struct_fields_len == 0) return CType.void;
+ if (struct_fields_len == 0) return .void;
sortFields(struct_fields[0..struct_fields_len]);
return pool.getAggregate(allocator, .{
.tag = .@"struct",
@@ -1929,7 +2261,7 @@ pub const Pool = struct {
}, mod, kind),
}
},
- .opaque_type => return CType.void,
+ .opaque_type => return .void,
.enum_type => return pool.fromType(
allocator,
scratch,
@@ -1938,7 +2270,7 @@ pub const Pool = struct {
mod,
kind,
),
- .func_type => |func_info| if (func_info.is_generic) return CType.void else {
+ .func_type => |func_info| if (func_info.is_generic) return .void else {
const scratch_top = scratch.items.len;
defer scratch.shrinkRetainingCapacity(scratch_top);
try scratch.ensureUnusedCapacity(allocator, func_info.param_types.len);
@@ -1952,7 +2284,7 @@ pub const Pool = struct {
pt,
mod,
kind.asParameter(),
- ) else CType.void;
+ ) else .void;
for (0..func_info.param_types.len) |param_index| {
const param_type = Type.fromInterned(
func_info.param_types.get(ip)[param_index],
@@ -2033,7 +2365,7 @@ pub const Pool = struct {
pub fn eql(map_adapter: @This(), _: CType, _: void, pool_index: usize) bool {
return map_adapter.source_info.eqlAdapted(
map_adapter.source_pool,
- CType.fromPoolIndex(pool_index),
+ .fromPoolIndex(pool_index),
map_adapter.pool,
map_adapter.pool_adapter,
);
@@ -2047,7 +2379,7 @@ pub const Pool = struct {
.pool_adapter = pool_adapter,
});
errdefer _ = pool.map.pop();
- const ctype = CType.fromPoolIndex(gop.index);
+ const ctype: CType = .fromPoolIndex(gop.index);
if (!gop.found_existing) switch (source_info) {
.basic => unreachable,
.pointer => |pointer_info| pool.items.appendAssumeCapacity(.{
@@ -2232,7 +2564,7 @@ pub const Pool = struct {
CTypeAdapter{ .pool = pool },
);
if (!gop.found_existing) pool.items.appendAssumeCapacity(.{ .tag = tag, .data = data });
- return CType.fromPoolIndex(gop.index);
+ return .fromPoolIndex(gop.index);
}
fn tagExtra(
@@ -2290,7 +2622,7 @@ pub const Pool = struct {
pool.extra.shrinkRetainingCapacity(extra_index)
else
pool.items.appendAssumeCapacity(.{ .tag = tag, .data = extra_index });
- return CType.fromPoolIndex(gop.index);
+ return .fromPoolIndex(gop.index);
}
fn sortFields(fields: []Info.Field) void {