Skip to content
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

Zig codegen #448

Closed
iacore opened this issue Dec 27, 2022 · 10 comments
Closed

Zig codegen #448

iacore opened this issue Dec 27, 2022 · 10 comments

Comments

@iacore
Copy link

iacore commented Dec 27, 2022

Coming from ziglang/zig#14068

How hard is it to port current zig translate-c to be arocc's Zig codegen backend?

@TwoClocks
Copy link
Contributor

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.

@MarcoPolo
Copy link

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

@TwoClocks
Copy link
Contributor

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
Copy link
Contributor

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

@MarcoPolo
Copy link

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

@Vexu
Copy link
Owner

Vexu commented May 24, 2023

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.

@TwoClocks
Copy link
Contributor

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
Copy link
Contributor

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

@Vexu
Copy link
Owner

Vexu commented Aug 25, 2023

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.

@ehaas
Copy link
Collaborator

ehaas commented Mar 22, 2024

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

@Vexu Vexu closed this as completed Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants