aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-10-18 00:32:59 -0400
committerGitHub <noreply@github.com>2023-10-18 00:32:59 -0400
commit149f2f8adb2b853eb80f420e019f60d34c8bd4b2 (patch)
tree456007a2bfe86c3578071998a86f42c09cd63826 /src
parent7a9500fd80990a3dc47821e627162bf769eecbba (diff)
parent96f9e20152001c7611b2c40f36ef9a522165d9d0 (diff)
downloadzig-149f2f8adb2b853eb80f420e019f60d34c8bd4b2.tar.gz
zig-149f2f8adb2b853eb80f420e019f60d34c8bd4b2.zip
Merge pull request #17524 from Vexu/aro-translate-c
Add ability to test Aro based `translate-c`
Diffstat (limited to 'src')
-rw-r--r--src/Compilation.zig1
-rw-r--r--src/aro_translate_c.zig7
-rw-r--r--src/main.zig1
3 files changed, 7 insertions, 2 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 3eec2a6e94..5bfabfdcfc 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -3980,6 +3980,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
man.hash.addBytes(c_src);
+ man.hash.add(comp.c_frontend);
// If the previous invocation resulted in clang errors, we will see a hit
// here with 0 files in the manifest, in which case it is actually a miss.
diff --git a/src/aro_translate_c.zig b/src/aro_translate_c.zig
index 5686c848bf..eaa99694de 100644
--- a/src/aro_translate_c.zig
+++ b/src/aro_translate_c.zig
@@ -308,7 +308,6 @@ fn transVarDecl(_: *Context, _: NodeIndex, _: ?usize) Error!void {
fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes: []const NodeIndex) Error!void {
const node_types = c.tree.nodes.items(.ty);
const ty = node_types[@intFromEnum(enum_decl)];
- const node_data = c.tree.nodes.items(.data);
if (c.decl_table.get(@intFromPtr(ty.data.@"enum"))) |_|
return; // Avoid processing this decl twice
const toplevel = scope.id == .root;
@@ -342,11 +341,15 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes:
else => |e| return e,
};
+ const val = c.tree.value_map.get(field_node).?;
+ const str = try std.fmt.allocPrint(c.arena, "{d}", .{val.data.int});
+ const int = try ZigTag.integer_literal.create(c.arena, str);
+
const enum_const_def = try ZigTag.enum_constant.create(c.arena, .{
.name = enum_val_name,
.is_public = toplevel,
.type = enum_const_type_node,
- .value = transExpr(c, node_data[@intFromEnum(field_node)].decl.node, .used) catch @panic("TODO"),
+ .value = int,
});
if (toplevel)
try addTopLevelDecl(c, enum_val_name, enum_const_def)
diff --git a/src/main.zig b/src/main.zig
index 6dd4fb0725..4c44076cd4 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -4265,6 +4265,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, fancy_output: ?*Compilati
defer man.deinit();
man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
+ man.hash.add(comp.c_frontend);
Compilation.cache_helpers.hashCSource(&man, c_source_file) catch |err| {
fatal("unable to process '{s}': {s}", .{ c_source_file.src_path, @errorName(err) });
};