aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-01-17 00:16:10 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-01-17 00:16:10 -0700
commit44135ea84e562ae67a5eeced99566be58bffc6fc (patch)
treefdf5e11589187137b7189e5fda128c725259e659 /src/codegen
parent1f65828ec6caa7697b26d9e919112aa1715b57bc (diff)
parent8deb21c58a4e5f9f8805f6b1a2c9a1774c4a4df5 (diff)
downloadzig-44135ea84e562ae67a5eeced99566be58bffc6fc.tar.gz
zig-44135ea84e562ae67a5eeced99566be58bffc6fc.zip
Merge branch 'stage2 error notes'
Closes #7555 There was still some extra work @Vexu did in that PR having to do with adding more compile errors and notes for switch expressions, but that can be added in a follow-up commit.
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig7
-rw-r--r--src/codegen/llvm.zig13
2 files changed, 16 insertions, 4 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 8c85f482fd..b26f753757 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -114,10 +114,13 @@ pub const DeclGen = struct {
module: *Module,
decl: *Decl,
fwd_decl: std.ArrayList(u8),
- error_msg: ?*Compilation.ErrorMsg,
+ error_msg: ?*Module.ErrorMsg,
fn fail(dg: *DeclGen, src: usize, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } {
- dg.error_msg = try Compilation.ErrorMsg.create(dg.module.gpa, src, format, args);
+ dg.error_msg = try Module.ErrorMsg.create(dg.module.gpa, .{
+ .file_scope = dg.decl.getFileScope(),
+ .byte_offset = src,
+ }, format, args);
return error.AnalysisFail;
}
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 5d753c41cb..1edd466d54 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -148,7 +148,7 @@ pub const LLVMIRModule = struct {
object_path: []const u8,
gpa: *Allocator,
- err_msg: ?*Compilation.ErrorMsg = null,
+ err_msg: ?*Module.ErrorMsg = null,
// TODO: The fields below should really move into a different struct,
// because they are only valid when generating a function
@@ -177,6 +177,8 @@ pub const LLVMIRModule = struct {
break_vals: *BreakValues,
}) = .{},
+ src_loc: Module.SrcLoc,
+
const BreakBasicBlocks = std.ArrayListUnmanaged(*const llvm.BasicBlock);
const BreakValues = std.ArrayListUnmanaged(*const llvm.Value);
@@ -254,6 +256,8 @@ pub const LLVMIRModule = struct {
.builder = builder,
.object_path = object_path,
.gpa = gpa,
+ // TODO move this field into a struct that is only instantiated per gen() call
+ .src_loc = undefined,
};
return self;
}
@@ -335,6 +339,8 @@ pub const LLVMIRModule = struct {
const typed_value = decl.typed_value.most_recent.typed_value;
const src = decl.src();
+ self.src_loc = decl.srcLoc();
+
log.debug("gen: {s} type: {}, value: {}", .{ decl.name, typed_value.ty, typed_value.val });
if (typed_value.val.castTag(.function)) |func_payload| {
@@ -853,7 +859,10 @@ pub const LLVMIRModule = struct {
pub fn fail(self: *LLVMIRModule, src: usize, comptime format: []const u8, args: anytype) error{ OutOfMemory, CodegenFail } {
@setCold(true);
assert(self.err_msg == null);
- self.err_msg = try Compilation.ErrorMsg.create(self.gpa, src, format, args);
+ self.err_msg = try Module.ErrorMsg.create(self.gpa, .{
+ .file_scope = self.src_loc.file_scope,
+ .byte_offset = src,
+ }, format, args);
return error.CodegenFail;
}
};