From 96f9e20152001c7611b2c40f36ef9a522165d9d0 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Tue, 17 Oct 2023 11:51:39 +0300 Subject: [PATCH] add c_frontend to translate-c cache hash --- src/Compilation.zig | 1 + src/aro_translate_c.zig | 7 +++++-- src/main.zig | 1 + test/src/Cases.zig | 6 +++--- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index 4f26c95ea9480c19907c99164aa8eda0453af8a2..cc922998c33515e2e4f05537d925a53f8fa2d7ea 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -3936,6 +3936,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 5686c848bfdbc0bcb1839ce3ff9a01aedf0c38ef..eaa99694de35973672a44782e59ab3e0a7c7e271 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 14d187796c8d1261834cbc50842545bfea6f361f..d30fe16dda95e335c3da695a91c1a39501d31b27 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4238,6 +4238,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) }); }; diff --git a/test/src/Cases.zig b/test/src/Cases.zig index 4969b82033607335a03898faf54cda8f91a10281..0ef584ccecdf120e09cec02f6c49aeb313633fbd 100644 --- a/test/src/Cases.zig +++ b/test/src/Cases.zig @@ -681,11 +681,11 @@ pub fn lowerToBuildSteps( } } - for (self.translate.items) |*case| switch (case.kind) { + for (self.translate.items) |case| switch (case.kind) { .run => |output| { const annotated_case_name = b.fmt("run-translated-c {s}", .{case.name}); if (opt_test_filter) |filter| { - if (std.mem.indexOf(u8, annotated_case_name, filter) == null) return; + if (std.mem.indexOf(u8, annotated_case_name, filter) == null) continue; } if (!std.process.can_spawn) { std.debug.print("Unable to spawn child processes on {s}, skipping test.\n", .{@tagName(builtin.os.tag)}); @@ -723,7 +723,7 @@ pub fn lowerToBuildSteps( .translate => |output| { const annotated_case_name = b.fmt("zig translate-c {s}", .{case.name}); if (opt_test_filter) |filter| { - if (std.mem.indexOf(u8, annotated_case_name, filter) == null) return; + if (std.mem.indexOf(u8, annotated_case_name, filter) == null) continue; } const write_src = b.addWriteFiles(); -- 2.54.0