Zig codegen
Coming from https://github.com/ziglang/zig/pull/14068
How hard is it to port current zig translate-c to be arocc's Zig codegen backend?
I started working on an arocc version of translate-c. It doesn't look too bad; just a fair bit of time.
I have a feeling that translate-c/ast.zig is incomplete compared to arocc's, but I haven't gotten far enough into it to know sure. For example, arocc knows all the offset of the bitfields, but there isn't a way to represent that in ast.zig ATM (at least it wasn't obvious to me).
I have yet to generate any zig code, so if this is an inspiring problem for you, go nuts.
I might pick this up. Do you have a branch I can start on @TwoClocks ? Thank you!
Here is my feeble branch: https://github.com/TwoClocks/zig/tree/aro-translate-c
It should compile w/ a recent master version of zig.
I added aro as a module to zig. The path is relative but hard-coded in build.zig. Around line 180. Obviously not a long-term solution....
I basically just added a new zig cmd-line command for aro_translate_c. It will compile the C code using aro.
The function to translate from aro's ATS to zig's AST is setup and stubbed. I was going to start w/ just trying to get a simple int decl to work.
To me, both ATSs are confusing to a casual observer.
@MarcoPolo I'm not sure if you've decided to take this on.
I realized it doesn't need to be in the zig compiler at all. It can be a stand-alone app. Zig's AST is in std, and trying to convert to translate_c/Ast.zig I think is the wrong way to do it.
I started a new repro which does translate var decls, and "just" needs to be filled out. You can check it out here: https://github.com/TwoClocks/aro-translate-c If you have something farther along, I'd be happy to abandon this and contribute.
It can be a stand-alone app.
I was thinking the same thing. I haven’t started anything. I’ll try to take a look at your repo
and trying to convert to
translate_c/Ast.zigI think is the wrong way to do it.
The reason for the special AST is that the Zig AST assumes tokens to be in a certain order that they'd appear in actual source files making it difficult to generate correctly during translation.
Unless you're interested in continuing your project I'll start working on getting Aro translate-c to a contributor friendly state.
Unless you're interested in continuing your project I'll start working on getting Aro translate-c to a contributor friendly state.
Please. I'll port whatever I've added recently.
@Vexu
Unless you're interested in continuing your project I'll start working on getting Aro translate-c to a contributor friendly state.
I'm going to have some free time as the summer ends. I'd like to pick this up again. Did you start a new project somewhere?
I started working on it in https://github.com/Vexu/zig/tree/aro-translate-c but paused to wait for 0.11.0 since there were a lot of breaking changes at the time.
Perhaps this issue should be closed now that aro-based translate-c work is taking place in the main Zig repo?