-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use self hosted translate-c for cImport #3973
Conversation
oh my god this is so beautiful |
b022863
to
913f7cc
Compare
@@ -21,9 +21,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | |||
, &[_][]const u8{ | |||
\\pub export fn foo() void { | |||
\\ var a: c_int = undefined; | |||
\\ var b: u8 = @as(u8, 123); | |||
\\ var b: u8 = @intCast(u8, 123); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't we prefer @as
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but there seem to be some places @intCast
is required and I'm not sure they can be done separately.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
b1a7d04
to
a175454
Compare
a175454
to
f5e7d2d
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
- fix use of undefined value - fix parenexprclass result not being suppressed - add an error and a TODO for access of an anonymous field
Thanks for merging. If you're looking for more source to test with I've been trying to convert the stm32h7 headers. One other issue is things like Also it'd be nice to be able to retain comments and the order since currently converting makes them practically unreadable. |
Not sure what you mean here. If you want to use
Might be possible but low priority.
Order of what? |
Oh sorry, I don't want to use
Order of which macros, functions, etc are defined. For example stm32h743xx.h currently translates to stm32h743xx.zig which seems to be in a completely random order (this was done with translate-c not translate-c-2 but they both do this). This is also a low priority. |
Yeah this is planned, but not a requirement to replace translate-c with the self-hosted version. |
The translation of the macro is correct. What you're looking for is support for translating volatile things, which is a different topic than macros. The feature you're looking for is independent of whether someone uses |
Errors don't seem to get reported well: if the clang invocation doesn't work, then we only report "C import failed". To get the actual error I have to use |
The best way to troubleshoot with the self hosted version is to use --verbose-cimport and then open the translated zig code file in a text editor. The errors will be comments inline with the translated code. |
That of course is only available if the cimport succeeded (which is not the case in the scenario above). |
Oh I see, C compilation errors. That is a regression that I would like to rectify before merging this. |
I added support for #4006 to the tokenizer in https://github.com/Vexu/zig/compare/stage-2-cimport...frmdstryr:translate-c-macro-stringify-concat?expand=1 Not sure what's the best way to integrate it into translate-c. |
I started working on merging this in the branch Vexu-stage-2-cimport. |
Progress: the Vexu-stage-2-cimport branch is now passing all the tests for macOS as well as Linux. Next up: Windows. |
Re: 42945a2 int foo(int bar) {
bar = 2;
}
int bar = 4; no longer produces valid zig as pub export fn foo(arg_bar: c_int) c_int {
var bar = arg_bar;
bar = 2;
}
pub export var bar: c_int = 4; |
Ah, thanks for pointing that out. I think we're going to need 2 passes over the clang AST unit. Once to determine all the names in the global namespace, and then a second one to actually do the translation. I'm on it. |
I opened the branch as a pull request in #4025, let's continue efforts there. (pull requests can be filed against branches other than master) |
Closes #1964