InternPool: remove more legacy values
Reinstate some tags that will be needed for comptime init.
This commit is contained in:
committed by
Andrew Kelley
parent
6e0de1d116
commit
1a4626d2cf
144
src/codegen.zig
144
src/codegen.zig
@@ -204,150 +204,6 @@ pub fn generateSymbol(
|
||||
return .ok;
|
||||
}
|
||||
|
||||
if (typed_value.val.ip_index == .none) switch (typed_value.ty.zigTypeTag(mod)) {
|
||||
.Array => switch (typed_value.val.tag()) {
|
||||
.bytes => {
|
||||
const bytes = typed_value.val.castTag(.bytes).?.data;
|
||||
const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel(mod));
|
||||
// The bytes payload already includes the sentinel, if any
|
||||
try code.ensureUnusedCapacity(len);
|
||||
code.appendSliceAssumeCapacity(bytes[0..len]);
|
||||
return Result.ok;
|
||||
},
|
||||
.str_lit => {
|
||||
const str_lit = typed_value.val.castTag(.str_lit).?.data;
|
||||
const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
|
||||
try code.ensureUnusedCapacity(bytes.len + 1);
|
||||
code.appendSliceAssumeCapacity(bytes);
|
||||
if (typed_value.ty.sentinel(mod)) |sent_val| {
|
||||
const byte = @intCast(u8, sent_val.toUnsignedInt(mod));
|
||||
code.appendAssumeCapacity(byte);
|
||||
}
|
||||
return Result.ok;
|
||||
},
|
||||
else => return Result{
|
||||
.fail = try ErrorMsg.create(
|
||||
bin_file.allocator,
|
||||
src_loc,
|
||||
"TODO implement generateSymbol for array type value: {s}",
|
||||
.{@tagName(typed_value.val.tag())},
|
||||
),
|
||||
},
|
||||
},
|
||||
.Struct => {
|
||||
if (typed_value.ty.containerLayout(mod) == .Packed) {
|
||||
const struct_obj = mod.typeToStruct(typed_value.ty).?;
|
||||
const fields = struct_obj.fields.values();
|
||||
const field_vals = typed_value.val.castTag(.aggregate).?.data;
|
||||
const abi_size = math.cast(usize, typed_value.ty.abiSize(mod)) orelse return error.Overflow;
|
||||
const current_pos = code.items.len;
|
||||
try code.resize(current_pos + abi_size);
|
||||
var bits: u16 = 0;
|
||||
|
||||
for (field_vals, 0..) |field_val, index| {
|
||||
const field_ty = fields[index].ty;
|
||||
// pointer may point to a decl which must be marked used
|
||||
// but can also result in a relocation. Therefore we handle those seperately.
|
||||
if (field_ty.zigTypeTag(mod) == .Pointer) {
|
||||
const field_size = math.cast(usize, field_ty.abiSize(mod)) orelse return error.Overflow;
|
||||
var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size);
|
||||
defer tmp_list.deinit();
|
||||
switch (try generateSymbol(bin_file, src_loc, .{
|
||||
.ty = field_ty,
|
||||
.val = field_val,
|
||||
}, &tmp_list, debug_output, reloc_info)) {
|
||||
.ok => @memcpy(code.items[current_pos..][0..tmp_list.items.len], tmp_list.items),
|
||||
.fail => |em| return Result{ .fail = em },
|
||||
}
|
||||
} else {
|
||||
field_val.writeToPackedMemory(field_ty, mod, code.items[current_pos..], bits) catch unreachable;
|
||||
}
|
||||
bits += @intCast(u16, field_ty.bitSize(mod));
|
||||
}
|
||||
|
||||
return Result.ok;
|
||||
}
|
||||
|
||||
const struct_begin = code.items.len;
|
||||
const field_vals = typed_value.val.castTag(.aggregate).?.data;
|
||||
for (field_vals, 0..) |field_val, index| {
|
||||
const field_ty = typed_value.ty.structFieldType(index, mod);
|
||||
if (!field_ty.hasRuntimeBits(mod)) continue;
|
||||
|
||||
switch (try generateSymbol(bin_file, src_loc, .{
|
||||
.ty = field_ty,
|
||||
.val = field_val,
|
||||
}, code, debug_output, reloc_info)) {
|
||||
.ok => {},
|
||||
.fail => |em| return Result{ .fail = em },
|
||||
}
|
||||
const unpadded_field_end = code.items.len - struct_begin;
|
||||
|
||||
// Pad struct members if required
|
||||
const padded_field_end = typed_value.ty.structFieldOffset(index + 1, mod);
|
||||
const padding = math.cast(usize, padded_field_end - unpadded_field_end) orelse return error.Overflow;
|
||||
|
||||
if (padding > 0) {
|
||||
try code.writer().writeByteNTimes(0, padding);
|
||||
}
|
||||
}
|
||||
|
||||
return Result.ok;
|
||||
},
|
||||
.Vector => switch (typed_value.val.tag()) {
|
||||
.bytes => {
|
||||
const bytes = typed_value.val.castTag(.bytes).?.data;
|
||||
const len = math.cast(usize, typed_value.ty.arrayLen(mod)) orelse return error.Overflow;
|
||||
const padding = math.cast(usize, typed_value.ty.abiSize(mod) - len) orelse
|
||||
return error.Overflow;
|
||||
try code.ensureUnusedCapacity(len + padding);
|
||||
code.appendSliceAssumeCapacity(bytes[0..len]);
|
||||
if (padding > 0) try code.writer().writeByteNTimes(0, padding);
|
||||
return Result.ok;
|
||||
},
|
||||
.str_lit => {
|
||||
const str_lit = typed_value.val.castTag(.str_lit).?.data;
|
||||
const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
|
||||
const padding = math.cast(usize, typed_value.ty.abiSize(mod) - str_lit.len) orelse
|
||||
return error.Overflow;
|
||||
try code.ensureUnusedCapacity(str_lit.len + padding);
|
||||
code.appendSliceAssumeCapacity(bytes);
|
||||
if (padding > 0) try code.writer().writeByteNTimes(0, padding);
|
||||
return Result.ok;
|
||||
},
|
||||
else => unreachable,
|
||||
},
|
||||
.Frame,
|
||||
.AnyFrame,
|
||||
=> return .{ .fail = try ErrorMsg.create(
|
||||
bin_file.allocator,
|
||||
src_loc,
|
||||
"TODO generateSymbol for type {}",
|
||||
.{typed_value.ty.fmt(mod)},
|
||||
) },
|
||||
.Float,
|
||||
.Union,
|
||||
.Optional,
|
||||
.ErrorUnion,
|
||||
.ErrorSet,
|
||||
.Int,
|
||||
.Enum,
|
||||
.Bool,
|
||||
.Pointer,
|
||||
=> unreachable, // handled below
|
||||
.Type,
|
||||
.Void,
|
||||
.NoReturn,
|
||||
.ComptimeFloat,
|
||||
.ComptimeInt,
|
||||
.Undefined,
|
||||
.Null,
|
||||
.Opaque,
|
||||
.EnumLiteral,
|
||||
.Fn,
|
||||
=> unreachable, // comptime-only types
|
||||
};
|
||||
|
||||
switch (mod.intern_pool.indexToKey(typed_value.val.ip_index)) {
|
||||
.int_type,
|
||||
.ptr_type,
|
||||
|
||||
Reference in New Issue
Block a user