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

backend: basic x86_64 assembly codegen for some global vars #799

Merged
merged 3 commits into from
Nov 9, 2024

Conversation

ehaas
Copy link
Collaborator

@ehaas ehaas commented Nov 7, 2024

Some basic assembly codegen, tested with:

/* main.c */
int printf(const char *fmt, ...);
extern char foo[];
extern int bar;
extern double baz;

int main(void)
{
    printf("%s\n%d\n%lf\n", foo, bar, baz);
    return 0;
}
/* test.c */
char foo[] = "hello";
int bar = 42;
double baz = 3.14;
~$ gcc -c main.c
~$ arocc -O0 test.c main.o`
~$ ./a.out
hello
42
3.140000

I structured things the way I did so that aro (the frontend module) wouldn't depend on this assembly backend (as in, needing to import it so that it can call it from Driver). The way things are set up now, a do-nothing function can be passed as the final argument of Driver.main. But I'm not sure if that's the best way to achieve that.

My next goal is to get very basic function generation going and then I can revive the EXPECTED_OUTPUT tests.

Copy link
Owner

@Vexu Vexu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I structured things the way I did so that aro (the frontend module) wouldn't depend on this assembly backend (as in, needing to import it so that it can call it from Driver). The way things are set up now, a do-nothing function can be passed as the final argument of Driver.main. But I'm not sure if that's the best way to achieve that.

I'd be OK with placing the genAsm function in backend.zig and the Driver calling it from there unless you want to do it like this.

src/backend/CodeGenOptions.zig Outdated Show resolved Hide resolved
@ehaas
Copy link
Collaborator Author

ehaas commented Nov 8, 2024

I'd be OK with placing the genAsm function in backend.zig and the Driver calling it from there unless you want to do it like this.

It looks like backend currently does not depend on frontend so I was trying to preserve that property - is it worth keeping it that way?

@ehaas
Copy link
Collaborator Author

ehaas commented Nov 8, 2024

I changed things around a bit to use an optional function instead of anytype, and just have codegen return FatalError for unimplemented things instead of a new kind of error.

@Vexu
Copy link
Owner

Vexu commented Nov 8, 2024

It looks like backend currently does not depend on frontend so I was trying to preserve that property - is it worth keeping it that way?

The backend should be kept separate, I didn't notice this used Compilation for all the type details. I guess this could also be moved to the main module since it's not standalone like the backend module is.

Either way feel free to merge as is.

@ehaas ehaas merged commit 8d01979 into Vexu:master Nov 9, 2024
3 checks passed
@ehaas ehaas deleted the assembly-output branch November 9, 2024 06:34
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

Successfully merging this pull request may close these issues.

2 participants