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;
2323
2424const 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};
2631pub const Result = union(enum) {
2732 /// The `code` parameter passed to `generateSymbol` has the value appended.
2833 appended: void,
......@@ -54,7 +59,7 @@ pub fn generateFunction(
5459 liveness: Liveness,
5560 code: *std.ArrayList(u8),
5661 debug_output: DebugInfoOutput,
57) GenerateSymbolError!Result {
62) GenerateSymbolError!FnResult {
5863 switch (bin_file.options.target.cpu.arch) {
5964 .wasm32 => unreachable, // has its own code path
6065 .wasm64 => unreachable, // has its own code path
......@@ -451,7 +456,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
451456 liveness: Liveness,
452457 code: *std.ArrayList(u8),
453458 debug_output: DebugInfoOutput,
454 ) GenerateSymbolError!Result {
459 ) GenerateSymbolError!FnResult {
455460 if (build_options.skip_non_native and std.Target.current.cpu.arch != arch) {
456461 @panic("Attempted to compile for architecture that was disabled by build configuration");
457462 }
......@@ -495,7 +500,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
495500 defer function.exitlude_jump_relocs.deinit(bin_file.allocator);
496501
497502 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.? },
499504 else => |e| return e,
500505 };
501506 defer call_info.deinit(&function);
......@@ -506,14 +511,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
506511 function.max_end_stack = call_info.stack_byte_count;
507512
508513 function.gen() catch |err| switch (err) {
509 error.CodegenFail => return Result{ .fail = function.err_msg.? },
514 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
510515 else => |e| return e,
511516 };
512517
513518 if (function.err_msg) |em| {
514 return Result{ .fail = em };
519 return FnResult{ .fail = em };
515520 } else {
516 return Result{ .appended = {} };
521 return FnResult{ .appended = {} };
517522 }
518523 }
519524
src/link/Elf.zig-1
......@@ -2363,7 +2363,6 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven
23632363 },
23642364 });
23652365 const code = switch (res) {
2366 .externally_managed => |x| x,
23672366 .appended => code_buffer.items,
23682367 .fail => |em| {
23692368 decl.analysis = .codegen_failure;