authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-09-09 11:17:12-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-09-10 13:06:08-04:00
log0f0142527a0f2adc8f2348f0c97db80b0a24d330
treeccbddf0c53b7b02475f580e26dc002ebe7f8f868
parentcdaf3154eee467da887198d15558cb7d83296258

Dwarf: implement default field values


1 files changed, 42 insertions(+), 16 deletions(-)

src/link/Dwarf.zig+42-16
......@@ -2643,7 +2643,14 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
26432643 try uleb128(diw, nav_val.toType().abiAlignment(zcu).toByteUnits().?);
26442644 for (0..loaded_struct.field_types.len) |field_index| {
26452645 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
2646 try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);
2646 const field_init = loaded_struct.fieldInit(ip, field_index);
2647 assert(!(is_comptime and field_init == .none));
2648 try wip_nav.abbrevCode(if (is_comptime)
2649 .struct_field_comptime
2650 else if (field_init != .none)
2651 .struct_field_default
2652 else
2653 .struct_field);
26472654 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
26482655 const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index});
26492656 defer dwarf.gpa.free(field_name);
......@@ -2651,14 +2658,12 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
26512658 }
26522659 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
26532660 try wip_nav.refType(field_type);
2654 if (is_comptime) try wip_nav.blockValue(
2655 nav_src_loc,
2656 Value.fromInterned(loaded_struct.fieldInit(ip, field_index)),
2657 ) else {
2661 if (!is_comptime) {
26582662 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
26592663 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
26602664 field_type.abiAlignment(zcu).toByteUnits().?);
26612665 }
2666 if (field_init != .none) try wip_nav.blockValue(nav_src_loc, Value.fromInterned(field_init));
26622667 }
26632668 try uleb128(diw, @intFromEnum(AbbrevCode.null));
26642669 }
......@@ -3498,7 +3503,14 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
34983503 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
34993504 for (0..loaded_struct.field_types.len) |field_index| {
35003505 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
3501 try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);
3506 const field_init = loaded_struct.fieldInit(ip, field_index);
3507 assert(!(is_comptime and field_init == .none));
3508 try wip_nav.abbrevCode(if (is_comptime)
3509 .struct_field_comptime
3510 else if (field_init != .none)
3511 .struct_field_default
3512 else
3513 .struct_field);
35023514 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
35033515 const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index});
35043516 defer dwarf.gpa.free(field_name);
......@@ -3506,14 +3518,12 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
35063518 }
35073519 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
35083520 try wip_nav.refType(field_type);
3509 if (is_comptime) try wip_nav.blockValue(
3510 ty_src_loc,
3511 Value.fromInterned(loaded_struct.fieldInit(ip, field_index)),
3512 ) else {
3521 if (!is_comptime) {
35133522 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
35143523 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
35153524 field_type.abiAlignment(zcu).toByteUnits().?);
35163525 }
3526 if (field_init != .none) try wip_nav.blockValue(ty_src_loc, Value.fromInterned(field_init));
35173527 }
35183528 try uleb128(diw, @intFromEnum(AbbrevCode.null));
35193529 }
......@@ -3569,7 +3579,14 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
35693579 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
35703580 for (0..loaded_struct.field_types.len) |field_index| {
35713581 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
3572 try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);
3582 const field_init = loaded_struct.fieldInit(ip, field_index);
3583 assert(!(is_comptime and field_init == .none));
3584 try wip_nav.abbrevCode(if (is_comptime)
3585 .struct_field_comptime
3586 else if (field_init != .none)
3587 .struct_field_default
3588 else
3589 .struct_field);
35733590 if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name| try wip_nav.strp(field_name.toSlice(ip)) else {
35743591 const field_name = try std.fmt.allocPrint(dwarf.gpa, "{d}", .{field_index});
35753592 defer dwarf.gpa.free(field_name);
......@@ -3577,14 +3594,12 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
35773594 }
35783595 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
35793596 try wip_nav.refType(field_type);
3580 if (is_comptime) try wip_nav.blockValue(
3581 ty_src_loc,
3582 Value.fromInterned(loaded_struct.fieldInit(ip, field_index)),
3583 ) else {
3597 if (!is_comptime) {
35843598 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
35853599 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
35863600 field_type.abiAlignment(zcu).toByteUnits().?);
35873601 }
3602 if (field_init != .none) try wip_nav.blockValue(ty_src_loc, Value.fromInterned(field_init));
35883603 }
35893604 try uleb128(diw, @intFromEnum(AbbrevCode.null));
35903605 }
......@@ -4165,6 +4180,7 @@ const AbbrevCode = enum {
41654180 big_enum_field,
41664181 generated_field,
41674182 struct_field,
4183 struct_field_default,
41684184 struct_field_comptime,
41694185 packed_struct_field,
41704186 untagged_union_field,
......@@ -4412,13 +4428,23 @@ const AbbrevCode = enum {
44124428 .{ .alignment, .udata },
44134429 },
44144430 },
4431 .struct_field_default = .{
4432 .tag = .member,
4433 .attrs = &.{
4434 .{ .name, .strp },
4435 .{ .type, .ref_addr },
4436 .{ .data_member_location, .udata },
4437 .{ .alignment, .udata },
4438 .{ .default_value, .block },
4439 },
4440 },
44154441 .struct_field_comptime = .{
44164442 .tag = .member,
44174443 .attrs = &.{
44184444 .{ .const_expr, .flag_present },
44194445 .{ .name, .strp },
44204446 .{ .type, .ref_addr },
4421 .{ .default_value, .block },
4447 .{ .const_value, .block },
44224448 },
44234449 },
44244450 .packed_struct_field = .{