authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-01-25 10:10:50+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-01-25 10:10:50+01:00
log4983da40d02632217e606098fd8a94bd7732bf0c
treec70fcfe533b5ec55ca60592815afdfb27fd57d4d
parente675af06984d0709d308e3faf60b33cadadf2bbf

self-hosted: remove unused `externally_managed` prong for Decls code


12 files changed, 49 insertions(+), 139 deletions(-)

src/arch/aarch64/CodeGen.zig+9-9
...@@ -24,7 +24,7 @@ const log = std.log.scoped(.codegen);...@@ -24,7 +24,7 @@ const log = std.log.scoped(.codegen);
24const build_options = @import("build_options");24const build_options = @import("build_options");
2525
26const GenerateSymbolError = codegen.GenerateSymbolError;26const GenerateSymbolError = codegen.GenerateSymbolError;
27const FnResult = codegen.FnResult;27const Result = codegen.Result;
28const DebugInfoOutput = codegen.DebugInfoOutput;28const DebugInfoOutput = codegen.DebugInfoOutput;
2929
30const bits = @import("bits.zig");30const bits = @import("bits.zig");
...@@ -349,7 +349,7 @@ pub fn generate(...@@ -349,7 +349,7 @@ pub fn generate(
349 liveness: Liveness,349 liveness: Liveness,
350 code: *std.ArrayList(u8),350 code: *std.ArrayList(u8),
351 debug_output: DebugInfoOutput,351 debug_output: DebugInfoOutput,
352) GenerateSymbolError!FnResult {352) GenerateSymbolError!Result {
353 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {353 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {
354 @panic("Attempted to compile for architecture that was disabled by build configuration");354 @panic("Attempted to compile for architecture that was disabled by build configuration");
355 }355 }
...@@ -392,8 +392,8 @@ pub fn generate(...@@ -392,8 +392,8 @@ pub fn generate(
392 defer function.dbg_info_relocs.deinit(bin_file.allocator);392 defer function.dbg_info_relocs.deinit(bin_file.allocator);
393393
394 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {394 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {
395 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },395 error.CodegenFail => return Result{ .fail = function.err_msg.? },
396 error.OutOfRegisters => return FnResult{396 error.OutOfRegisters => return Result{
397 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),397 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
398 },398 },
399 else => |e| return e,399 else => |e| return e,
...@@ -406,8 +406,8 @@ pub fn generate(...@@ -406,8 +406,8 @@ pub fn generate(
406 function.max_end_stack = call_info.stack_byte_count;406 function.max_end_stack = call_info.stack_byte_count;
407407
408 function.gen() catch |err| switch (err) {408 function.gen() catch |err| switch (err) {
409 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },409 error.CodegenFail => return Result{ .fail = function.err_msg.? },
410 error.OutOfRegisters => return FnResult{410 error.OutOfRegisters => return Result{
411 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),411 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
412 },412 },
413 else => |e| return e,413 else => |e| return e,
...@@ -439,14 +439,14 @@ pub fn generate(...@@ -439,14 +439,14 @@ pub fn generate(
439 defer emit.deinit();439 defer emit.deinit();
440440
441 emit.emitMir() catch |err| switch (err) {441 emit.emitMir() catch |err| switch (err) {
442 error.EmitFail => return FnResult{ .fail = emit.err_msg.? },442 error.EmitFail => return Result{ .fail = emit.err_msg.? },
443 else => |e| return e,443 else => |e| return e,
444 };444 };
445445
446 if (function.err_msg) |em| {446 if (function.err_msg) |em| {
447 return FnResult{ .fail = em };447 return Result{ .fail = em };
448 } else {448 } else {
449 return FnResult{ .appended = {} };449 return Result{ .appended = {} };
450 }450 }
451}451}
452452
src/arch/arm/CodeGen.zig+9-9
...@@ -23,7 +23,7 @@ const leb128 = std.leb;...@@ -23,7 +23,7 @@ const leb128 = std.leb;
23const log = std.log.scoped(.codegen);23const log = std.log.scoped(.codegen);
24const build_options = @import("build_options");24const build_options = @import("build_options");
2525
26const FnResult = codegen.FnResult;26const Result = codegen.Result;
27const GenerateSymbolError = codegen.GenerateSymbolError;27const GenerateSymbolError = codegen.GenerateSymbolError;
28const DebugInfoOutput = codegen.DebugInfoOutput;28const DebugInfoOutput = codegen.DebugInfoOutput;
2929
...@@ -356,7 +356,7 @@ pub fn generate(...@@ -356,7 +356,7 @@ pub fn generate(
356 liveness: Liveness,356 liveness: Liveness,
357 code: *std.ArrayList(u8),357 code: *std.ArrayList(u8),
358 debug_output: DebugInfoOutput,358 debug_output: DebugInfoOutput,
359) GenerateSymbolError!FnResult {359) GenerateSymbolError!Result {
360 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {360 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {
361 @panic("Attempted to compile for architecture that was disabled by build configuration");361 @panic("Attempted to compile for architecture that was disabled by build configuration");
362 }362 }
...@@ -399,8 +399,8 @@ pub fn generate(...@@ -399,8 +399,8 @@ pub fn generate(
399 defer function.dbg_info_relocs.deinit(bin_file.allocator);399 defer function.dbg_info_relocs.deinit(bin_file.allocator);
400400
401 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {401 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {
402 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },402 error.CodegenFail => return Result{ .fail = function.err_msg.? },
403 error.OutOfRegisters => return FnResult{403 error.OutOfRegisters => return Result{
404 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),404 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
405 },405 },
406 else => |e| return e,406 else => |e| return e,
...@@ -413,8 +413,8 @@ pub fn generate(...@@ -413,8 +413,8 @@ pub fn generate(
413 function.max_end_stack = call_info.stack_byte_count;413 function.max_end_stack = call_info.stack_byte_count;
414414
415 function.gen() catch |err| switch (err) {415 function.gen() catch |err| switch (err) {
416 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },416 error.CodegenFail => return Result{ .fail = function.err_msg.? },
417 error.OutOfRegisters => return FnResult{417 error.OutOfRegisters => return Result{
418 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),418 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
419 },419 },
420 else => |e| return e,420 else => |e| return e,
...@@ -446,14 +446,14 @@ pub fn generate(...@@ -446,14 +446,14 @@ pub fn generate(
446 defer emit.deinit();446 defer emit.deinit();
447447
448 emit.emitMir() catch |err| switch (err) {448 emit.emitMir() catch |err| switch (err) {
449 error.EmitFail => return FnResult{ .fail = emit.err_msg.? },449 error.EmitFail => return Result{ .fail = emit.err_msg.? },
450 else => |e| return e,450 else => |e| return e,
451 };451 };
452452
453 if (function.err_msg) |em| {453 if (function.err_msg) |em| {
454 return FnResult{ .fail = em };454 return Result{ .fail = em };
455 } else {455 } else {
456 return FnResult{ .appended = {} };456 return Result{ .appended = {} };
457 }457 }
458}458}
459459
src/arch/riscv64/CodeGen.zig+9-9
...@@ -22,7 +22,7 @@ const leb128 = std.leb;...@@ -22,7 +22,7 @@ const leb128 = std.leb;
22const log = std.log.scoped(.codegen);22const log = std.log.scoped(.codegen);
23const build_options = @import("build_options");23const build_options = @import("build_options");
2424
25const FnResult = @import("../../codegen.zig").FnResult;25const Result = @import("../../codegen.zig").Result;
26const GenerateSymbolError = @import("../../codegen.zig").GenerateSymbolError;26const GenerateSymbolError = @import("../../codegen.zig").GenerateSymbolError;
27const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;27const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
2828
...@@ -225,7 +225,7 @@ pub fn generate(...@@ -225,7 +225,7 @@ pub fn generate(
225 liveness: Liveness,225 liveness: Liveness,
226 code: *std.ArrayList(u8),226 code: *std.ArrayList(u8),
227 debug_output: DebugInfoOutput,227 debug_output: DebugInfoOutput,
228) GenerateSymbolError!FnResult {228) GenerateSymbolError!Result {
229 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {229 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {
230 @panic("Attempted to compile for architecture that was disabled by build configuration");230 @panic("Attempted to compile for architecture that was disabled by build configuration");
231 }231 }
...@@ -268,8 +268,8 @@ pub fn generate(...@@ -268,8 +268,8 @@ pub fn generate(
268 defer function.exitlude_jump_relocs.deinit(bin_file.allocator);268 defer function.exitlude_jump_relocs.deinit(bin_file.allocator);
269269
270 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {270 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {
271 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },271 error.CodegenFail => return Result{ .fail = function.err_msg.? },
272 error.OutOfRegisters => return FnResult{272 error.OutOfRegisters => return Result{
273 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),273 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
274 },274 },
275 else => |e| return e,275 else => |e| return e,
...@@ -282,8 +282,8 @@ pub fn generate(...@@ -282,8 +282,8 @@ pub fn generate(
282 function.max_end_stack = call_info.stack_byte_count;282 function.max_end_stack = call_info.stack_byte_count;
283283
284 function.gen() catch |err| switch (err) {284 function.gen() catch |err| switch (err) {
285 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },285 error.CodegenFail => return Result{ .fail = function.err_msg.? },
286 error.OutOfRegisters => return FnResult{286 error.OutOfRegisters => return Result{
287 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),287 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
288 },288 },
289 else => |e| return e,289 else => |e| return e,
...@@ -309,14 +309,14 @@ pub fn generate(...@@ -309,14 +309,14 @@ pub fn generate(
309 defer emit.deinit();309 defer emit.deinit();
310310
311 emit.emitMir() catch |err| switch (err) {311 emit.emitMir() catch |err| switch (err) {
312 error.EmitFail => return FnResult{ .fail = emit.err_msg.? },312 error.EmitFail => return Result{ .fail = emit.err_msg.? },
313 else => |e| return e,313 else => |e| return e,
314 };314 };
315315
316 if (function.err_msg) |em| {316 if (function.err_msg) |em| {
317 return FnResult{ .fail = em };317 return Result{ .fail = em };
318 } else {318 } else {
319 return FnResult{ .appended = {} };319 return Result{ .appended = {} };
320 }320 }
321}321}
322322
src/arch/sparc64/CodeGen.zig+9-9
...@@ -20,7 +20,7 @@ const Emit = @import("Emit.zig");...@@ -20,7 +20,7 @@ const Emit = @import("Emit.zig");
20const Liveness = @import("../../Liveness.zig");20const Liveness = @import("../../Liveness.zig");
21const Type = @import("../../type.zig").Type;21const Type = @import("../../type.zig").Type;
22const GenerateSymbolError = @import("../../codegen.zig").GenerateSymbolError;22const GenerateSymbolError = @import("../../codegen.zig").GenerateSymbolError;
23const FnResult = @import("../../codegen.zig").FnResult;23const Result = @import("../../codegen.zig").Result;
24const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;24const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
2525
26const build_options = @import("build_options");26const build_options = @import("build_options");
...@@ -265,7 +265,7 @@ pub fn generate(...@@ -265,7 +265,7 @@ pub fn generate(
265 liveness: Liveness,265 liveness: Liveness,
266 code: *std.ArrayList(u8),266 code: *std.ArrayList(u8),
267 debug_output: DebugInfoOutput,267 debug_output: DebugInfoOutput,
268) GenerateSymbolError!FnResult {268) GenerateSymbolError!Result {
269 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {269 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {
270 @panic("Attempted to compile for architecture that was disabled by build configuration");270 @panic("Attempted to compile for architecture that was disabled by build configuration");
271 }271 }
...@@ -310,8 +310,8 @@ pub fn generate(...@@ -310,8 +310,8 @@ pub fn generate(
310 defer function.exitlude_jump_relocs.deinit(bin_file.allocator);310 defer function.exitlude_jump_relocs.deinit(bin_file.allocator);
311311
312 var call_info = function.resolveCallingConventionValues(fn_type, .callee) catch |err| switch (err) {312 var call_info = function.resolveCallingConventionValues(fn_type, .callee) catch |err| switch (err) {
313 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },313 error.CodegenFail => return Result{ .fail = function.err_msg.? },
314 error.OutOfRegisters => return FnResult{314 error.OutOfRegisters => return Result{
315 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),315 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
316 },316 },
317 else => |e| return e,317 else => |e| return e,
...@@ -324,8 +324,8 @@ pub fn generate(...@@ -324,8 +324,8 @@ pub fn generate(
324 function.max_end_stack = call_info.stack_byte_count;324 function.max_end_stack = call_info.stack_byte_count;
325325
326 function.gen() catch |err| switch (err) {326 function.gen() catch |err| switch (err) {
327 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },327 error.CodegenFail => return Result{ .fail = function.err_msg.? },
328 error.OutOfRegisters => return FnResult{328 error.OutOfRegisters => return Result{
329 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),329 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
330 },330 },
331 else => |e| return e,331 else => |e| return e,
...@@ -351,14 +351,14 @@ pub fn generate(...@@ -351,14 +351,14 @@ pub fn generate(
351 defer emit.deinit();351 defer emit.deinit();
352352
353 emit.emitMir() catch |err| switch (err) {353 emit.emitMir() catch |err| switch (err) {
354 error.EmitFail => return FnResult{ .fail = emit.err_msg.? },354 error.EmitFail => return Result{ .fail = emit.err_msg.? },
355 else => |e| return e,355 else => |e| return e,
356 };356 };
357357
358 if (function.err_msg) |em| {358 if (function.err_msg) |em| {
359 return FnResult{ .fail = em };359 return Result{ .fail = em };
360 } else {360 } else {
361 return FnResult{ .appended = {} };361 return Result{ .appended = {} };
362 }362 }
363}363}
364364
src/arch/wasm/CodeGen.zig+3-10
...@@ -627,13 +627,6 @@ test "Wasm - buildOpcode" {...@@ -627,13 +627,6 @@ test "Wasm - buildOpcode" {
627 try testing.expectEqual(@as(wasm.Opcode, .f64_reinterpret_i64), f64_reinterpret_i64);627 try testing.expectEqual(@as(wasm.Opcode, .f64_reinterpret_i64), f64_reinterpret_i64);
628}628}
629629
630pub const Result = union(enum) {
631 /// The codegen bytes have been appended to `Context.code`
632 appended: void,
633 /// The data is managed externally and are part of the `Result`
634 externally_managed: []const u8,
635};
636
637/// Hashmap to store generated `WValue` for each `Air.Inst.Ref`630/// Hashmap to store generated `WValue` for each `Air.Inst.Ref`
638pub const ValueTable = std.AutoArrayHashMapUnmanaged(Air.Inst.Ref, WValue);631pub const ValueTable = std.AutoArrayHashMapUnmanaged(Air.Inst.Ref, WValue);
639632
...@@ -1171,7 +1164,7 @@ pub fn generate(...@@ -1171,7 +1164,7 @@ pub fn generate(
1171 liveness: Liveness,1164 liveness: Liveness,
1172 code: *std.ArrayList(u8),1165 code: *std.ArrayList(u8),
1173 debug_output: codegen.DebugInfoOutput,1166 debug_output: codegen.DebugInfoOutput,
1174) codegen.GenerateSymbolError!codegen.FnResult {1167) codegen.GenerateSymbolError!codegen.Result {
1175 _ = src_loc;1168 _ = src_loc;
1176 var code_gen: CodeGen = .{1169 var code_gen: CodeGen = .{
1177 .gpa = bin_file.allocator,1170 .gpa = bin_file.allocator,
...@@ -1190,11 +1183,11 @@ pub fn generate(...@@ -1190,11 +1183,11 @@ pub fn generate(
1190 defer code_gen.deinit();1183 defer code_gen.deinit();
11911184
1192 genFunc(&code_gen) catch |err| switch (err) {1185 genFunc(&code_gen) catch |err| switch (err) {
1193 error.CodegenFail => return codegen.FnResult{ .fail = code_gen.err_msg },1186 error.CodegenFail => return codegen.Result{ .fail = code_gen.err_msg },
1194 else => |e| return e,1187 else => |e| return e,
1195 };1188 };
11961189
1197 return codegen.FnResult{ .appended = {} };1190 return codegen.Result{ .appended = {} };
1198}1191}
11991192
1200fn genFunc(func: *CodeGen) InnerError!void {1193fn genFunc(func: *CodeGen) InnerError!void {
src/arch/x86_64/CodeGen.zig+9-9
...@@ -16,7 +16,7 @@ const Compilation = @import("../../Compilation.zig");...@@ -16,7 +16,7 @@ const Compilation = @import("../../Compilation.zig");
16const DebugInfoOutput = codegen.DebugInfoOutput;16const DebugInfoOutput = codegen.DebugInfoOutput;
17const DW = std.dwarf;17const DW = std.dwarf;
18const ErrorMsg = Module.ErrorMsg;18const ErrorMsg = Module.ErrorMsg;
19const FnResult = codegen.FnResult;19const Result = codegen.Result;
20const GenerateSymbolError = codegen.GenerateSymbolError;20const GenerateSymbolError = codegen.GenerateSymbolError;
21const Emit = @import("Emit.zig");21const Emit = @import("Emit.zig");
22const Liveness = @import("../../Liveness.zig");22const Liveness = @import("../../Liveness.zig");
...@@ -257,7 +257,7 @@ pub fn generate(...@@ -257,7 +257,7 @@ pub fn generate(
257 liveness: Liveness,257 liveness: Liveness,
258 code: *std.ArrayList(u8),258 code: *std.ArrayList(u8),
259 debug_output: DebugInfoOutput,259 debug_output: DebugInfoOutput,
260) GenerateSymbolError!FnResult {260) GenerateSymbolError!Result {
261 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {261 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {
262 @panic("Attempted to compile for architecture that was disabled by build configuration");262 @panic("Attempted to compile for architecture that was disabled by build configuration");
263 }263 }
...@@ -305,8 +305,8 @@ pub fn generate(...@@ -305,8 +305,8 @@ pub fn generate(
305 defer if (builtin.mode == .Debug) function.mir_to_air_map.deinit();305 defer if (builtin.mode == .Debug) function.mir_to_air_map.deinit();
306306
307 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {307 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {
308 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },308 error.CodegenFail => return Result{ .fail = function.err_msg.? },
309 error.OutOfRegisters => return FnResult{309 error.OutOfRegisters => return Result{
310 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),310 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
311 },311 },
312 else => |e| return e,312 else => |e| return e,
...@@ -319,8 +319,8 @@ pub fn generate(...@@ -319,8 +319,8 @@ pub fn generate(
319 function.max_end_stack = call_info.stack_byte_count;319 function.max_end_stack = call_info.stack_byte_count;
320320
321 function.gen() catch |err| switch (err) {321 function.gen() catch |err| switch (err) {
322 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },322 error.CodegenFail => return Result{ .fail = function.err_msg.? },
323 error.OutOfRegisters => return FnResult{323 error.OutOfRegisters => return Result{
324 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),324 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
325 },325 },
326 else => |e| return e,326 else => |e| return e,
...@@ -345,14 +345,14 @@ pub fn generate(...@@ -345,14 +345,14 @@ pub fn generate(
345 };345 };
346 defer emit.deinit();346 defer emit.deinit();
347 emit.lowerMir() catch |err| switch (err) {347 emit.lowerMir() catch |err| switch (err) {
348 error.EmitFail => return FnResult{ .fail = emit.err_msg.? },348 error.EmitFail => return Result{ .fail = emit.err_msg.? },
349 else => |e| return e,349 else => |e| return e,
350 };350 };
351351
352 if (function.err_msg) |em| {352 if (function.err_msg) |em| {
353 return FnResult{ .fail = em };353 return Result{ .fail = em };
354 } else {354 } else {
355 return FnResult{ .appended = {} };355 return Result{ .appended = {} };
356 }356 }
357}357}
358358
src/codegen.zig+1-74
...@@ -21,16 +21,9 @@ const TypedValue = @import("TypedValue.zig");...@@ -21,16 +21,9 @@ const TypedValue = @import("TypedValue.zig");
21const Value = @import("value.zig").Value;21const Value = @import("value.zig").Value;
22const Zir = @import("Zir.zig");22const Zir = @import("Zir.zig");
2323
24pub const FnResult = union(enum) {
25 /// The `code` parameter passed to `generateSymbol` has the value appended.
26 appended: void,
27 fail: *ErrorMsg,
28};
29pub const Result = union(enum) {24pub const Result = union(enum) {
30 /// The `code` parameter passed to `generateSymbol` has the value appended.25 /// The `code` parameter passed to `generateSymbol` has the value appended.
31 appended: void,26 appended: void,
32 /// The value is available externally, `code` is unused.
33 externally_managed: []const u8,
34 fail: *ErrorMsg,27 fail: *ErrorMsg,
35};28};
3629
...@@ -89,7 +82,7 @@ pub fn generateFunction(...@@ -89,7 +82,7 @@ pub fn generateFunction(
89 liveness: Liveness,82 liveness: Liveness,
90 code: *std.ArrayList(u8),83 code: *std.ArrayList(u8),
91 debug_output: DebugInfoOutput,84 debug_output: DebugInfoOutput,
92) GenerateSymbolError!FnResult {85) GenerateSymbolError!Result {
93 switch (bin_file.options.target.cpu.arch) {86 switch (bin_file.options.target.cpu.arch) {
94 .arm,87 .arm,
95 .armeb,88 .armeb,
...@@ -209,9 +202,6 @@ pub fn generateSymbol(...@@ -209,9 +202,6 @@ pub fn generateSymbol(
209 .val = elem_val,202 .val = elem_val,
210 }, code, debug_output, reloc_info)) {203 }, code, debug_output, reloc_info)) {
211 .appended => {},204 .appended => {},
212 .externally_managed => |slice| {
213 code.appendSliceAssumeCapacity(slice);
214 },
215 .fail => |em| return Result{ .fail = em },205 .fail => |em| return Result{ .fail = em },
216 }206 }
217 }207 }
...@@ -230,9 +220,6 @@ pub fn generateSymbol(...@@ -230,9 +220,6 @@ pub fn generateSymbol(
230 .val = array,220 .val = array,
231 }, code, debug_output, reloc_info)) {221 }, code, debug_output, reloc_info)) {
232 .appended => {},222 .appended => {},
233 .externally_managed => |slice| {
234 code.appendSliceAssumeCapacity(slice);
235 },
236 .fail => |em| return Result{ .fail = em },223 .fail => |em| return Result{ .fail = em },
237 }224 }
238 }225 }
...@@ -243,9 +230,6 @@ pub fn generateSymbol(...@@ -243,9 +230,6 @@ pub fn generateSymbol(
243 .val = sentinel_val,230 .val = sentinel_val,
244 }, code, debug_output, reloc_info)) {231 }, code, debug_output, reloc_info)) {
245 .appended => {},232 .appended => {},
246 .externally_managed => |slice| {
247 code.appendSliceAssumeCapacity(slice);
248 },
249 .fail => |em| return Result{ .fail = em },233 .fail => |em| return Result{ .fail = em },
250 }234 }
251 }235 }
...@@ -260,9 +244,6 @@ pub fn generateSymbol(...@@ -260,9 +244,6 @@ pub fn generateSymbol(
260 .val = sentinel_val,244 .val = sentinel_val,
261 }, code, debug_output, reloc_info)) {245 }, code, debug_output, reloc_info)) {
262 .appended => {},246 .appended => {},
263 .externally_managed => |slice| {
264 code.appendSliceAssumeCapacity(slice);
265 },
266 .fail => |em| return Result{ .fail = em },247 .fail => |em| return Result{ .fail = em },
267 }248 }
268 return Result{ .appended = {} };249 return Result{ .appended = {} };
...@@ -310,9 +291,6 @@ pub fn generateSymbol(...@@ -310,9 +291,6 @@ pub fn generateSymbol(
310 .val = slice.ptr,291 .val = slice.ptr,
311 }, code, debug_output, reloc_info)) {292 }, code, debug_output, reloc_info)) {
312 .appended => {},293 .appended => {},
313 .externally_managed => |external_slice| {
314 code.appendSliceAssumeCapacity(external_slice);
315 },
316 .fail => |em| return Result{ .fail = em },294 .fail => |em| return Result{ .fail = em },
317 }295 }
318296
...@@ -322,9 +300,6 @@ pub fn generateSymbol(...@@ -322,9 +300,6 @@ pub fn generateSymbol(
322 .val = slice.len,300 .val = slice.len,
323 }, code, debug_output, reloc_info)) {301 }, code, debug_output, reloc_info)) {
324 .appended => {},302 .appended => {},
325 .externally_managed => |external_slice| {
326 code.appendSliceAssumeCapacity(external_slice);
327 },
328 .fail => |em| return Result{ .fail = em },303 .fail => |em| return Result{ .fail = em },
329 }304 }
330305
...@@ -376,9 +351,6 @@ pub fn generateSymbol(...@@ -376,9 +351,6 @@ pub fn generateSymbol(
376 .val = container_ptr,351 .val = container_ptr,
377 }, code, debug_output, reloc_info)) {352 }, code, debug_output, reloc_info)) {
378 .appended => {},353 .appended => {},
379 .externally_managed => |external_slice| {
380 code.appendSliceAssumeCapacity(external_slice);
381 },
382 .fail => |em| return Result{ .fail = em },354 .fail => |em| return Result{ .fail = em },
383 }355 }
384 return Result{ .appended = {} };356 return Result{ .appended = {} };
...@@ -552,9 +524,6 @@ pub fn generateSymbol(...@@ -552,9 +524,6 @@ pub fn generateSymbol(
552 .appended => {524 .appended => {
553 mem.copy(u8, code.items[current_pos..], tmp_list.items);525 mem.copy(u8, code.items[current_pos..], tmp_list.items);
554 },526 },
555 .externally_managed => |external_slice| {
556 mem.copy(u8, code.items[current_pos..], external_slice);
557 },
558 .fail => |em| return Result{ .fail = em },527 .fail => |em| return Result{ .fail = em },
559 }528 }
560 } else {529 } else {
...@@ -577,9 +546,6 @@ pub fn generateSymbol(...@@ -577,9 +546,6 @@ pub fn generateSymbol(
577 .val = field_val,546 .val = field_val,
578 }, code, debug_output, reloc_info)) {547 }, code, debug_output, reloc_info)) {
579 .appended => {},548 .appended => {},
580 .externally_managed => |external_slice| {
581 code.appendSliceAssumeCapacity(external_slice);
582 },
583 .fail => |em| return Result{ .fail = em },549 .fail => |em| return Result{ .fail = em },
584 }550 }
585 const unpadded_field_end = code.items.len - struct_begin;551 const unpadded_field_end = code.items.len - struct_begin;
...@@ -613,9 +579,6 @@ pub fn generateSymbol(...@@ -613,9 +579,6 @@ pub fn generateSymbol(
613 .val = union_obj.tag,579 .val = union_obj.tag,
614 }, code, debug_output, reloc_info)) {580 }, code, debug_output, reloc_info)) {
615 .appended => {},581 .appended => {},
616 .externally_managed => |external_slice| {
617 code.appendSliceAssumeCapacity(external_slice);
618 },
619 .fail => |em| return Result{ .fail = em },582 .fail => |em| return Result{ .fail = em },
620 }583 }
621 }584 }
...@@ -633,9 +596,6 @@ pub fn generateSymbol(...@@ -633,9 +596,6 @@ pub fn generateSymbol(
633 .val = union_obj.val,596 .val = union_obj.val,
634 }, code, debug_output, reloc_info)) {597 }, code, debug_output, reloc_info)) {
635 .appended => {},598 .appended => {},
636 .externally_managed => |external_slice| {
637 code.appendSliceAssumeCapacity(external_slice);
638 },
639 .fail => |em| return Result{ .fail = em },599 .fail => |em| return Result{ .fail = em },
640 }600 }
641601
...@@ -651,9 +611,6 @@ pub fn generateSymbol(...@@ -651,9 +611,6 @@ pub fn generateSymbol(
651 .val = union_obj.tag,611 .val = union_obj.tag,
652 }, code, debug_output, reloc_info)) {612 }, code, debug_output, reloc_info)) {
653 .appended => {},613 .appended => {},
654 .externally_managed => |external_slice| {
655 code.appendSliceAssumeCapacity(external_slice);
656 },
657 .fail => |em| return Result{ .fail = em },614 .fail => |em| return Result{ .fail = em },
658 }615 }
659 }616 }
...@@ -679,9 +636,6 @@ pub fn generateSymbol(...@@ -679,9 +636,6 @@ pub fn generateSymbol(
679 .val = payload.data,636 .val = payload.data,
680 }, code, debug_output, reloc_info)) {637 }, code, debug_output, reloc_info)) {
681 .appended => {},638 .appended => {},
682 .externally_managed => |external_slice| {
683 code.appendSliceAssumeCapacity(external_slice);
684 },
685 .fail => |em| return Result{ .fail = em },639 .fail => |em| return Result{ .fail = em },
686 }640 }
687 } else if (!typed_value.val.isNull()) {641 } else if (!typed_value.val.isNull()) {
...@@ -690,9 +644,6 @@ pub fn generateSymbol(...@@ -690,9 +644,6 @@ pub fn generateSymbol(
690 .val = typed_value.val,644 .val = typed_value.val,
691 }, code, debug_output, reloc_info)) {645 }, code, debug_output, reloc_info)) {
692 .appended => {},646 .appended => {},
693 .externally_managed => |external_slice| {
694 code.appendSliceAssumeCapacity(external_slice);
695 },
696 .fail => |em| return Result{ .fail = em },647 .fail => |em| return Result{ .fail = em },
697 }648 }
698 } else {649 } else {
...@@ -709,9 +660,6 @@ pub fn generateSymbol(...@@ -709,9 +660,6 @@ pub fn generateSymbol(
709 .val = value,660 .val = value,
710 }, code, debug_output, reloc_info)) {661 }, code, debug_output, reloc_info)) {
711 .appended => {},662 .appended => {},
712 .externally_managed => |external_slice| {
713 code.appendSliceAssumeCapacity(external_slice);
714 },
715 .fail => |em| return Result{ .fail = em },663 .fail => |em| return Result{ .fail = em },
716 }664 }
717665
...@@ -741,9 +689,6 @@ pub fn generateSymbol(...@@ -741,9 +689,6 @@ pub fn generateSymbol(
741 .val = if (is_payload) Value.initTag(.zero) else typed_value.val,689 .val = if (is_payload) Value.initTag(.zero) else typed_value.val,
742 }, code, debug_output, reloc_info)) {690 }, code, debug_output, reloc_info)) {
743 .appended => {},691 .appended => {},
744 .externally_managed => |external_slice| {
745 code.appendSliceAssumeCapacity(external_slice);
746 },
747 .fail => |em| return Result{ .fail = em },692 .fail => |em| return Result{ .fail = em },
748 }693 }
749 }694 }
...@@ -757,9 +702,6 @@ pub fn generateSymbol(...@@ -757,9 +702,6 @@ pub fn generateSymbol(
757 .val = payload_val,702 .val = payload_val,
758 }, code, debug_output, reloc_info)) {703 }, code, debug_output, reloc_info)) {
759 .appended => {},704 .appended => {},
760 .externally_managed => |external_slice| {
761 code.appendSliceAssumeCapacity(external_slice);
762 },
763 .fail => |em| return Result{ .fail = em },705 .fail => |em| return Result{ .fail = em },
764 }706 }
765 const unpadded_end = code.items.len - begin;707 const unpadded_end = code.items.len - begin;
...@@ -779,9 +721,6 @@ pub fn generateSymbol(...@@ -779,9 +721,6 @@ pub fn generateSymbol(
779 .val = if (is_payload) Value.initTag(.zero) else typed_value.val,721 .val = if (is_payload) Value.initTag(.zero) else typed_value.val,
780 }, code, debug_output, reloc_info)) {722 }, code, debug_output, reloc_info)) {
781 .appended => {},723 .appended => {},
782 .externally_managed => |external_slice| {
783 code.appendSliceAssumeCapacity(external_slice);
784 },
785 .fail => |em| return Result{ .fail = em },724 .fail => |em| return Result{ .fail = em },
786 }725 }
787 const unpadded_end = code.items.len - begin;726 const unpadded_end = code.items.len - begin;
...@@ -826,9 +765,6 @@ pub fn generateSymbol(...@@ -826,9 +765,6 @@ pub fn generateSymbol(
826 .val = elem_val,765 .val = elem_val,
827 }, code, debug_output, reloc_info)) {766 }, code, debug_output, reloc_info)) {
828 .appended => {},767 .appended => {},
829 .externally_managed => |slice| {
830 code.appendSliceAssumeCapacity(slice);
831 },
832 .fail => |em| return Result{ .fail = em },768 .fail => |em| return Result{ .fail = em },
833 }769 }
834 }770 }
...@@ -846,9 +782,6 @@ pub fn generateSymbol(...@@ -846,9 +782,6 @@ pub fn generateSymbol(
846 .val = array,782 .val = array,
847 }, code, debug_output, reloc_info)) {783 }, code, debug_output, reloc_info)) {
848 .appended => {},784 .appended => {},
849 .externally_managed => |slice| {
850 code.appendSliceAssumeCapacity(slice);
851 },
852 .fail => |em| return Result{ .fail = em },785 .fail => |em| return Result{ .fail = em },
853 }786 }
854 }787 }
...@@ -902,9 +835,6 @@ fn lowerDeclRef(...@@ -902,9 +835,6 @@ fn lowerDeclRef(
902 .val = typed_value.val,835 .val = typed_value.val,
903 }, code, debug_output, reloc_info)) {836 }, code, debug_output, reloc_info)) {
904 .appended => {},837 .appended => {},
905 .externally_managed => |external_slice| {
906 code.appendSliceAssumeCapacity(external_slice);
907 },
908 .fail => |em| return Result{ .fail = em },838 .fail => |em| return Result{ .fail = em },
909 }839 }
910840
...@@ -918,9 +848,6 @@ fn lowerDeclRef(...@@ -918,9 +848,6 @@ fn lowerDeclRef(
918 .val = Value.initPayload(&slice_len.base),848 .val = Value.initPayload(&slice_len.base),
919 }, code, debug_output, reloc_info)) {849 }, code, debug_output, reloc_info)) {
920 .appended => {},850 .appended => {},
921 .externally_managed => |external_slice| {
922 code.appendSliceAssumeCapacity(external_slice);
923 },
924 .fail => |em| return Result{ .fail = em },851 .fail => |em| return Result{ .fail = em },
925 }852 }
926853
src/link/Coff.zig-2
...@@ -981,7 +981,6 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In...@@ -981,7 +981,6 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In
981 .parent_atom_index = atom.sym_index,981 .parent_atom_index = atom.sym_index,
982 });982 });
983 const code = switch (res) {983 const code = switch (res) {
984 .externally_managed => |x| x,
985 .appended => code_buffer.items,984 .appended => code_buffer.items,
986 .fail => |em| {985 .fail => |em| {
987 decl.analysis = .codegen_failure;986 decl.analysis = .codegen_failure;
...@@ -1042,7 +1041,6 @@ pub fn updateDecl(self: *Coff, module: *Module, decl_index: Module.Decl.Index) !...@@ -1042,7 +1041,6 @@ pub fn updateDecl(self: *Coff, module: *Module, decl_index: Module.Decl.Index) !
1042 .parent_atom_index = decl.link.coff.sym_index,1041 .parent_atom_index = decl.link.coff.sym_index,
1043 });1042 });
1044 const code = switch (res) {1043 const code = switch (res) {
1045 .externally_managed => |x| x,
1046 .appended => code_buffer.items,1044 .appended => code_buffer.items,
1047 .fail => |em| {1045 .fail => |em| {
1048 decl.analysis = .codegen_failure;1046 decl.analysis = .codegen_failure;
src/link/Elf.zig-2
...@@ -2553,7 +2553,6 @@ pub fn updateDecl(self: *Elf, module: *Module, decl_index: Module.Decl.Index) !v...@@ -2553,7 +2553,6 @@ pub fn updateDecl(self: *Elf, module: *Module, decl_index: Module.Decl.Index) !v
2553 });2553 });
25542554
2555 const code = switch (res) {2555 const code = switch (res) {
2556 .externally_managed => |x| x,
2557 .appended => code_buffer.items,2556 .appended => code_buffer.items,
2558 .fail => |em| {2557 .fail => |em| {
2559 decl.analysis = .codegen_failure;2558 decl.analysis = .codegen_failure;
...@@ -2618,7 +2617,6 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module...@@ -2618,7 +2617,6 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module
2618 .parent_atom_index = atom.local_sym_index,2617 .parent_atom_index = atom.local_sym_index,
2619 });2618 });
2620 const code = switch (res) {2619 const code = switch (res) {
2621 .externally_managed => |x| x,
2622 .appended => code_buffer.items,2620 .appended => code_buffer.items,
2623 .fail => |em| {2621 .fail => |em| {
2624 decl.analysis = .codegen_failure;2622 decl.analysis = .codegen_failure;
src/link/MachO.zig-2
...@@ -2082,7 +2082,6 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu...@@ -2082,7 +2082,6 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu
2082 .parent_atom_index = atom.sym_index,2082 .parent_atom_index = atom.sym_index,
2083 });2083 });
2084 const code = switch (res) {2084 const code = switch (res) {
2085 .externally_managed => |x| x,
2086 .appended => code_buffer.items,2085 .appended => code_buffer.items,
2087 .fail => |em| {2086 .fail => |em| {
2088 decl.analysis = .codegen_failure;2087 decl.analysis = .codegen_failure;
...@@ -2167,7 +2166,6 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)...@@ -2167,7 +2166,6 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
2167 });2166 });
21682167
2169 const code = switch (res) {2168 const code = switch (res) {
2170 .externally_managed => |x| x,
2171 .appended => code_buffer.items,2169 .appended => code_buffer.items,
2172 .fail => |em| {2170 .fail => |em| {
2173 decl.analysis = .codegen_failure;2171 decl.analysis = .codegen_failure;
src/link/Plan9.zig-2
...@@ -358,7 +358,6 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I...@@ -358,7 +358,6 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I
358 .parent_atom_index = @enumToInt(decl_index),358 .parent_atom_index = @enumToInt(decl_index),
359 });359 });
360 const code = switch (res) {360 const code = switch (res) {
361 .externally_managed => |x| x,
362 .appended => code_buffer.items,361 .appended => code_buffer.items,
363 .fail => |em| {362 .fail => |em| {
364 decl.analysis = .codegen_failure;363 decl.analysis = .codegen_failure;
...@@ -403,7 +402,6 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl_index: Module.Decl.Index)...@@ -403,7 +402,6 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl_index: Module.Decl.Index)
403 .parent_atom_index = @enumToInt(decl_index),402 .parent_atom_index = @enumToInt(decl_index),
404 });403 });
405 const code = switch (res) {404 const code = switch (res) {
406 .externally_managed => |x| x,
407 .appended => code_buffer.items,405 .appended => code_buffer.items,
408 .fail => |em| {406 .fail => |em| {
409 decl.analysis = .codegen_failure;407 decl.analysis = .codegen_failure;
src/link/Wasm.zig-2
...@@ -1113,7 +1113,6 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi...@@ -1113,7 +1113,6 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi
1113 );1113 );
11141114
1115 const code = switch (res) {1115 const code = switch (res) {
1116 .externally_managed => |x| x,
1117 .appended => code_writer.items,1116 .appended => code_writer.items,
1118 .fail => |em| {1117 .fail => |em| {
1119 decl.analysis = .codegen_failure;1118 decl.analysis = .codegen_failure;
...@@ -1250,7 +1249,6 @@ pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: Module.Decl.In...@@ -1250,7 +1249,6 @@ pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: Module.Decl.In
1250 },1249 },
1251 );1250 );
1252 const code = switch (result) {1251 const code = switch (result) {
1253 .externally_managed => |x| x,
1254 .appended => value_bytes.items,1252 .appended => value_bytes.items,
1255 .fail => |em| {1253 .fail => |em| {
1256 decl.analysis = .codegen_failure;1254 decl.analysis = .codegen_failure;