| author | |
| committer | |
| log | b3ecdb21eedeb8be099cf1ef43ceff68592593ed |
| tree | f5fb9a8412cf2b652e5d501c201064fdb219a7b5 |
| parent | bf20a4aa9eeca3c1911709bf48a8c476106042dc |
17 files changed, 135 insertions(+), 131 deletions(-)
src/arch/aarch64/CodeGen.zig+1-1| ... | ... | @@ -323,7 +323,7 @@ pub fn generate( |
| 323 | 323 | func_index: InternPool.Index, |
| 324 | 324 | air: Air, |
| 325 | 325 | liveness: Liveness, |
| 326 | code: *std.ArrayList(u8), | |
| 326 | code: *std.ArrayListUnmanaged(u8), | |
| 327 | 327 | debug_output: link.File.DebugInfoOutput, |
| 328 | 328 | ) CodeGenError!void { |
| 329 | 329 | const zcu = pt.zcu; |
src/arch/aarch64/Emit.zig+4-2| ... | ... | @@ -20,7 +20,7 @@ debug_output: link.File.DebugInfoOutput, |
| 20 | 20 | target: *const std.Target, |
| 21 | 21 | err_msg: ?*ErrorMsg = null, |
| 22 | 22 | src_loc: Zcu.LazySrcLoc, |
| 23 | code: *std.ArrayList(u8), | |
| 23 | code: *std.ArrayListUnmanaged(u8), | |
| 24 | 24 | |
| 25 | 25 | prev_di_line: u32, |
| 26 | 26 | prev_di_column: u32, |
| ... | ... | @@ -424,8 +424,10 @@ fn lowerBranches(emit: *Emit) !void { |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | fn writeInstruction(emit: *Emit, instruction: Instruction) !void { |
| 427 | const comp = emit.bin_file.comp; | |
| 428 | const gpa = comp.gpa; | |
| 427 | 429 | const endian = emit.target.cpu.arch.endian(); |
| 428 | std.mem.writeInt(u32, try emit.code.addManyAsArray(4), instruction.toU32(), endian); | |
| 430 | std.mem.writeInt(u32, try emit.code.addManyAsArray(gpa, 4), instruction.toU32(), endian); | |
| 429 | 431 | } |
| 430 | 432 | |
| 431 | 433 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { |
src/arch/arm/CodeGen.zig+1-1| ... | ... | @@ -332,7 +332,7 @@ pub fn generate( |
| 332 | 332 | func_index: InternPool.Index, |
| 333 | 333 | air: Air, |
| 334 | 334 | liveness: Liveness, |
| 335 | code: *std.ArrayList(u8), | |
| 335 | code: *std.ArrayListUnmanaged(u8), | |
| 336 | 336 | debug_output: link.File.DebugInfoOutput, |
| 337 | 337 | ) CodeGenError!void { |
| 338 | 338 | const zcu = pt.zcu; |
src/arch/arm/Emit.zig+4-2| ... | ... | @@ -24,7 +24,7 @@ debug_output: link.File.DebugInfoOutput, |
| 24 | 24 | target: *const std.Target, |
| 25 | 25 | err_msg: ?*ErrorMsg = null, |
| 26 | 26 | src_loc: Zcu.LazySrcLoc, |
| 27 | code: *std.ArrayList(u8), | |
| 27 | code: *std.ArrayListUnmanaged(u8), | |
| 28 | 28 | |
| 29 | 29 | prev_di_line: u32, |
| 30 | 30 | prev_di_column: u32, |
| ... | ... | @@ -342,8 +342,10 @@ fn lowerBranches(emit: *Emit) !void { |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | fn writeInstruction(emit: *Emit, instruction: Instruction) !void { |
| 345 | const comp = emit.bin_file.comp; | |
| 346 | const gpa = comp.gpa; | |
| 345 | 347 | const endian = emit.target.cpu.arch.endian(); |
| 346 | std.mem.writeInt(u32, try emit.code.addManyAsArray(4), instruction.toU32(), endian); | |
| 348 | std.mem.writeInt(u32, try emit.code.addManyAsArray(gpa, 4), instruction.toU32(), endian); | |
| 347 | 349 | } |
| 348 | 350 | |
| 349 | 351 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { |
src/arch/riscv64/CodeGen.zig+2-2| ... | ... | @@ -757,7 +757,7 @@ pub fn generate( |
| 757 | 757 | func_index: InternPool.Index, |
| 758 | 758 | air: Air, |
| 759 | 759 | liveness: Liveness, |
| 760 | code: *std.ArrayList(u8), | |
| 760 | code: *std.ArrayListUnmanaged(u8), | |
| 761 | 761 | debug_output: link.File.DebugInfoOutput, |
| 762 | 762 | ) CodeGenError!void { |
| 763 | 763 | const zcu = pt.zcu; |
| ... | ... | @@ -898,7 +898,7 @@ pub fn generateLazy( |
| 898 | 898 | pt: Zcu.PerThread, |
| 899 | 899 | src_loc: Zcu.LazySrcLoc, |
| 900 | 900 | lazy_sym: link.File.LazySymbol, |
| 901 | code: *std.ArrayList(u8), | |
| 901 | code: *std.ArrayListUnmanaged(u8), | |
| 902 | 902 | debug_output: link.File.DebugInfoOutput, |
| 903 | 903 | ) CodeGenError!void { |
| 904 | 904 | const comp = bin_file.comp; |
src/arch/riscv64/Emit.zig+9-8| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | bin_file: *link.File, |
| 4 | 4 | lower: Lower, |
| 5 | 5 | debug_output: link.File.DebugInfoOutput, |
| 6 | code: *std.ArrayList(u8), | |
| 6 | code: *std.ArrayListUnmanaged(u8), | |
| 7 | 7 | |
| 8 | 8 | prev_di_line: u32, |
| 9 | 9 | prev_di_column: u32, |
| ... | ... | @@ -18,6 +18,7 @@ pub const Error = Lower.Error || error{ |
| 18 | 18 | }; |
| 19 | 19 | |
| 20 | 20 | pub fn emitMir(emit: *Emit) Error!void { |
| 21 | const gpa = emit.bin_file.comp.gpa; | |
| 21 | 22 | log.debug("mir instruction len: {}", .{emit.lower.mir.instructions.len}); |
| 22 | 23 | for (0..emit.lower.mir.instructions.len) |mir_i| { |
| 23 | 24 | const mir_index: Mir.Inst.Index = @intCast(mir_i); |
| ... | ... | @@ -30,7 +31,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 30 | 31 | var lowered_relocs = lowered.relocs; |
| 31 | 32 | for (lowered.insts, 0..) |lowered_inst, lowered_index| { |
| 32 | 33 | const start_offset: u32 = @intCast(emit.code.items.len); |
| 33 | try lowered_inst.encode(emit.code.writer()); | |
| 34 | try lowered_inst.encode(emit.code.writer(gpa)); | |
| 34 | 35 | |
| 35 | 36 | while (lowered_relocs.len > 0 and |
| 36 | 37 | lowered_relocs[0].lowered_inst_index == lowered_index) : ({ |
| ... | ... | @@ -56,13 +57,13 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 56 | 57 | const hi_r_type: u32 = @intFromEnum(std.elf.R_RISCV.HI20); |
| 57 | 58 | const lo_r_type: u32 = @intFromEnum(std.elf.R_RISCV.LO12_I); |
| 58 | 59 | |
| 59 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | |
| 60 | try atom_ptr.addReloc(gpa, .{ | |
| 60 | 61 | .r_offset = start_offset, |
| 61 | 62 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | hi_r_type, |
| 62 | 63 | .r_addend = 0, |
| 63 | 64 | }, zo); |
| 64 | 65 | |
| 65 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | |
| 66 | try atom_ptr.addReloc(gpa, .{ | |
| 66 | 67 | .r_offset = start_offset + 4, |
| 67 | 68 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | lo_r_type, |
| 68 | 69 | .r_addend = 0, |
| ... | ... | @@ -76,19 +77,19 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 76 | 77 | |
| 77 | 78 | const R_RISCV = std.elf.R_RISCV; |
| 78 | 79 | |
| 79 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | |
| 80 | try atom_ptr.addReloc(gpa, .{ | |
| 80 | 81 | .r_offset = start_offset, |
| 81 | 82 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | @intFromEnum(R_RISCV.TPREL_HI20), |
| 82 | 83 | .r_addend = 0, |
| 83 | 84 | }, zo); |
| 84 | 85 | |
| 85 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | |
| 86 | try atom_ptr.addReloc(gpa, .{ | |
| 86 | 87 | .r_offset = start_offset + 4, |
| 87 | 88 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | @intFromEnum(R_RISCV.TPREL_ADD), |
| 88 | 89 | .r_addend = 0, |
| 89 | 90 | }, zo); |
| 90 | 91 | |
| 91 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | |
| 92 | try atom_ptr.addReloc(gpa, .{ | |
| 92 | 93 | .r_offset = start_offset + 8, |
| 93 | 94 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | @intFromEnum(R_RISCV.TPREL_LO12_I), |
| 94 | 95 | .r_addend = 0, |
| ... | ... | @@ -101,7 +102,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 101 | 102 | |
| 102 | 103 | const r_type: u32 = @intFromEnum(std.elf.R_RISCV.CALL_PLT); |
| 103 | 104 | |
| 104 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | |
| 105 | try atom_ptr.addReloc(gpa, .{ | |
| 105 | 106 | .r_offset = start_offset, |
| 106 | 107 | .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | r_type, |
| 107 | 108 | .r_addend = 0, |
src/arch/sparc64/CodeGen.zig+4-4| ... | ... | @@ -54,7 +54,7 @@ liveness: Liveness, |
| 54 | 54 | bin_file: *link.File, |
| 55 | 55 | target: *const std.Target, |
| 56 | 56 | func_index: InternPool.Index, |
| 57 | code: *std.ArrayList(u8), | |
| 57 | code: *std.ArrayListUnmanaged(u8), | |
| 58 | 58 | debug_output: link.File.DebugInfoOutput, |
| 59 | 59 | err_msg: ?*ErrorMsg, |
| 60 | 60 | args: []MCValue, |
| ... | ... | @@ -265,7 +265,7 @@ pub fn generate( |
| 265 | 265 | func_index: InternPool.Index, |
| 266 | 266 | air: Air, |
| 267 | 267 | liveness: Liveness, |
| 268 | code: *std.ArrayList(u8), | |
| 268 | code: *std.ArrayListUnmanaged(u8), | |
| 269 | 269 | debug_output: link.File.DebugInfoOutput, |
| 270 | 270 | ) CodeGenError!void { |
| 271 | 271 | const zcu = pt.zcu; |
| ... | ... | @@ -283,7 +283,7 @@ pub fn generate( |
| 283 | 283 | } |
| 284 | 284 | try branch_stack.append(.{}); |
| 285 | 285 | |
| 286 | var function = Self{ | |
| 286 | var function: Self = .{ | |
| 287 | 287 | .gpa = gpa, |
| 288 | 288 | .pt = pt, |
| 289 | 289 | .air = air, |
| ... | ... | @@ -331,7 +331,7 @@ pub fn generate( |
| 331 | 331 | }; |
| 332 | 332 | defer mir.deinit(gpa); |
| 333 | 333 | |
| 334 | var emit = Emit{ | |
| 334 | var emit: Emit = .{ | |
| 335 | 335 | .mir = mir, |
| 336 | 336 | .bin_file = lf, |
| 337 | 337 | .debug_output = debug_output, |
src/arch/sparc64/Emit.zig+6-3| ... | ... | @@ -22,7 +22,7 @@ debug_output: link.File.DebugInfoOutput, |
| 22 | 22 | target: *const std.Target, |
| 23 | 23 | err_msg: ?*ErrorMsg = null, |
| 24 | 24 | src_loc: Zcu.LazySrcLoc, |
| 25 | code: *std.ArrayList(u8), | |
| 25 | code: *std.ArrayListUnmanaged(u8), | |
| 26 | 26 | |
| 27 | 27 | prev_di_line: u32, |
| 28 | 28 | prev_di_column: u32, |
| ... | ... | @@ -678,10 +678,13 @@ fn optimalBranchType(emit: *Emit, tag: Mir.Inst.Tag, offset: i64) !BranchType { |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | fn writeInstruction(emit: *Emit, instruction: Instruction) !void { |
| 681 | const comp = emit.bin_file.comp; | |
| 682 | const gpa = comp.gpa; | |
| 683 | ||
| 681 | 684 | // SPARCv9 instructions are always arranged in BE regardless of the |
| 682 | 685 | // endianness mode the CPU is running in (Section 3.1 of the ISA specification). |
| 683 | 686 | // This is to ease porting in case someone wants to do a LE SPARCv9 backend. |
| 684 | const endian = Endian.big; | |
| 687 | const endian: Endian = .big; | |
| 685 | 688 | |
| 686 | std.mem.writeInt(u32, try emit.code.addManyAsArray(4), instruction.toU32(), endian); | |
| 689 | std.mem.writeInt(u32, try emit.code.addManyAsArray(gpa, 4), instruction.toU32(), endian); | |
| 687 | 690 | } |
src/arch/x86_64/CodeGen.zig+2-2| ... | ... | @@ -817,7 +817,7 @@ pub fn generate( |
| 817 | 817 | func_index: InternPool.Index, |
| 818 | 818 | air: Air, |
| 819 | 819 | liveness: Liveness, |
| 820 | code: *std.ArrayList(u8), | |
| 820 | code: *std.ArrayListUnmanaged(u8), | |
| 821 | 821 | debug_output: link.File.DebugInfoOutput, |
| 822 | 822 | ) CodeGenError!void { |
| 823 | 823 | const zcu = pt.zcu; |
| ... | ... | @@ -970,7 +970,7 @@ pub fn generateLazy( |
| 970 | 970 | pt: Zcu.PerThread, |
| 971 | 971 | src_loc: Zcu.LazySrcLoc, |
| 972 | 972 | lazy_sym: link.File.LazySymbol, |
| 973 | code: *std.ArrayList(u8), | |
| 973 | code: *std.ArrayListUnmanaged(u8), | |
| 974 | 974 | debug_output: link.File.DebugInfoOutput, |
| 975 | 975 | ) CodeGenError!void { |
| 976 | 976 | const comp = bin_file.comp; |
src/arch/x86_64/Emit.zig+8-7| ... | ... | @@ -4,7 +4,7 @@ air: Air, |
| 4 | 4 | lower: Lower, |
| 5 | 5 | atom_index: u32, |
| 6 | 6 | debug_output: link.File.DebugInfoOutput, |
| 7 | code: *std.ArrayList(u8), | |
| 7 | code: *std.ArrayListUnmanaged(u8), | |
| 8 | 8 | |
| 9 | 9 | prev_di_loc: Loc, |
| 10 | 10 | /// Relative to the beginning of `code`. |
| ... | ... | @@ -18,6 +18,7 @@ pub const Error = Lower.Error || error{ |
| 18 | 18 | } || link.File.UpdateDebugInfoError; |
| 19 | 19 | |
| 20 | 20 | pub fn emitMir(emit: *Emit) Error!void { |
| 21 | const gpa = emit.lower.bin_file.comp.gpa; | |
| 21 | 22 | for (0..emit.lower.mir.instructions.len) |mir_i| { |
| 22 | 23 | const mir_index: Mir.Inst.Index = @intCast(mir_i); |
| 23 | 24 | try emit.code_offset_mapping.putNoClobber( |
| ... | ... | @@ -82,7 +83,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 82 | 83 | } |
| 83 | 84 | continue; |
| 84 | 85 | } |
| 85 | try lowered_inst.encode(emit.code.writer(), .{}); | |
| 86 | try lowered_inst.encode(emit.code.writer(gpa), .{}); | |
| 86 | 87 | const end_offset: u32 = @intCast(emit.code.items.len); |
| 87 | 88 | while (lowered_relocs.len > 0 and |
| 88 | 89 | lowered_relocs[0].lowered_inst_index == lowered_index) : ({ |
| ... | ... | @@ -100,7 +101,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 100 | 101 | const zo = elf_file.zigObjectPtr().?; |
| 101 | 102 | const atom_ptr = zo.symbol(emit.atom_index).atom(elf_file).?; |
| 102 | 103 | const r_type = @intFromEnum(std.elf.R_X86_64.PLT32); |
| 103 | try atom_ptr.addReloc(elf_file.base.comp.gpa, .{ | |
| 104 | try atom_ptr.addReloc(gpa, .{ | |
| 104 | 105 | .r_offset = end_offset - 4, |
| 105 | 106 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, |
| 106 | 107 | .r_addend = lowered_relocs[0].off - 4, |
| ... | ... | @@ -147,7 +148,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 147 | 148 | const zo = elf_file.zigObjectPtr().?; |
| 148 | 149 | const atom = zo.symbol(emit.atom_index).atom(elf_file).?; |
| 149 | 150 | const r_type = @intFromEnum(std.elf.R_X86_64.TLSLD); |
| 150 | try atom.addReloc(elf_file.base.comp.gpa, .{ | |
| 151 | try atom.addReloc(gpa, .{ | |
| 151 | 152 | .r_offset = end_offset - 4, |
| 152 | 153 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, |
| 153 | 154 | .r_addend = lowered_relocs[0].off - 4, |
| ... | ... | @@ -158,7 +159,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 158 | 159 | const zo = elf_file.zigObjectPtr().?; |
| 159 | 160 | const atom = zo.symbol(emit.atom_index).atom(elf_file).?; |
| 160 | 161 | const r_type = @intFromEnum(std.elf.R_X86_64.DTPOFF32); |
| 161 | try atom.addReloc(elf_file.base.comp.gpa, .{ | |
| 162 | try atom.addReloc(gpa, .{ | |
| 162 | 163 | .r_offset = end_offset - 4, |
| 163 | 164 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, |
| 164 | 165 | .r_addend = lowered_relocs[0].off, |
| ... | ... | @@ -173,7 +174,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 173 | 174 | @intFromEnum(std.elf.R_X86_64.GOTPCREL) |
| 174 | 175 | else |
| 175 | 176 | @intFromEnum(std.elf.R_X86_64.PC32); |
| 176 | try atom.addReloc(elf_file.base.comp.gpa, .{ | |
| 177 | try atom.addReloc(gpa, .{ | |
| 177 | 178 | .r_offset = end_offset - 4, |
| 178 | 179 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, |
| 179 | 180 | .r_addend = lowered_relocs[0].off - 4, |
| ... | ... | @@ -183,7 +184,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 183 | 184 | @intFromEnum(std.elf.R_X86_64.TPOFF32) |
| 184 | 185 | else |
| 185 | 186 | @intFromEnum(std.elf.R_X86_64.@"32"); |
| 186 | try atom.addReloc(elf_file.base.comp.gpa, .{ | |
| 187 | try atom.addReloc(gpa, .{ | |
| 187 | 188 | .r_offset = end_offset - 4, |
| 188 | 189 | .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, |
| 189 | 190 | .r_addend = lowered_relocs[0].off, |
src/codegen.zig+53-51| ... | ... | @@ -55,7 +55,7 @@ pub fn generateFunction( |
| 55 | 55 | func_index: InternPool.Index, |
| 56 | 56 | air: Air, |
| 57 | 57 | liveness: Liveness, |
| 58 | code: *std.ArrayList(u8), | |
| 58 | code: *std.ArrayListUnmanaged(u8), | |
| 59 | 59 | debug_output: link.File.DebugInfoOutput, |
| 60 | 60 | ) CodeGenError!void { |
| 61 | 61 | const zcu = pt.zcu; |
| ... | ... | @@ -80,7 +80,7 @@ pub fn generateLazyFunction( |
| 80 | 80 | pt: Zcu.PerThread, |
| 81 | 81 | src_loc: Zcu.LazySrcLoc, |
| 82 | 82 | lazy_sym: link.File.LazySymbol, |
| 83 | code: *std.ArrayList(u8), | |
| 83 | code: *std.ArrayListUnmanaged(u8), | |
| 84 | 84 | debug_output: link.File.DebugInfoOutput, |
| 85 | 85 | ) CodeGenError!void { |
| 86 | 86 | const zcu = pt.zcu; |
| ... | ... | @@ -110,7 +110,7 @@ pub fn generateLazySymbol( |
| 110 | 110 | lazy_sym: link.File.LazySymbol, |
| 111 | 111 | // TODO don't use an "out" parameter like this; put it in the result instead |
| 112 | 112 | alignment: *Alignment, |
| 113 | code: *std.ArrayList(u8), | |
| 113 | code: *std.ArrayListUnmanaged(u8), | |
| 114 | 114 | debug_output: link.File.DebugInfoOutput, |
| 115 | 115 | reloc_parent: link.File.RelocInfo.Parent, |
| 116 | 116 | ) CodeGenError!void { |
| ... | ... | @@ -120,6 +120,7 @@ pub fn generateLazySymbol( |
| 120 | 120 | defer tracy.end(); |
| 121 | 121 | |
| 122 | 122 | const comp = bin_file.comp; |
| 123 | const gpa = comp.gpa; | |
| 123 | 124 | const zcu = pt.zcu; |
| 124 | 125 | const ip = &zcu.intern_pool; |
| 125 | 126 | const target = comp.root_mod.resolved_target.result; |
| ... | ... | @@ -140,7 +141,7 @@ pub fn generateLazySymbol( |
| 140 | 141 | const err_names = ip.global_error_set.getNamesFromMainThread(); |
| 141 | 142 | var offset_index: u32 = @intCast(code.items.len); |
| 142 | 143 | var string_index: u32 = @intCast(4 * (1 + err_names.len + @intFromBool(err_names.len > 0))); |
| 143 | try code.resize(offset_index + string_index); | |
| 144 | try code.resize(gpa, offset_index + string_index); | |
| 144 | 145 | mem.writeInt(u32, code.items[offset_index..][0..4], @intCast(err_names.len), endian); |
| 145 | 146 | if (err_names.len == 0) return .ok; |
| 146 | 147 | offset_index += 4; |
| ... | ... | @@ -148,7 +149,7 @@ pub fn generateLazySymbol( |
| 148 | 149 | const err_name = err_name_nts.toSlice(ip); |
| 149 | 150 | mem.writeInt(u32, code.items[offset_index..][0..4], string_index, endian); |
| 150 | 151 | offset_index += 4; |
| 151 | try code.ensureUnusedCapacity(err_name.len + 1); | |
| 152 | try code.ensureUnusedCapacity(gpa, err_name.len + 1); | |
| 152 | 153 | code.appendSliceAssumeCapacity(err_name); |
| 153 | 154 | code.appendAssumeCapacity(0); |
| 154 | 155 | string_index += @intCast(err_name.len + 1); |
| ... | ... | @@ -160,7 +161,7 @@ pub fn generateLazySymbol( |
| 160 | 161 | const tag_names = enum_ty.enumFields(zcu); |
| 161 | 162 | for (0..tag_names.len) |tag_index| { |
| 162 | 163 | const tag_name = tag_names.get(ip)[tag_index].toSlice(ip); |
| 163 | try code.ensureUnusedCapacity(tag_name.len + 1); | |
| 164 | try code.ensureUnusedCapacity(gpa, tag_name.len + 1); | |
| 164 | 165 | code.appendSliceAssumeCapacity(tag_name); |
| 165 | 166 | code.appendAssumeCapacity(0); |
| 166 | 167 | } |
| ... | ... | @@ -182,13 +183,14 @@ pub fn generateSymbol( |
| 182 | 183 | pt: Zcu.PerThread, |
| 183 | 184 | src_loc: Zcu.LazySrcLoc, |
| 184 | 185 | val: Value, |
| 185 | code: *std.ArrayList(u8), | |
| 186 | code: *std.ArrayListUnmanaged(u8), | |
| 186 | 187 | reloc_parent: link.File.RelocInfo.Parent, |
| 187 | 188 | ) GenerateSymbolError!void { |
| 188 | 189 | const tracy = trace(@src()); |
| 189 | 190 | defer tracy.end(); |
| 190 | 191 | |
| 191 | 192 | const zcu = pt.zcu; |
| 193 | const gpa = zcu.gpa; | |
| 192 | 194 | const ip = &zcu.intern_pool; |
| 193 | 195 | const ty = val.typeOf(zcu); |
| 194 | 196 | |
| ... | ... | @@ -199,7 +201,7 @@ pub fn generateSymbol( |
| 199 | 201 | |
| 200 | 202 | if (val.isUndefDeep(zcu)) { |
| 201 | 203 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; |
| 202 | try code.appendNTimes(0xaa, abi_size); | |
| 204 | try code.appendNTimes(gpa, 0xaa, abi_size); | |
| 203 | 205 | return; |
| 204 | 206 | } |
| 205 | 207 | |
| ... | ... | @@ -231,7 +233,7 @@ pub fn generateSymbol( |
| 231 | 233 | .@"unreachable", |
| 232 | 234 | .generic_poison, |
| 233 | 235 | => unreachable, // non-runtime values |
| 234 | .false, .true => try code.append(switch (simple_value) { | |
| 236 | .false, .true => try code.append(gpa, switch (simple_value) { | |
| 235 | 237 | .false => 0, |
| 236 | 238 | .true => 1, |
| 237 | 239 | else => unreachable, |
| ... | ... | @@ -247,11 +249,11 @@ pub fn generateSymbol( |
| 247 | 249 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; |
| 248 | 250 | var space: Value.BigIntSpace = undefined; |
| 249 | 251 | const int_val = val.toBigInt(&space, zcu); |
| 250 | int_val.writeTwosComplement(try code.addManyAsSlice(abi_size), endian); | |
| 252 | int_val.writeTwosComplement(try code.addManyAsSlice(gpa, abi_size), endian); | |
| 251 | 253 | }, |
| 252 | 254 | .err => |err| { |
| 253 | 255 | const int = try pt.getErrorValue(err.name); |
| 254 | try code.writer().writeInt(u16, @intCast(int), endian); | |
| 256 | try code.writer(gpa).writeInt(u16, @intCast(int), endian); | |
| 255 | 257 | }, |
| 256 | 258 | .error_union => |error_union| { |
| 257 | 259 | const payload_ty = ty.errorUnionPayload(zcu); |
| ... | ... | @@ -261,7 +263,7 @@ pub fn generateSymbol( |
| 261 | 263 | }; |
| 262 | 264 | |
| 263 | 265 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 264 | try code.writer().writeInt(u16, err_val, endian); | |
| 266 | try code.writer(gpa).writeInt(u16, err_val, endian); | |
| 265 | 267 | return; |
| 266 | 268 | } |
| 267 | 269 | |
| ... | ... | @@ -271,7 +273,7 @@ pub fn generateSymbol( |
| 271 | 273 | |
| 272 | 274 | // error value first when its type is larger than the error union's payload |
| 273 | 275 | if (error_align.order(payload_align) == .gt) { |
| 274 | try code.writer().writeInt(u16, err_val, endian); | |
| 276 | try code.writer(gpa).writeInt(u16, err_val, endian); | |
| 275 | 277 | } |
| 276 | 278 | |
| 277 | 279 | // emit payload part of the error union |
| ... | ... | @@ -286,20 +288,20 @@ pub fn generateSymbol( |
| 286 | 288 | const padding = math.cast(usize, padded_end - unpadded_end) orelse return error.Overflow; |
| 287 | 289 | |
| 288 | 290 | if (padding > 0) { |
| 289 | try code.appendNTimes(0, padding); | |
| 291 | try code.appendNTimes(gpa, 0, padding); | |
| 290 | 292 | } |
| 291 | 293 | } |
| 292 | 294 | |
| 293 | 295 | // Payload size is larger than error set, so emit our error set last |
| 294 | 296 | if (error_align.compare(.lte, payload_align)) { |
| 295 | 297 | const begin = code.items.len; |
| 296 | try code.writer().writeInt(u16, err_val, endian); | |
| 298 | try code.writer(gpa).writeInt(u16, err_val, endian); | |
| 297 | 299 | const unpadded_end = code.items.len - begin; |
| 298 | 300 | const padded_end = abi_align.forward(unpadded_end); |
| 299 | 301 | const padding = math.cast(usize, padded_end - unpadded_end) orelse return error.Overflow; |
| 300 | 302 | |
| 301 | 303 | if (padding > 0) { |
| 302 | try code.appendNTimes(0, padding); | |
| 304 | try code.appendNTimes(gpa, 0, padding); | |
| 303 | 305 | } |
| 304 | 306 | } |
| 305 | 307 | }, |
| ... | ... | @@ -308,15 +310,15 @@ pub fn generateSymbol( |
| 308 | 310 | try generateSymbol(bin_file, pt, src_loc, try pt.getCoerced(Value.fromInterned(enum_tag.int), int_tag_ty), code, reloc_parent); |
| 309 | 311 | }, |
| 310 | 312 | .float => |float| switch (float.storage) { |
| 311 | .f16 => |f16_val| writeFloat(f16, f16_val, target, endian, try code.addManyAsArray(2)), | |
| 312 | .f32 => |f32_val| writeFloat(f32, f32_val, target, endian, try code.addManyAsArray(4)), | |
| 313 | .f64 => |f64_val| writeFloat(f64, f64_val, target, endian, try code.addManyAsArray(8)), | |
| 313 | .f16 => |f16_val| writeFloat(f16, f16_val, target, endian, try code.addManyAsArray(gpa, 2)), | |
| 314 | .f32 => |f32_val| writeFloat(f32, f32_val, target, endian, try code.addManyAsArray(gpa, 4)), | |
| 315 | .f64 => |f64_val| writeFloat(f64, f64_val, target, endian, try code.addManyAsArray(gpa, 8)), | |
| 314 | 316 | .f80 => |f80_val| { |
| 315 | writeFloat(f80, f80_val, target, endian, try code.addManyAsArray(10)); | |
| 317 | writeFloat(f80, f80_val, target, endian, try code.addManyAsArray(gpa, 10)); | |
| 316 | 318 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; |
| 317 | try code.appendNTimes(0, abi_size - 10); | |
| 319 | try code.appendNTimes(gpa, 0, abi_size - 10); | |
| 318 | 320 | }, |
| 319 | .f128 => |f128_val| writeFloat(f128, f128_val, target, endian, try code.addManyAsArray(16)), | |
| 321 | .f128 => |f128_val| writeFloat(f128, f128_val, target, endian, try code.addManyAsArray(gpa, 16)), | |
| 320 | 322 | }, |
| 321 | 323 | .ptr => try lowerPtr(bin_file, pt, src_loc, val.toIntern(), code, reloc_parent, 0), |
| 322 | 324 | .slice => |slice| { |
| ... | ... | @@ -332,7 +334,7 @@ pub fn generateSymbol( |
| 332 | 334 | if (payload_val) |value| { |
| 333 | 335 | try generateSymbol(bin_file, pt, src_loc, value, code, reloc_parent); |
| 334 | 336 | } else { |
| 335 | try code.appendNTimes(0, abi_size); | |
| 337 | try code.appendNTimes(gpa, 0, abi_size); | |
| 336 | 338 | } |
| 337 | 339 | } else { |
| 338 | 340 | const padding = abi_size - (math.cast(usize, payload_type.abiSize(zcu)) orelse return error.Overflow) - 1; |
| ... | ... | @@ -342,13 +344,13 @@ pub fn generateSymbol( |
| 342 | 344 | })); |
| 343 | 345 | try generateSymbol(bin_file, pt, src_loc, value, code, reloc_parent); |
| 344 | 346 | } |
| 345 | try code.writer().writeByte(@intFromBool(payload_val != null)); | |
| 346 | try code.appendNTimes(0, padding); | |
| 347 | try code.writer(gpa).writeByte(@intFromBool(payload_val != null)); | |
| 348 | try code.appendNTimes(gpa, 0, padding); | |
| 347 | 349 | } |
| 348 | 350 | }, |
| 349 | 351 | .aggregate => |aggregate| switch (ip.indexToKey(ty.toIntern())) { |
| 350 | 352 | .array_type => |array_type| switch (aggregate.storage) { |
| 351 | .bytes => |bytes| try code.appendSlice(bytes.toSlice(array_type.lenIncludingSentinel(), ip)), | |
| 353 | .bytes => |bytes| try code.appendSlice(gpa, bytes.toSlice(array_type.lenIncludingSentinel(), ip)), | |
| 352 | 354 | .elems, .repeated_elem => { |
| 353 | 355 | var index: u64 = 0; |
| 354 | 356 | while (index < array_type.lenIncludingSentinel()) : (index += 1) { |
| ... | ... | @@ -366,7 +368,7 @@ pub fn generateSymbol( |
| 366 | 368 | .vector_type => |vector_type| { |
| 367 | 369 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; |
| 368 | 370 | if (vector_type.child == .bool_type) { |
| 369 | const bytes = try code.addManyAsSlice(abi_size); | |
| 371 | const bytes = try code.addManyAsSlice(gpa, abi_size); | |
| 370 | 372 | @memset(bytes, 0xaa); |
| 371 | 373 | var index: usize = 0; |
| 372 | 374 | const len = math.cast(usize, vector_type.len) orelse return error.Overflow; |
| ... | ... | @@ -405,7 +407,7 @@ pub fn generateSymbol( |
| 405 | 407 | } |
| 406 | 408 | } else { |
| 407 | 409 | switch (aggregate.storage) { |
| 408 | .bytes => |bytes| try code.appendSlice(bytes.toSlice(vector_type.len, ip)), | |
| 410 | .bytes => |bytes| try code.appendSlice(gpa, bytes.toSlice(vector_type.len, ip)), | |
| 409 | 411 | .elems, .repeated_elem => { |
| 410 | 412 | var index: u64 = 0; |
| 411 | 413 | while (index < vector_type.len) : (index += 1) { |
| ... | ... | @@ -423,7 +425,7 @@ pub fn generateSymbol( |
| 423 | 425 | const padding = abi_size - |
| 424 | 426 | (math.cast(usize, Type.fromInterned(vector_type.child).abiSize(zcu) * vector_type.len) orelse |
| 425 | 427 | return error.Overflow); |
| 426 | if (padding > 0) try code.appendNTimes(0, padding); | |
| 428 | if (padding > 0) try code.appendNTimes(gpa, 0, padding); | |
| 427 | 429 | } |
| 428 | 430 | }, |
| 429 | 431 | .tuple_type => |tuple| { |
| ... | ... | @@ -454,7 +456,7 @@ pub fn generateSymbol( |
| 454 | 456 | return error.Overflow; |
| 455 | 457 | |
| 456 | 458 | if (padding > 0) { |
| 457 | try code.appendNTimes(0, padding); | |
| 459 | try code.appendNTimes(gpa, 0, padding); | |
| 458 | 460 | } |
| 459 | 461 | } |
| 460 | 462 | }, |
| ... | ... | @@ -464,7 +466,7 @@ pub fn generateSymbol( |
| 464 | 466 | .@"packed" => { |
| 465 | 467 | const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow; |
| 466 | 468 | const current_pos = code.items.len; |
| 467 | try code.appendNTimes(0, abi_size); | |
| 469 | try code.appendNTimes(gpa, 0, abi_size); | |
| 468 | 470 | var bits: u16 = 0; |
| 469 | 471 | |
| 470 | 472 | for (struct_type.field_types.get(ip), 0..) |field_ty, index| { |
| ... | ... | @@ -482,8 +484,8 @@ pub fn generateSymbol( |
| 482 | 484 | if (Type.fromInterned(field_ty).zigTypeTag(zcu) == .pointer) { |
| 483 | 485 | const field_size = math.cast(usize, Type.fromInterned(field_ty).abiSize(zcu)) orelse |
| 484 | 486 | return error.Overflow; |
| 485 | var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size); | |
| 486 | defer tmp_list.deinit(); | |
| 487 | var tmp_list = try std.ArrayListUnmanaged(u8).initCapacity(gpa, field_size); | |
| 488 | defer tmp_list.deinit(gpa); | |
| 487 | 489 | try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), &tmp_list, reloc_parent); |
| 488 | 490 | @memcpy(code.items[current_pos..][0..tmp_list.items.len], tmp_list.items); |
| 489 | 491 | } else { |
| ... | ... | @@ -515,7 +517,7 @@ pub fn generateSymbol( |
| 515 | 517 | usize, |
| 516 | 518 | offsets[field_index] - (code.items.len - struct_begin), |
| 517 | 519 | ) orelse return error.Overflow; |
| 518 | if (padding > 0) try code.appendNTimes(0, padding); | |
| 520 | if (padding > 0) try code.appendNTimes(gpa, 0, padding); | |
| 519 | 521 | |
| 520 | 522 | try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), code, reloc_parent); |
| 521 | 523 | } |
| ... | ... | @@ -528,7 +530,7 @@ pub fn generateSymbol( |
| 528 | 530 | std.mem.alignForward(u64, size, @max(alignment, 1)) - |
| 529 | 531 | (code.items.len - struct_begin), |
| 530 | 532 | ) orelse return error.Overflow; |
| 531 | if (padding > 0) try code.appendNTimes(0, padding); | |
| 533 | if (padding > 0) try code.appendNTimes(gpa, 0, padding); | |
| 532 | 534 | }, |
| 533 | 535 | } |
| 534 | 536 | }, |
| ... | ... | @@ -551,13 +553,13 @@ pub fn generateSymbol( |
| 551 | 553 | const field_index = ty.unionTagFieldIndex(Value.fromInterned(un.tag), zcu).?; |
| 552 | 554 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]); |
| 553 | 555 | if (!field_ty.hasRuntimeBits(zcu)) { |
| 554 | try code.appendNTimes(0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow); | |
| 556 | try code.appendNTimes(gpa, 0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow); | |
| 555 | 557 | } else { |
| 556 | 558 | try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, reloc_parent); |
| 557 | 559 | |
| 558 | 560 | const padding = math.cast(usize, layout.payload_size - field_ty.abiSize(zcu)) orelse return error.Overflow; |
| 559 | 561 | if (padding > 0) { |
| 560 | try code.appendNTimes(0, padding); | |
| 562 | try code.appendNTimes(gpa, 0, padding); | |
| 561 | 563 | } |
| 562 | 564 | } |
| 563 | 565 | } else { |
| ... | ... | @@ -568,7 +570,7 @@ pub fn generateSymbol( |
| 568 | 570 | try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, reloc_parent); |
| 569 | 571 | |
| 570 | 572 | if (layout.padding > 0) { |
| 571 | try code.appendNTimes(0, layout.padding); | |
| 573 | try code.appendNTimes(gpa, 0, layout.padding); | |
| 572 | 574 | } |
| 573 | 575 | } |
| 574 | 576 | }, |
| ... | ... | @@ -581,7 +583,7 @@ fn lowerPtr( |
| 581 | 583 | pt: Zcu.PerThread, |
| 582 | 584 | src_loc: Zcu.LazySrcLoc, |
| 583 | 585 | ptr_val: InternPool.Index, |
| 584 | code: *std.ArrayList(u8), | |
| 586 | code: *std.ArrayListUnmanaged(u8), | |
| 585 | 587 | reloc_parent: link.File.RelocInfo.Parent, |
| 586 | 588 | prev_offset: u64, |
| 587 | 589 | ) GenerateSymbolError!void { |
| ... | ... | @@ -634,7 +636,7 @@ fn lowerUavRef( |
| 634 | 636 | pt: Zcu.PerThread, |
| 635 | 637 | src_loc: Zcu.LazySrcLoc, |
| 636 | 638 | uav: InternPool.Key.Ptr.BaseAddr.Uav, |
| 637 | code: *std.ArrayList(u8), | |
| 639 | code: *std.ArrayListUnmanaged(u8), | |
| 638 | 640 | reloc_parent: link.File.RelocInfo.Parent, |
| 639 | 641 | offset: u64, |
| 640 | 642 | ) GenerateSymbolError!void { |
| ... | ... | @@ -649,7 +651,7 @@ fn lowerUavRef( |
| 649 | 651 | log.debug("lowerUavRef: ty = {}", .{uav_ty.fmt(pt)}); |
| 650 | 652 | const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn"; |
| 651 | 653 | if (!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) { |
| 652 | try code.appendNTimes(0xaa, ptr_width_bytes); | |
| 654 | try code.appendNTimes(gpa, 0xaa, ptr_width_bytes); | |
| 653 | 655 | return; |
| 654 | 656 | } |
| 655 | 657 | |
| ... | ... | @@ -667,7 +669,7 @@ fn lowerUavRef( |
| 667 | 669 | .offset = @intCast(code.items.len), |
| 668 | 670 | .pointee = .{ .uav_index = uav.val }, |
| 669 | 671 | }); |
| 670 | try code.appendNTimes(0, ptr_width_bytes); | |
| 672 | try code.appendNTimes(gpa, 0, ptr_width_bytes); | |
| 671 | 673 | return; |
| 672 | 674 | }, |
| 673 | 675 | else => {}, |
| ... | ... | @@ -686,9 +688,9 @@ fn lowerUavRef( |
| 686 | 688 | }); |
| 687 | 689 | const endian = target.cpu.arch.endian(); |
| 688 | 690 | switch (ptr_width_bytes) { |
| 689 | 2 => mem.writeInt(u16, try code.addManyAsArray(2), @intCast(vaddr), endian), | |
| 690 | 4 => mem.writeInt(u32, try code.addManyAsArray(4), @intCast(vaddr), endian), | |
| 691 | 8 => mem.writeInt(u64, try code.addManyAsArray(8), vaddr, endian), | |
| 691 | 2 => mem.writeInt(u16, try code.addManyAsArray(gpa, 2), @intCast(vaddr), endian), | |
| 692 | 4 => mem.writeInt(u32, try code.addManyAsArray(gpa, 4), @intCast(vaddr), endian), | |
| 693 | 8 => mem.writeInt(u64, try code.addManyAsArray(gpa, 8), vaddr, endian), | |
| 692 | 694 | else => unreachable, |
| 693 | 695 | } |
| 694 | 696 | } |
| ... | ... | @@ -698,7 +700,7 @@ fn lowerNavRef( |
| 698 | 700 | pt: Zcu.PerThread, |
| 699 | 701 | src_loc: Zcu.LazySrcLoc, |
| 700 | 702 | nav_index: InternPool.Nav.Index, |
| 701 | code: *std.ArrayList(u8), | |
| 703 | code: *std.ArrayListUnmanaged(u8), | |
| 702 | 704 | reloc_parent: link.File.RelocInfo.Parent, |
| 703 | 705 | offset: u64, |
| 704 | 706 | ) GenerateSymbolError!void { |
| ... | ... | @@ -712,7 +714,7 @@ fn lowerNavRef( |
| 712 | 714 | const nav_ty = Type.fromInterned(ip.getNav(nav_index).typeOf(ip)); |
| 713 | 715 | const is_fn_body = nav_ty.zigTypeTag(zcu) == .@"fn"; |
| 714 | 716 | if (!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) { |
| 715 | try code.appendNTimes(0xaa, ptr_width_bytes); | |
| 717 | try code.appendNTimes(gpa, 0xaa, ptr_width_bytes); | |
| 716 | 718 | return; |
| 717 | 719 | } |
| 718 | 720 | |
| ... | ... | @@ -730,7 +732,7 @@ fn lowerNavRef( |
| 730 | 732 | .offset = @intCast(code.items.len), |
| 731 | 733 | .pointee = .{ .nav_index = nav_index }, |
| 732 | 734 | }); |
| 733 | try code.appendNTimes(0, ptr_width_bytes); | |
| 735 | try code.appendNTimes(gpa, 0, ptr_width_bytes); | |
| 734 | 736 | return; |
| 735 | 737 | }, |
| 736 | 738 | else => {}, |
| ... | ... | @@ -743,9 +745,9 @@ fn lowerNavRef( |
| 743 | 745 | }) catch @panic("TODO rework getNavVAddr"); |
| 744 | 746 | const endian = target.cpu.arch.endian(); |
| 745 | 747 | switch (ptr_width_bytes) { |
| 746 | 2 => mem.writeInt(u16, try code.addManyAsArray(2), @intCast(vaddr), endian), | |
| 747 | 4 => mem.writeInt(u32, try code.addManyAsArray(4), @intCast(vaddr), endian), | |
| 748 | 8 => mem.writeInt(u64, try code.addManyAsArray(8), vaddr, endian), | |
| 748 | 2 => mem.writeInt(u16, try code.addManyAsArray(gpa, 2), @intCast(vaddr), endian), | |
| 749 | 4 => mem.writeInt(u32, try code.addManyAsArray(gpa, 4), @intCast(vaddr), endian), | |
| 750 | 8 => mem.writeInt(u64, try code.addManyAsArray(gpa, 8), vaddr, endian), | |
| 749 | 751 | else => unreachable, |
| 750 | 752 | } |
| 751 | 753 | } |
src/link/Coff.zig+8-8| ... | ... | @@ -1119,8 +1119,8 @@ pub fn updateFunc( |
| 1119 | 1119 | |
| 1120 | 1120 | coff.navs.getPtr(func.owner_nav).?.section = coff.text_section_index.?; |
| 1121 | 1121 | |
| 1122 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 1123 | defer code_buffer.deinit(); | |
| 1122 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 1123 | defer code_buffer.deinit(gpa); | |
| 1124 | 1124 | |
| 1125 | 1125 | codegen.generateFunction( |
| 1126 | 1126 | &coff.base, |
| ... | ... | @@ -1167,8 +1167,8 @@ fn lowerConst( |
| 1167 | 1167 | ) !LowerConstResult { |
| 1168 | 1168 | const gpa = coff.base.comp.gpa; |
| 1169 | 1169 | |
| 1170 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 1171 | defer code_buffer.deinit(); | |
| 1170 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 1171 | defer code_buffer.deinit(gpa); | |
| 1172 | 1172 | |
| 1173 | 1173 | const atom_index = try coff.createAtom(); |
| 1174 | 1174 | const sym = coff.getAtom(atom_index).getSymbolPtr(coff); |
| ... | ... | @@ -1237,8 +1237,8 @@ pub fn updateNav( |
| 1237 | 1237 | |
| 1238 | 1238 | coff.navs.getPtr(nav_index).?.section = coff.getNavOutputSection(nav_index); |
| 1239 | 1239 | |
| 1240 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 1241 | defer code_buffer.deinit(); | |
| 1240 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 1241 | defer code_buffer.deinit(gpa); | |
| 1242 | 1242 | |
| 1243 | 1243 | try codegen.generateSymbol( |
| 1244 | 1244 | &coff.base, |
| ... | ... | @@ -1267,8 +1267,8 @@ fn updateLazySymbolAtom( |
| 1267 | 1267 | const gpa = comp.gpa; |
| 1268 | 1268 | |
| 1269 | 1269 | var required_alignment: InternPool.Alignment = .none; |
| 1270 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 1271 | defer code_buffer.deinit(); | |
| 1270 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 1271 | defer code_buffer.deinit(gpa); | |
| 1272 | 1272 | |
| 1273 | 1273 | const name = try allocPrint(gpa, "__lazy_{s}_{}", .{ |
| 1274 | 1274 | @tagName(sym.kind), |
src/link/Dwarf.zig+3-4| ... | ... | @@ -1890,17 +1890,16 @@ pub const WipNav = struct { |
| 1890 | 1890 | const bytes = if (ty.hasRuntimeBits(wip_nav.pt.zcu)) ty.abiSize(wip_nav.pt.zcu) else 0; |
| 1891 | 1891 | try uleb128(diw, bytes); |
| 1892 | 1892 | if (bytes == 0) return; |
| 1893 | var dim = wip_nav.debug_info.toManaged(wip_nav.dwarf.gpa); | |
| 1894 | defer wip_nav.debug_info = dim.moveToUnmanaged(); | |
| 1893 | const old_len = wip_nav.debug_info.items.len; | |
| 1895 | 1894 | try codegen.generateSymbol( |
| 1896 | 1895 | wip_nav.dwarf.bin_file, |
| 1897 | 1896 | wip_nav.pt, |
| 1898 | 1897 | src_loc, |
| 1899 | 1898 | val, |
| 1900 | &dim, | |
| 1899 | &wip_nav.debug_info, | |
| 1901 | 1900 | .{ .debug_output = .{ .dwarf = wip_nav } }, |
| 1902 | 1901 | ); |
| 1903 | assert(dim.items.len == wip_nav.debug_info.items.len + bytes); | |
| 1902 | assert(old_len + bytes == wip_nav.debug_info.items.len); | |
| 1904 | 1903 | } |
| 1905 | 1904 | |
| 1906 | 1905 | const AbbrevCodeForForm = struct { |
src/link/Elf/ZigObject.zig+8-8| ... | ... | @@ -1431,8 +1431,8 @@ pub fn updateFunc( |
| 1431 | 1431 | const sym_index = try self.getOrCreateMetadataForNav(zcu, func.owner_nav); |
| 1432 | 1432 | self.atom(self.symbol(sym_index).ref.index).?.freeRelocs(self); |
| 1433 | 1433 | |
| 1434 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 1435 | defer code_buffer.deinit(); | |
| 1434 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 1435 | defer code_buffer.deinit(gpa); | |
| 1436 | 1436 | |
| 1437 | 1437 | var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, func.owner_nav, sym_index) else null; |
| 1438 | 1438 | defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit(); |
| ... | ... | @@ -1561,8 +1561,8 @@ pub fn updateNav( |
| 1561 | 1561 | const sym_index = try self.getOrCreateMetadataForNav(zcu, nav_index); |
| 1562 | 1562 | self.symbol(sym_index).atom(elf_file).?.freeRelocs(self); |
| 1563 | 1563 | |
| 1564 | var code_buffer = std.ArrayList(u8).init(zcu.gpa); | |
| 1565 | defer code_buffer.deinit(); | |
| 1564 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 1565 | defer code_buffer.deinit(zcu.gpa); | |
| 1566 | 1566 | |
| 1567 | 1567 | var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, nav_index, sym_index) else null; |
| 1568 | 1568 | defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit(); |
| ... | ... | @@ -1616,8 +1616,8 @@ fn updateLazySymbol( |
| 1616 | 1616 | const gpa = zcu.gpa; |
| 1617 | 1617 | |
| 1618 | 1618 | var required_alignment: InternPool.Alignment = .none; |
| 1619 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 1620 | defer code_buffer.deinit(); | |
| 1619 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 1620 | defer code_buffer.deinit(gpa); | |
| 1621 | 1621 | |
| 1622 | 1622 | const name_str_index = blk: { |
| 1623 | 1623 | const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{}", .{ |
| ... | ... | @@ -1706,8 +1706,8 @@ fn lowerConst( |
| 1706 | 1706 | ) !LowerConstResult { |
| 1707 | 1707 | const gpa = pt.zcu.gpa; |
| 1708 | 1708 | |
| 1709 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 1710 | defer code_buffer.deinit(); | |
| 1709 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 1710 | defer code_buffer.deinit(gpa); | |
| 1711 | 1711 | |
| 1712 | 1712 | const name_off = try self.addString(gpa, name); |
| 1713 | 1713 | const sym_index = try self.newSymbolWithAtom(gpa, name_off); |
src/link/MachO/ZigObject.zig+8-8| ... | ... | @@ -789,8 +789,8 @@ pub fn updateFunc( |
| 789 | 789 | const sym_index = try self.getOrCreateMetadataForNav(macho_file, func.owner_nav); |
| 790 | 790 | self.symbols.items[sym_index].getAtom(macho_file).?.freeRelocs(macho_file); |
| 791 | 791 | |
| 792 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 793 | defer code_buffer.deinit(); | |
| 792 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 793 | defer code_buffer.deinit(gpa); | |
| 794 | 794 | |
| 795 | 795 | var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, func.owner_nav, sym_index) else null; |
| 796 | 796 | defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit(); |
| ... | ... | @@ -900,8 +900,8 @@ pub fn updateNav( |
| 900 | 900 | const sym_index = try self.getOrCreateMetadataForNav(macho_file, nav_index); |
| 901 | 901 | self.symbols.items[sym_index].getAtom(macho_file).?.freeRelocs(macho_file); |
| 902 | 902 | |
| 903 | var code_buffer = std.ArrayList(u8).init(zcu.gpa); | |
| 904 | defer code_buffer.deinit(); | |
| 903 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 904 | defer code_buffer.deinit(zcu.gpa); | |
| 905 | 905 | |
| 906 | 906 | var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, nav_index, sym_index) else null; |
| 907 | 907 | defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit(); |
| ... | ... | @@ -1201,8 +1201,8 @@ fn lowerConst( |
| 1201 | 1201 | ) !LowerConstResult { |
| 1202 | 1202 | const gpa = macho_file.base.comp.gpa; |
| 1203 | 1203 | |
| 1204 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 1205 | defer code_buffer.deinit(); | |
| 1204 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 1205 | defer code_buffer.deinit(gpa); | |
| 1206 | 1206 | |
| 1207 | 1207 | const name_str = try self.addString(gpa, name); |
| 1208 | 1208 | const sym_index = try self.newSymbolWithAtom(gpa, name_str, macho_file); |
| ... | ... | @@ -1352,8 +1352,8 @@ fn updateLazySymbol( |
| 1352 | 1352 | const gpa = zcu.gpa; |
| 1353 | 1353 | |
| 1354 | 1354 | var required_alignment: Atom.Alignment = .none; |
| 1355 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 1356 | defer code_buffer.deinit(); | |
| 1355 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 1356 | defer code_buffer.deinit(gpa); | |
| 1357 | 1357 | |
| 1358 | 1358 | const name_str = blk: { |
| 1359 | 1359 | const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{}", .{ |
src/link/Plan9.zig+10-10| ... | ... | @@ -404,8 +404,8 @@ pub fn updateFunc( |
| 404 | 404 | |
| 405 | 405 | const atom_idx = try self.seeNav(pt, func.owner_nav); |
| 406 | 406 | |
| 407 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 408 | defer code_buffer.deinit(); | |
| 407 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 408 | defer code_buffer.deinit(gpa); | |
| 409 | 409 | var dbg_info_output: DebugInfoOutput = .{ |
| 410 | 410 | .dbg_line = std.ArrayList(u8).init(gpa), |
| 411 | 411 | .start_line = null, |
| ... | ... | @@ -426,7 +426,7 @@ pub fn updateFunc( |
| 426 | 426 | &code_buffer, |
| 427 | 427 | .{ .plan9 = &dbg_info_output }, |
| 428 | 428 | ); |
| 429 | const code = try code_buffer.toOwnedSlice(); | |
| 429 | const code = try code_buffer.toOwnedSlice(gpa); | |
| 430 | 430 | self.getAtomPtr(atom_idx).code = .{ |
| 431 | 431 | .code_ptr = null, |
| 432 | 432 | .other = .{ .nav_index = func.owner_nav }, |
| ... | ... | @@ -462,8 +462,8 @@ pub fn updateNav(self: *Plan9, pt: Zcu.PerThread, nav_index: InternPool.Nav.Inde |
| 462 | 462 | if (nav_init.typeOf(zcu).hasRuntimeBits(zcu)) { |
| 463 | 463 | const atom_idx = try self.seeNav(pt, nav_index); |
| 464 | 464 | |
| 465 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 466 | defer code_buffer.deinit(); | |
| 465 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 466 | defer code_buffer.deinit(gpa); | |
| 467 | 467 | // TODO we need the symbol index for symbol in the table of locals for the containing atom |
| 468 | 468 | try codegen.generateSymbol( |
| 469 | 469 | &self.base, |
| ... | ... | @@ -1060,8 +1060,8 @@ fn updateLazySymbolAtom( |
| 1060 | 1060 | const diags = &comp.link_diags; |
| 1061 | 1061 | |
| 1062 | 1062 | var required_alignment: InternPool.Alignment = .none; |
| 1063 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 1064 | defer code_buffer.deinit(); | |
| 1063 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 1064 | defer code_buffer.deinit(gpa); | |
| 1065 | 1065 | |
| 1066 | 1066 | // create the symbol for the name |
| 1067 | 1067 | const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{}", .{ |
| ... | ... | @@ -1401,16 +1401,16 @@ pub fn lowerUav( |
| 1401 | 1401 | const got_index = self.allocateGotIndex(); |
| 1402 | 1402 | gop.value_ptr.* = index; |
| 1403 | 1403 | // we need to free name latex |
| 1404 | var code_buffer = std.ArrayList(u8).init(gpa); | |
| 1404 | var code_buffer: std.ArrayListUnmanaged(u8) = .empty; | |
| 1405 | defer code_buffer.deinit(gpa); | |
| 1405 | 1406 | try codegen.generateSymbol(&self.base, pt, src_loc, val, &code_buffer, .{ .atom_index = index }); |
| 1406 | const code = code_buffer.items; | |
| 1407 | 1407 | const atom_ptr = self.getAtomPtr(index); |
| 1408 | 1408 | atom_ptr.* = .{ |
| 1409 | 1409 | .type = .d, |
| 1410 | 1410 | .offset = undefined, |
| 1411 | 1411 | .sym_index = null, |
| 1412 | 1412 | .got_index = got_index, |
| 1413 | .code = Atom.CodePtr.fromSlice(code), | |
| 1413 | .code = Atom.CodePtr.fromSlice(try code_buffer.toOwnedSlice(gpa)), | |
| 1414 | 1414 | }; |
| 1415 | 1415 | _ = try atom_ptr.getOrCreateSymbolTableEntry(self); |
| 1416 | 1416 | self.syms.items[atom_ptr.sym_index.?] = .{ |
src/link/Wasm.zig+4-10| ... | ... | @@ -1560,7 +1560,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index |
| 1560 | 1560 | const relocs_start: u32 = @intCast(wasm.relocations.len); |
| 1561 | 1561 | wasm.string_bytes_lock.lock(); |
| 1562 | 1562 | |
| 1563 | const res = try codegen.generateSymbol( | |
| 1563 | try codegen.generateSymbol( | |
| 1564 | 1564 | &wasm.base, |
| 1565 | 1565 | pt, |
| 1566 | 1566 | zcu.navSrcLoc(nav_index), |
| ... | ... | @@ -1573,15 +1573,9 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index |
| 1573 | 1573 | const relocs_len: u32 = @intCast(wasm.relocations.len - relocs_start); |
| 1574 | 1574 | wasm.string_bytes_lock.unlock(); |
| 1575 | 1575 | |
| 1576 | const code: Nav.Code = switch (res) { | |
| 1577 | .ok => .{ | |
| 1578 | .off = code_start, | |
| 1579 | .len = code_len, | |
| 1580 | }, | |
| 1581 | .fail => |em| { | |
| 1582 | try zcu.failed_codegen.put(gpa, nav_index, em); | |
| 1583 | return; | |
| 1584 | }, | |
| 1576 | const code: Nav.Code = .{ | |
| 1577 | .off = code_start, | |
| 1578 | .len = code_len, | |
| 1585 | 1579 | }; |
| 1586 | 1580 | |
| 1587 | 1581 | const gop = try wasm.navs.getOrPut(gpa, nav_index); |