aboutsummaryrefslogtreecommitdiff
path: root/src/arch/arm/CodeGen.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-01-16 04:20:41 -0500
committerGitHub <noreply@github.com>2025-01-16 04:20:41 -0500
commitd4fe4698d9ff865ed1dc7e0163f2d5fcbe2b45a6 (patch)
tree160d596e8ab0ab9568dac3f026c2ce42ad1c935e /src/arch/arm/CodeGen.zig
parent77273103a8f9895ceab28287dffcf4d4c6fcb91b (diff)
parenteda8b6e137a10f398cd292b533e924960f7fc409 (diff)
downloadzig-d4fe4698d9ff865ed1dc7e0163f2d5fcbe2b45a6.tar.gz
zig-d4fe4698d9ff865ed1dc7e0163f2d5fcbe2b45a6.zip
Merge pull request #22220 from ziglang/wasm-linker
wasm linker: aggressive rewrite towards Data-Oriented Design
Diffstat (limited to 'src/arch/arm/CodeGen.zig')
-rw-r--r--src/arch/arm/CodeGen.zig46
1 files changed, 17 insertions, 29 deletions
diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig
index 065f4a047d..65a202803d 100644
--- a/src/arch/arm/CodeGen.zig
+++ b/src/arch/arm/CodeGen.zig
@@ -23,7 +23,6 @@ const log = std.log.scoped(.codegen);
const build_options = @import("build_options");
const Alignment = InternPool.Alignment;
-const Result = codegen.Result;
const CodeGenError = codegen.CodeGenError;
const bits = @import("bits.zig");
@@ -333,9 +332,9 @@ pub fn generate(
func_index: InternPool.Index,
air: Air,
liveness: Liveness,
- code: *std.ArrayList(u8),
+ code: *std.ArrayListUnmanaged(u8),
debug_output: link.File.DebugInfoOutput,
-) CodeGenError!Result {
+) CodeGenError!void {
const zcu = pt.zcu;
const gpa = zcu.gpa;
const func = zcu.funcInfo(func_index);
@@ -377,10 +376,7 @@ pub fn generate(
defer function.dbg_info_relocs.deinit(gpa);
var call_info = function.resolveCallingConventionValues(func_ty) catch |err| switch (err) {
- error.CodegenFail => return Result{ .fail = function.err_msg.? },
- error.OutOfRegisters => return Result{
- .fail = try ErrorMsg.create(gpa, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
- },
+ error.CodegenFail => return error.CodegenFail,
else => |e| return e,
};
defer call_info.deinit(&function);
@@ -391,15 +387,14 @@ pub fn generate(
function.max_end_stack = call_info.stack_byte_count;
function.gen() catch |err| switch (err) {
- error.CodegenFail => return Result{ .fail = function.err_msg.? },
- error.OutOfRegisters => return Result{
- .fail = try ErrorMsg.create(gpa, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
- },
+ error.CodegenFail => return error.CodegenFail,
+ error.OutOfRegisters => return function.fail("ran out of registers (Zig compiler bug)", .{}),
else => |e| return e,
};
for (function.dbg_info_relocs.items) |reloc| {
- try reloc.genDbgInfo(function);
+ reloc.genDbgInfo(function) catch |err|
+ return function.fail("failed to generate debug info: {s}", .{@errorName(err)});
}
var mir = Mir{
@@ -424,15 +419,9 @@ pub fn generate(
defer emit.deinit();
emit.emitMir() catch |err| switch (err) {
- error.EmitFail => return Result{ .fail = emit.err_msg.? },
+ error.EmitFail => return function.failMsg(emit.err_msg.?),
else => |e| return e,
};
-
- if (function.err_msg) |em| {
- return Result{ .fail = em };
- } else {
- return Result.ok;
- }
}
fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
@@ -6310,20 +6299,19 @@ fn wantSafety(self: *Self) bool {
};
}
-fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
+fn fail(self: *Self, comptime format: []const u8, args: anytype) error{ OutOfMemory, CodegenFail } {
@branchHint(.cold);
- assert(self.err_msg == null);
- const gpa = self.gpa;
- self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
- return error.CodegenFail;
+ const zcu = self.pt.zcu;
+ const func = zcu.funcInfo(self.func_index);
+ const msg = try ErrorMsg.create(zcu.gpa, self.src_loc, format, args);
+ return zcu.codegenFailMsg(func.owner_nav, msg);
}
-fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
+fn failMsg(self: *Self, msg: *ErrorMsg) error{ OutOfMemory, CodegenFail } {
@branchHint(.cold);
- assert(self.err_msg == null);
- const gpa = self.gpa;
- self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
- return error.CodegenFail;
+ const zcu = self.pt.zcu;
+ const func = zcu.funcInfo(self.func_index);
+ return zcu.codegenFailMsg(func.owner_nav, msg);
}
fn parseRegName(name: []const u8) ?Register {