arocc icon indicating copy to clipboard operation
arocc copied to clipboard

Zig codegen

Open iacore opened this issue 3 years ago • 9 comments

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?

iacore avatar Dec 27 '22 13:12 iacore

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.

TwoClocks avatar Dec 30 '22 10:12 TwoClocks

I might pick this up. Do you have a branch I can start on @TwoClocks ? Thank you!

MarcoPolo avatar Mar 30 '23 17:03 MarcoPolo

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.

TwoClocks avatar Apr 04 '23 21:04 TwoClocks

@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.

TwoClocks avatar May 16 '23 04:05 TwoClocks

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

MarcoPolo avatar May 16 '23 14:05 MarcoPolo

and trying to convert to translate_c/Ast.zig I 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.

Vexu avatar May 24 '23 22:05 Vexu

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.

TwoClocks avatar May 24 '23 23:05 TwoClocks

@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?

TwoClocks avatar Aug 24 '23 21:08 TwoClocks

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.

Vexu avatar Aug 25 '23 10:08 Vexu

Perhaps this issue should be closed now that aro-based translate-c work is taking place in the main Zig repo?

ehaas avatar Mar 22 '24 20:03 ehaas