commit 3a41e4430eae16e5aa739b7a71b1fded1f1029e3 (tree)
parent c09b973ec25f328f5e15e9e6eed4da7f5e4634af
Author: Jacob G-W <jacoblevgw@gmail.com>
Date: Tue, 13 Jul 2021 20:38:55 -0400
codegen: add FnResult type which is a Result that removes externally_managed
Diffstat:
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/codegen.zig b/src/codegen.zig
@@ -23,6 +23,11 @@ const RegisterManager = @import("register_manager.zig").RegisterManager;
const X8664Encoder = @import("codegen/x86_64.zig").Encoder;
+pub const FnResult = union(enum) {
+ /// The `code` parameter passed to `generateSymbol` has the value appended.
+ appended: void,
+ fail: *ErrorMsg,
+};
pub const Result = union(enum) {
/// The `code` parameter passed to `generateSymbol` has the value appended.
appended: void,
@@ -54,7 +59,7 @@ pub fn generateFunction(
liveness: Liveness,
code: *std.ArrayList(u8),
debug_output: DebugInfoOutput,
-) GenerateSymbolError!Result {
+) GenerateSymbolError!FnResult {
switch (bin_file.options.target.cpu.arch) {
.wasm32 => unreachable, // has its own code path
.wasm64 => unreachable, // has its own code path
@@ -451,7 +456,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
liveness: Liveness,
code: *std.ArrayList(u8),
debug_output: DebugInfoOutput,
- ) GenerateSymbolError!Result {
+ ) GenerateSymbolError!FnResult {
if (build_options.skip_non_native and std.Target.current.cpu.arch != arch) {
@panic("Attempted to compile for architecture that was disabled by build configuration");
}
@@ -495,7 +500,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
defer function.exitlude_jump_relocs.deinit(bin_file.allocator);
var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {
- error.CodegenFail => return Result{ .fail = function.err_msg.? },
+ error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
else => |e| return e,
};
defer call_info.deinit(&function);
@@ -506,14 +511,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
function.max_end_stack = call_info.stack_byte_count;
function.gen() catch |err| switch (err) {
- error.CodegenFail => return Result{ .fail = function.err_msg.? },
+ error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
else => |e| return e,
};
if (function.err_msg) |em| {
- return Result{ .fail = em };
+ return FnResult{ .fail = em };
} else {
- return Result{ .appended = {} };
+ return FnResult{ .appended = {} };
}
}
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
@@ -2363,7 +2363,6 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven
},
});
const code = switch (res) {
- .externally_managed => |x| x,
.appended => code_buffer.items,
.fail => |em| {
decl.analysis = .codegen_failure;