authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-07-13 20:38:55-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-20 12:19:16-07:00
log3a41e4430eae16e5aa739b7a71b1fded1f1029e3
tree4e0eeded9ebcf0c1bc7ce2f679bd343119299792
parentc09b973ec25f328f5e15e9e6eed4da7f5e4634af

codegen: add FnResult type which is a Result that removes externally_managed


2 files changed, 11 insertions(+), 7 deletions(-)

src/codegen.zig+11-6
...@@ -23,6 +23,11 @@ const RegisterManager = @import("register_manager.zig").RegisterManager;...@@ -23,6 +23,11 @@ const RegisterManager = @import("register_manager.zig").RegisterManager;
2323
24const X8664Encoder = @import("codegen/x86_64.zig").Encoder;24const X8664Encoder = @import("codegen/x86_64.zig").Encoder;
2525
26pub const FnResult = union(enum) {
27 /// The `code` parameter passed to `generateSymbol` has the value appended.
28 appended: void,
29 fail: *ErrorMsg,
30};
26pub const Result = union(enum) {31pub const Result = union(enum) {
27 /// The `code` parameter passed to `generateSymbol` has the value appended.32 /// The `code` parameter passed to `generateSymbol` has the value appended.
28 appended: void,33 appended: void,
...@@ -54,7 +59,7 @@ pub fn generateFunction(...@@ -54,7 +59,7 @@ pub fn generateFunction(
54 liveness: Liveness,59 liveness: Liveness,
55 code: *std.ArrayList(u8),60 code: *std.ArrayList(u8),
56 debug_output: DebugInfoOutput,61 debug_output: DebugInfoOutput,
57) GenerateSymbolError!Result {62) GenerateSymbolError!FnResult {
58 switch (bin_file.options.target.cpu.arch) {63 switch (bin_file.options.target.cpu.arch) {
59 .wasm32 => unreachable, // has its own code path64 .wasm32 => unreachable, // has its own code path
60 .wasm64 => unreachable, // has its own code path65 .wasm64 => unreachable, // has its own code path
...@@ -451,7 +456,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -451,7 +456,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
451 liveness: Liveness,456 liveness: Liveness,
452 code: *std.ArrayList(u8),457 code: *std.ArrayList(u8),
453 debug_output: DebugInfoOutput,458 debug_output: DebugInfoOutput,
454 ) GenerateSymbolError!Result {459 ) GenerateSymbolError!FnResult {
455 if (build_options.skip_non_native and std.Target.current.cpu.arch != arch) {460 if (build_options.skip_non_native and std.Target.current.cpu.arch != arch) {
456 @panic("Attempted to compile for architecture that was disabled by build configuration");461 @panic("Attempted to compile for architecture that was disabled by build configuration");
457 }462 }
...@@ -495,7 +500,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -495,7 +500,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
495 defer function.exitlude_jump_relocs.deinit(bin_file.allocator);500 defer function.exitlude_jump_relocs.deinit(bin_file.allocator);
496501
497 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {502 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {
498 error.CodegenFail => return Result{ .fail = function.err_msg.? },503 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
499 else => |e| return e,504 else => |e| return e,
500 };505 };
501 defer call_info.deinit(&function);506 defer call_info.deinit(&function);
...@@ -506,14 +511,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -506,14 +511,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
506 function.max_end_stack = call_info.stack_byte_count;511 function.max_end_stack = call_info.stack_byte_count;
507512
508 function.gen() catch |err| switch (err) {513 function.gen() catch |err| switch (err) {
509 error.CodegenFail => return Result{ .fail = function.err_msg.? },514 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
510 else => |e| return e,515 else => |e| return e,
511 };516 };
512517
513 if (function.err_msg) |em| {518 if (function.err_msg) |em| {
514 return Result{ .fail = em };519 return FnResult{ .fail = em };
515 } else {520 } else {
516 return Result{ .appended = {} };521 return FnResult{ .appended = {} };
517 }522 }
518 }523 }
519524
src/link/Elf.zig-1
...@@ -2363,7 +2363,6 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven...@@ -2363,7 +2363,6 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven
2363 },2363 },
2364 });2364 });
2365 const code = switch (res) {2365 const code = switch (res) {
2366 .externally_managed => |x| x,
2367 .appended => code_buffer.items,2366 .appended => code_buffer.items,
2368 .fail => |em| {2367 .fail => |em| {
2369 decl.analysis = .codegen_failure;2368 decl.analysis = .codegen_failure;