authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-10-17 11:51:39+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-10-17 11:55:17+03:00
log96f9e20152001c7611b2c40f36ef9a522165d9d0
tree696de46e18d697cd772ccf9c36b7a967ca50749e
parente765495b114af3417aea4cffcd7c37f400aab3fe

add c_frontend to translate-c cache hash


4 files changed, 10 insertions(+), 5 deletions(-)

src/Compilation.zig+1
...@@ -3936,6 +3936,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {...@@ -3936,6 +3936,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
39363936
3937 man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects3937 man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
3938 man.hash.addBytes(c_src);3938 man.hash.addBytes(c_src);
3939 man.hash.add(comp.c_frontend);
39393940
3940 // If the previous invocation resulted in clang errors, we will see a hit3941 // If the previous invocation resulted in clang errors, we will see a hit
3941 // here with 0 files in the manifest, in which case it is actually a miss.3942 // here with 0 files in the manifest, in which case it is actually a miss.
src/aro_translate_c.zig+5-2
...@@ -308,7 +308,6 @@ fn transVarDecl(_: *Context, _: NodeIndex, _: ?usize) Error!void {...@@ -308,7 +308,6 @@ fn transVarDecl(_: *Context, _: NodeIndex, _: ?usize) Error!void {
308fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes: []const NodeIndex) Error!void {308fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes: []const NodeIndex) Error!void {
309 const node_types = c.tree.nodes.items(.ty);309 const node_types = c.tree.nodes.items(.ty);
310 const ty = node_types[@intFromEnum(enum_decl)];310 const ty = node_types[@intFromEnum(enum_decl)];
311 const node_data = c.tree.nodes.items(.data);
312 if (c.decl_table.get(@intFromPtr(ty.data.@"enum"))) |_|311 if (c.decl_table.get(@intFromPtr(ty.data.@"enum"))) |_|
313 return; // Avoid processing this decl twice312 return; // Avoid processing this decl twice
314 const toplevel = scope.id == .root;313 const toplevel = scope.id == .root;
...@@ -342,11 +341,15 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes:...@@ -342,11 +341,15 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes:
342 else => |e| return e,341 else => |e| return e,
343 };342 };
344343
344 const val = c.tree.value_map.get(field_node).?;
345 const str = try std.fmt.allocPrint(c.arena, "{d}", .{val.data.int});
346 const int = try ZigTag.integer_literal.create(c.arena, str);
347
345 const enum_const_def = try ZigTag.enum_constant.create(c.arena, .{348 const enum_const_def = try ZigTag.enum_constant.create(c.arena, .{
346 .name = enum_val_name,349 .name = enum_val_name,
347 .is_public = toplevel,350 .is_public = toplevel,
348 .type = enum_const_type_node,351 .type = enum_const_type_node,
349 .value = transExpr(c, node_data[@intFromEnum(field_node)].decl.node, .used) catch @panic("TODO"),352 .value = int,
350 });353 });
351 if (toplevel)354 if (toplevel)
352 try addTopLevelDecl(c, enum_val_name, enum_const_def)355 try addTopLevelDecl(c, enum_val_name, enum_const_def)
src/main.zig+1
...@@ -4238,6 +4238,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, fancy_output: ?*Compilati...@@ -4238,6 +4238,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, fancy_output: ?*Compilati
4238 defer man.deinit();4238 defer man.deinit();
42394239
4240 man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects4240 man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
4241 man.hash.add(comp.c_frontend);
4241 Compilation.cache_helpers.hashCSource(&man, c_source_file) catch |err| {4242 Compilation.cache_helpers.hashCSource(&man, c_source_file) catch |err| {
4242 fatal("unable to process '{s}': {s}", .{ c_source_file.src_path, @errorName(err) });4243 fatal("unable to process '{s}': {s}", .{ c_source_file.src_path, @errorName(err) });
4243 };4244 };
test/src/Cases.zig+3-3
...@@ -681,11 +681,11 @@ pub fn lowerToBuildSteps(...@@ -681,11 +681,11 @@ pub fn lowerToBuildSteps(
681 }681 }
682 }682 }
683683
684 for (self.translate.items) |*case| switch (case.kind) {684 for (self.translate.items) |case| switch (case.kind) {
685 .run => |output| {685 .run => |output| {
686 const annotated_case_name = b.fmt("run-translated-c {s}", .{case.name});686 const annotated_case_name = b.fmt("run-translated-c {s}", .{case.name});
687 if (opt_test_filter) |filter| {687 if (opt_test_filter) |filter| {
688 if (std.mem.indexOf(u8, annotated_case_name, filter) == null) return;688 if (std.mem.indexOf(u8, annotated_case_name, filter) == null) continue;
689 }689 }
690 if (!std.process.can_spawn) {690 if (!std.process.can_spawn) {
691 std.debug.print("Unable to spawn child processes on {s}, skipping test.\n", .{@tagName(builtin.os.tag)});691 std.debug.print("Unable to spawn child processes on {s}, skipping test.\n", .{@tagName(builtin.os.tag)});
...@@ -723,7 +723,7 @@ pub fn lowerToBuildSteps(...@@ -723,7 +723,7 @@ pub fn lowerToBuildSteps(
723 .translate => |output| {723 .translate => |output| {
724 const annotated_case_name = b.fmt("zig translate-c {s}", .{case.name});724 const annotated_case_name = b.fmt("zig translate-c {s}", .{case.name});
725 if (opt_test_filter) |filter| {725 if (opt_test_filter) |filter| {
726 if (std.mem.indexOf(u8, annotated_case_name, filter) == null) return;726 if (std.mem.indexOf(u8, annotated_case_name, filter) == null) continue;
727 }727 }
728728
729 const write_src = b.addWriteFiles();729 const write_src = b.addWriteFiles();