From 469625d32a81c45e79ca7e990d5223ecdeb74e5d Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 22 Sep 2019 18:26:00 -0300 Subject: [PATCH] add CompileError error type --- src/codegen.zig | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/codegen.zig b/src/codegen.zig index b0d652a..d45320f 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -7,6 +7,8 @@ fn sliceify(non_slice: ?[*]const u8) []const u8 { return non_slice.?[0..std.mem.len(u8, non_slice.?)]; } +pub const CompileError = error{LLVMError}; + pub const Codegen = struct { allocator: *std.mem.Allocator, @@ -89,9 +91,7 @@ pub const Codegen = struct { if (llvm.LLVMWriteBitcodeToFile(mod, c"awoo.bc") != 0) { std.debug.warn("error writing bitcode to file: {}\n", sliceify(err)); - - // TODO return error value - @panic("compile error"); + return CompileError.LLVMError; } //llvm.InitializeAllTargetInfos(); @@ -103,9 +103,7 @@ pub const Codegen = struct { var engine: llvm.LLVMExecutionEngineRef = undefined; if (llvm.LLVMCreateExecutionEngineForModule(&engine, mod, &err) != 0) { std.debug.warn("failed to create execution engine: {}\n", sliceify(err)); - - // TODO return error value - @panic("compile error"); + return CompileError.LLVMError; } var machine = llvm.LLVMGetExecutionEngineTargetMachine(engine); @@ -135,9 +133,7 @@ pub const Codegen = struct { &err, ) != 0) { std.debug.warn("failed to emit to file: {}\n", sliceify(err)); - - // TODO return error value - @panic("compile error"); + return CompileError.LLVMError; } } };