Skip to content

Commit

Permalink
translate-c: self-hosted implementation can detect C errors
Browse files Browse the repository at this point in the history
See #1964
  • Loading branch information
andrewrk committed Apr 21, 2019
1 parent 4dfe787 commit a171c77
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src-self-hosted/clang.zig
Original file line number Diff line number Diff line change
Expand Up @@ -959,3 +959,11 @@ pub const Stage2ErrorMsg = extern struct {
offset: c_uint,
};
pub extern fn ZigClangErrorMsg_delete(ptr: [*c]Stage2ErrorMsg, len: usize) void;

pub extern fn ZigClangLoadFromCommandLine(
args_begin: [*]?[*]const u8,
args_end: [*]?[*]const u8,
errors_ptr: *[*]Stage2ErrorMsg,
errors_len: *usize,
resources_path: [*c]const u8,
) ?*ZigClangASTUnit;
9 changes: 7 additions & 2 deletions src-self-hosted/stage1.zig
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ export fn stage2_translate_c(
out_ast.* = translate_c.translate(args_begin, args_end, switch (mode) {
.import => translate_c.Mode.import,
.translate => translate_c.Mode.translate,
}, &errors) catch |err| switch (err) {
}, &errors, resources_path) catch |err| switch (err) {
error.Unimplemented => return Error.Unimplemented,
error.SemanticAnalyzeFail => {
out_errors_ptr.* = errors.ptr;
out_errors_len.* = errors.len;
return Error.CCompileErrors;
},
error.OutOfMemory => return Error.OutOfMemory,
};

return Error.None;
}

Expand Down
12 changes: 12 additions & 0 deletions src-self-hosted/translate_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ pub fn translate(
args_end: [*]?[*]const u8,
mode: Mode,
errors: *[]ClangErrMsg,
resources_path: [*]const u8,
) !*ast.Tree {
const ast_unit = ZigClangLoadFromCommandLine(
args_begin,
args_end,
&errors.ptr,
&errors.len,
resources_path,
) orelse {
if (errors.len == 0) return error.OutOfMemory;
return error.SemanticAnalyzeFail;
};

return error.Unimplemented;
}

Expand Down

0 comments on commit a171c77

Please sign in to comment.