Skip to content

Commit

Permalink
Merge pull request #26 from Vexu/codegen
Browse files Browse the repository at this point in the history
Add codegen
  • Loading branch information
Vexu authored Sep 14, 2021
2 parents cb890ef + 9eb6485 commit b1a7d5d
Show file tree
Hide file tree
Showing 15 changed files with 2,083 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.zig text eol=lf

deps/** linguist-vendored
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
# Aro
A C compiler with the goal of providing fast compilation and low memory usage with good diagnostics.

Currently it can preprocess, parse and semantically analyze ~75% of standard C17 with
Currently it can preprocess, parse and semantically analyze ~85% of standard C17 with
work still being needed to support all of the usual extensions.

Basic code generation is supported for x86-64 linux and can produce a valid hello world:
```shell
$ cat hello.c
extern int printf(const char *restrict fmt, ...);
int main(void) {
pritnf("Hello, world!\n");
return 0;
}
$ zig build run -- hello.c -c
$ zig run hello.o -lc
Hello, world!
$
```

Future plans for the project include making it the C backend of Zig's `translate-c` feature and
making it an optional C frontend for the self-hosted Zig compiler.
```c
Expand Down Expand Up @@ -50,4 +64,4 @@ fn_def: 'fn (argc: int, argv: **const char) int'
value: 4
```
<sup>types are printed in Zig style as C types are more confusing than necessary</sup>
<sup>types are printed in Zig style as C types are more confusing than necessary, actual error messages contain proper C like types</sup>
14 changes: 13 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ pub fn build(b: *Builder) void {
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();

const zig_pkg = std.build.Pkg{
.name = "zig",
.path = .{ .path = "deps/zig/lib.zig" },
};

const exe = b.addExecutable("arocc", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.addPackage(zig_pkg);
exe.install();

const run_cmd = exe.run();
Expand All @@ -30,12 +36,18 @@ pub fn build(b: *Builder) void {
tests_step.dependOn(&exe.step);

var unit_tests = b.addTest("src/main.zig");
unit_tests.addPackage(zig_pkg);
tests_step.dependOn(&unit_tests.step);

const integration_tests = b.addExecutable("arocc", "test/runner.zig");
integration_tests.addPackagePath("aro", "src/lib.zig");
integration_tests.addPackage(.{
.name = "aro",
.path = .{ .path = "src/lib.zig" },
.dependencies = &.{zig_pkg},
});

const integration_test_runner = integration_tests.run();
integration_test_runner.addArg(b.pathFromRoot("test/cases"));
integration_test_runner.addArg(b.zig_exe);
tests_step.dependOn(&integration_test_runner.step);
}
Loading

0 comments on commit b1a7d5d

Please sign in to comment.