Skip to content

Commit 8554bb5

Browse files
committed
update Aro dependency and enable passing tests
1 parent 4952d95 commit 8554bb5

9 files changed

+42
-53
lines changed

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
.dependencies = .{
1111
.aro = .{
12-
.url = "git+https://github.com/Vexu/arocc#3daec2b3950ab8aee5b3a8ae3e9cc11fb437e803",
13-
.hash = "aro-0.0.0-JSD1QkIZJgDmOZ70WVhJvlnU4fV1zEjP6Hm8eF-y6Dtd",
12+
.url = "git+https://github.com/Vexu/arocc#6211f260b924c33b566367fe505021a2887489f3",
13+
.hash = "aro-0.0.0-JSD1QgZiJgAHbAL6WgwZx2fEUPB2WbHdYkAQ50URgkCG",
1414
},
1515

1616
// .example_compile_c = .{

src/Translator.zig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ pub fn translate(
173173

174174
try translator.prepopulateGlobalNameTable();
175175
try translator.transTopLevelDecls();
176+
177+
// Insert empty line before macros.
178+
try translator.global_scope.nodes.append(gpa, try ZigTag.warning.create(arena, "\n"));
179+
176180
try translator.transMacros();
177181

178182
for (translator.alias_list.items) |alias| {
@@ -592,9 +596,16 @@ fn transFnDecl(t: *Translator, scope: *Scope, fn_decl_node: Node.Index) Error!vo
592596
.is_export = !is_export_or_inline and has_body and !is_always_inline,
593597
.is_pub = is_pub,
594598
.cc = if (raw_qt.getAttribute(t.comp, .calling_convention)) |some| switch (some.cc) {
595-
.C => .c,
599+
.c => .c,
596600
.stdcall => .x86_stdcall,
597601
.thiscall => .x86_thiscall,
602+
.fastcall => .x86_fastcall,
603+
.regcall => .x86_regcall,
604+
.riscv_vector => .riscv_vector,
605+
.aarch64_sve_pcs => .aarch64_sve_pcs,
606+
.aarch64_vector_pcs => .aarch64_vfabi,
607+
.arm_aapcs => .arm_aapcs,
608+
.arm_aapcs_vfp => .arm_aapcs_vfp,
598609
.vectorcall => switch (t.comp.target.cpu.arch) {
599610
.x86 => .x86_vectorcall,
600611
.aarch64, .aarch64_be => .aarch64_vfabi,

src/ast.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,13 @@ pub const Payload = struct {
611611
x86_fastcall,
612612
x86_thiscall,
613613
x86_vectorcall,
614+
x86_regcall,
614615
aarch64_vfabi,
616+
aarch64_sve_pcs,
615617
arm_aapcs,
616618
arm_aapcs_vfp,
617619
m68k_rtd,
620+
riscv_vector,
618621
};
619622
};
620623

@@ -2867,10 +2870,13 @@ fn renderFunc(c: *Context, node: Node) !NodeIndex {
28672870
.x86_fastcall,
28682871
.x86_thiscall,
28692872
.x86_vectorcall,
2873+
.x86_regcall,
28702874
.aarch64_vfabi,
2875+
.aarch64_sve_pcs,
28712876
.arm_aapcs,
28722877
.arm_aapcs_vfp,
28732878
.m68k_rtd,
2879+
.riscv_vector,
28742880
=> cc_node: {
28752881
// .{ .foo = .{} }
28762882
_ = try c.addToken(.period, ".");

src/main.zig

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ pub fn main() u8 {
2222
return 1;
2323
};
2424

25-
var comp = aro.Compilation.initDefault(gpa, std.fs.cwd()) catch |err| switch (err) {
25+
const stderr = std.io.getStdErr();
26+
var diagnostics: aro.Diagnostics = .{
27+
.output = .{ .to_file = .{
28+
.file = stderr,
29+
.config = std.io.tty.detectConfig(stderr),
30+
} },
31+
};
32+
33+
var comp = aro.Compilation.initDefault(gpa, &diagnostics, std.fs.cwd()) catch |err| switch (err) {
2634
error.OutOfMemory => {
2735
std.debug.print("ran out of memory initializing C compilation\n", .{});
2836
if (fast_exit) process.exit(1);
@@ -38,7 +46,7 @@ pub fn main() u8 {
3846
};
3947
defer gpa.free(exe_name);
4048

41-
var driver: aro.Driver = .{ .comp = &comp, .aro_name = exe_name };
49+
var driver: aro.Driver = .{ .comp = &comp, .diagnostics = &diagnostics, .aro_name = exe_name };
4250
defer driver.deinit();
4351

4452
var toolchain: aro.Toolchain = .{ .driver = &driver, .arena = arena, .filesystem = .{ .real = comp.cwd } };
@@ -51,7 +59,6 @@ pub fn main() u8 {
5159
return 1;
5260
},
5361
error.FatalError => {
54-
_ = renderErrors(&driver);
5562
if (fast_exit) process.exit(1);
5663
return 1;
5764
},
@@ -102,9 +109,9 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: []const []const u8) !void
102109
var c_tree = try pp.parse();
103110
defer c_tree.deinit();
104111

105-
if (renderErrors(d) != 0) {
112+
if (d.diagnostics.errors != 0) {
106113
if (fast_exit) process.exit(1);
107-
return;
114+
return error.FatalError;
108115
}
109116

110117
const rendered_zig = try Translator.translate(gpa, d.comp, &pp, &c_tree);
@@ -129,39 +136,6 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: []const []const u8) !void
129136
if (fast_exit) process.exit(0);
130137
}
131138

132-
/// Renders errors and fatal errors + associated notes (e.g. "expanded from here"); does not render warnings or associated notes
133-
fn renderErrors(d: *aro.Driver) u32 {
134-
var writer = aro.Diagnostics.defaultMsgWriter(d.detectConfig(std.io.getStdErr()));
135-
defer writer.deinit();
136-
137-
var errors: u32 = 0;
138-
var saw_error = false;
139-
for (d.comp.diagnostics.list.items) |msg| {
140-
switch (msg.kind) {
141-
.@"error", .@"fatal error" => {
142-
errors += 1;
143-
saw_error = true;
144-
aro.Diagnostics.renderMessage(d.comp, &writer, msg);
145-
},
146-
.warning => saw_error = false,
147-
.note => {
148-
if (saw_error) {
149-
aro.Diagnostics.renderMessage(d.comp, &writer, msg);
150-
}
151-
},
152-
.off => {},
153-
.default => unreachable,
154-
}
155-
}
156-
const e_s = if (errors == 1) "" else "s";
157-
if (errors != 0) {
158-
writer.print("{d} error{s} generated.\n", .{ errors, e_s });
159-
}
160-
161-
d.comp.diagnostics.list.items.len = 0;
162-
return errors;
163-
}
164-
165139
comptime {
166140
if (@import("builtin").is_test) {
167141
_ = Translator;
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
void __attribute__((aarch64_vector_pcs)) foo1(float *a);
22

33
// translate
4-
// expect=fail
54
// target=aarch64-linux-none
65
//
76
// pub extern fn foo1(a: [*c]f32) callconv(.{ .aarch64_vfabi = .{} }) void;

test/cases/translate/Calling_convention_arm.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ void __attribute__((pcs("aapcs"))) foo1(float *a);
22
void __attribute__((pcs("aapcs-vfp"))) foo2(float *a);
33

44
// translate
5-
// expect=fail
65
// target=arm-linux-none
76
//
87
// pub extern fn foo1(a: [*c]f32) callconv(.{ .arm_aapcs = .{} }) void;

test/cases/translate/Calling_convention_x86.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ void __attribute__((cdecl)) foo4(float *a);
55
void __attribute__((thiscall)) foo5(float *a);
66

77
// translate
8-
// expect=fail
98
// target=x86-linux-none
109
//
1110
// pub extern fn foo1(a: [*c]f32) callconv(.{ .x86_fastcall = .{} }) void;

test/cases/translate/macros_with_field_targets.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ extern union OpenGLProcs glProcs;
1212
#define glClearPFN PFNGLCLEARPROC
1313

1414
// translate
15-
// expect=fail
1615
//
1716
// pub const GLbitfield = c_uint;
18-
// pub const PFNGLCLEARPROC = ?*const fn (GLbitfield) callconv(.c) void;
17+
// pub const PFNGLCLEARPROC = ?*const fn (mask: GLbitfield) callconv(.c) void;
1918
// pub const OpenGLProc = ?*const fn () callconv(.c) void;
2019
// const struct_unnamed_1 = extern struct {
21-
// Clear: PFNGLCLEARPROC = @import("std").mem.zeroes(PFNGLCLEARPROC),
20+
// Clear: PFNGLCLEARPROC = null,
2221
// };
2322
// pub const union_OpenGLProcs = extern union {
2423
// ptr: [1]OpenGLProc,
@@ -28,8 +27,8 @@ extern union OpenGLProcs glProcs;
2827
//
2928
// pub const glClearPFN = PFNGLCLEARPROC;
3029
//
31-
// pub inline fn glClearUnion(arg_2: GLbitfield) void {
32-
// return glProcs.gl.Clear.?(arg_2);
30+
// pub inline fn glClearUnion(mask: GLbitfield) void {
31+
// return glProcs.gl.Clear.?(mask);
3332
// }
3433
//
3534
// pub const OpenGLProcs = union_OpenGLProcs;
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#include <stdint.h>
1+
// TODO https://github.com/Vexu/arocc/issues/848
2+
// #include <stdint.h>
3+
typedef __UINT32_TYPE__ uint32_t;
4+
25
int log2(uint32_t a) {
36
int i = 0;
47
while (a > 0) {
@@ -8,15 +11,14 @@ int log2(uint32_t a) {
811
}
912

1013
// translate
11-
// expect=fail
1214
//
1315
// pub export fn log2(arg_a: u32) c_int {
1416
// var a = arg_a;
1517
// _ = &a;
1618
// var i: c_int = 0;
1719
// _ = &i;
18-
// while (a > @as(u32, @bitCast(@as(c_int, 0)))) {
19-
// a >>= @intCast(@as(c_int, 1));
20+
// while (a > @as(u32, 0)) {
21+
// a >>= @intCast(1);
2022
// }
2123
// return i;
2224
// }

0 commit comments

Comments
 (0)