diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-07-30 01:40:32 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-30 01:40:32 -0400 |
| commit | e5e6ceda6a98cc89e63abb62beb8557ff9f3109e (patch) | |
| tree | 4f099cece2f5dc1721b2843218b4cb072783fb6c /src/codegen.zig | |
| parent | 192b5d24cb4651ed2c6b6b1e5fee017d40ea5aa5 (diff) | |
| parent | 040c6eaaa03bbcfcdeadbe835c1c2f209e9f401e (diff) | |
| download | zig-e5e6ceda6a98cc89e63abb62beb8557ff9f3109e.tar.gz zig-e5e6ceda6a98cc89e63abb62beb8557ff9f3109e.zip | |
Merge pull request #9486 from ziglang/comptime-pointers
stage2: more principled approach to comptime pointers and garbage collection of unused anon decls
Diffstat (limited to 'src/codegen.zig')
| -rw-r--r-- | src/codegen.zig | 48 |
1 files changed, 3 insertions, 45 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 3b822c0f88..d16a87adca 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -184,6 +184,7 @@ pub fn generateSymbol( if (typed_value.val.castTag(.decl_ref)) |payload| { const decl = payload.data; if (decl.analysis != .complete) return error.AnalysisFail; + decl.alive = true; // TODO handle the dependency of this symbol on the decl's vaddr. // If the decl changes vaddr, then this symbol needs to get regenerated. const vaddr = bin_file.getDeclVAddr(decl); @@ -848,13 +849,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { .loop => try self.airLoop(inst), .not => try self.airNot(inst), .ptrtoint => try self.airPtrToInt(inst), - .ref => try self.airRef(inst), .ret => try self.airRet(inst), .store => try self.airStore(inst), .struct_field_ptr=> try self.airStructFieldPtr(inst), .struct_field_val=> try self.airStructFieldVal(inst), .switch_br => try self.airSwitch(inst), - .varptr => try self.airVarPtr(inst), .slice_ptr => try self.airSlicePtr(inst), .slice_len => try self.airSliceLen(inst), @@ -1340,13 +1339,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); } - fn airVarPtr(self: *Self, inst: Air.Inst.Index) !void { - const result: MCValue = if (self.liveness.isUnused(inst)) .dead else switch (arch) { - else => return self.fail("TODO implement varptr for {}", .{self.target.cpu.arch}), - }; - return self.finishAir(inst, result, .{ .none, .none, .none }); - } - fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void { const ty_op = self.air.instructions.items(.data)[inst].ty_op; const result: MCValue = if (self.liveness.isUnused(inst)) .dead else switch (arch) { @@ -2833,38 +2825,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { return bt.finishAir(result); } - fn airRef(self: *Self, inst: Air.Inst.Index) !void { - const ty_op = self.air.instructions.items(.data)[inst].ty_op; - const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { - const operand_ty = self.air.typeOf(ty_op.operand); - const operand = try self.resolveInst(ty_op.operand); - switch (operand) { - .unreach => unreachable, - .dead => unreachable, - .none => break :result MCValue{ .none = {} }, - - .immediate, - .register, - .ptr_stack_offset, - .ptr_embedded_in_code, - .compare_flags_unsigned, - .compare_flags_signed, - => { - const stack_offset = try self.allocMemPtr(inst); - try self.genSetStack(operand_ty, stack_offset, operand); - break :result MCValue{ .ptr_stack_offset = stack_offset }; - }, - - .stack_offset => |offset| break :result MCValue{ .ptr_stack_offset = offset }, - .embedded_in_code => |offset| break :result MCValue{ .ptr_embedded_in_code = offset }, - .memory => |vaddr| break :result MCValue{ .immediate = vaddr }, - - .undef => return self.fail("TODO implement ref on an undefined value", .{}), - } - }; - return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); - } - fn ret(self: *Self, mcv: MCValue) !void { const ret_ty = self.fn_type.fnReturnType(); try self.setRegOrMem(ret_ty, self.ret_mcv, mcv); @@ -4721,13 +4681,13 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { }, else => { if (typed_value.val.castTag(.decl_ref)) |payload| { + const decl = payload.data; + decl.alive = true; if (self.bin_file.cast(link.File.Elf)) |elf_file| { - const decl = payload.data; const got = &elf_file.program_headers.items[elf_file.phdr_got_index.?]; const got_addr = got.p_vaddr + decl.link.elf.offset_table_index * ptr_bytes; return MCValue{ .memory = got_addr }; } else if (self.bin_file.cast(link.File.MachO)) |macho_file| { - const decl = payload.data; const got_addr = blk: { const seg = macho_file.load_commands.items[macho_file.data_const_segment_cmd_index.?].Segment; const got = seg.sections.items[macho_file.got_section_index.?]; @@ -4739,11 +4699,9 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { }; return MCValue{ .memory = got_addr }; } else if (self.bin_file.cast(link.File.Coff)) |coff_file| { - const decl = payload.data; const got_addr = coff_file.offset_table_virtual_address + decl.link.coff.offset_table_index * ptr_bytes; return MCValue{ .memory = got_addr }; } else if (self.bin_file.cast(link.File.Plan9)) |p9| { - const decl = payload.data; const got_addr = p9.bases.data + decl.link.plan9.got_index.? * ptr_bytes; return MCValue{ .memory = got_addr }; } else { |
