authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-06-13 20:36:51+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-13 15:25:18-04:00
logff79b87fa062d602722a6ec17f74550cda42a624
treea08a33c1f2160724fc5436ad6f527fa1c4264aad
parent37f36da391570739e639f857bef3de1170eaac50

tools: Unbreak many tools

Many tools were broken after the recent hash-table refactorings, fix them and ensure they won't silently break again.

5 files changed, 46 insertions(+), 30 deletions(-)

test/standalone.zig+8
......@@ -32,4 +32,12 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
3232 cases.addBuildFile("test/stage1/c_abi/build.zig", .{});
3333 }
3434 cases.addBuildFile("test/standalone/c_compiler/build.zig", .{ .build_modes = true, .cross_targets = true });
35
36 // Ensure the development tools are buildable.
37 cases.add("tools/gen_spirv_spec.zig");
38 cases.add("tools/gen_stubs.zig");
39 cases.add("tools/update_clang_options.zig");
40 cases.add("tools/update_cpu_features.zig");
41 cases.add("tools/update_glibc.zig");
42 cases.add("tools/update_spirv_features.zig");
3543}
tools/gen_spirv_spec.zig+3
......@@ -14,6 +14,9 @@ pub fn main() !void {
1414 const spec_path = args[1];
1515 const spec = try std.fs.cwd().readFileAlloc(allocator, spec_path, std.math.maxInt(usize));
1616
17 // Required for json parsing.
18 @setEvalBranchQuota(10000);
19
1720 var tokens = std.json.TokenStream.init(spec);
1821 var registry = try std.json.parse(g.Registry, &tokens, .{ .allocator = allocator });
1922
tools/process_headers.zig+21-19
......@@ -234,17 +234,19 @@ const DestTarget = struct {
234234 os: OsTag,
235235 abi: Abi,
236236
237 fn hash(a: DestTarget) u32 {
238 return @enumToInt(a.arch) +%
239 (@enumToInt(a.os) *% @as(u32, 4202347608)) +%
240 (@enumToInt(a.abi) *% @as(u32, 4082223418));
241 }
237 const HashContext = struct {
238 pub fn hash(self: @This(), a: DestTarget) u32 {
239 return @enumToInt(a.arch) +%
240 (@enumToInt(a.os) *% @as(u32, 4202347608)) +%
241 (@enumToInt(a.abi) *% @as(u32, 4082223418));
242 }
242243
243 fn eql(a: DestTarget, b: DestTarget) bool {
244 return a.arch.eql(b.arch) and
245 a.os == b.os and
246 a.abi == b.abi;
247 }
244 pub fn eql(self: @This(), a: DestTarget, b: DestTarget) bool {
245 return a.arch.eql(b.arch) and
246 a.os == b.os and
247 a.abi == b.abi;
248 }
249 };
248250};
249251
250252const Contents = struct {
......@@ -259,7 +261,7 @@ const Contents = struct {
259261};
260262
261263const HashToContents = std.StringHashMap(Contents);
262const TargetToHash = std.ArrayHashMap(DestTarget, []const u8, DestTarget.hash, DestTarget.eql, true);
264const TargetToHash = std.ArrayHashMap(DestTarget, []const u8, DestTarget.HashContext, true);
263265const PathTable = std.StringHashMap(*TargetToHash);
264266
265267const LibCVendor = enum {
......@@ -423,9 +425,9 @@ pub fn main() !void {
423425 while (path_it.next()) |path_kv| {
424426 var contents_list = std.ArrayList(*Contents).init(allocator);
425427 {
426 var hash_it = path_kv.value.*.iterator();
428 var hash_it = path_kv.value_ptr.*.iterator();
427429 while (hash_it.next()) |hash_kv| {
428 const contents = hash_to_contents.get(hash_kv.value.*).?;
430 const contents = hash_to_contents.getPtr(hash_kv.value_ptr.*).?;
429431 try contents_list.append(contents);
430432 }
431433 }
......@@ -433,7 +435,7 @@ pub fn main() !void {
433435 const best_contents = contents_list.popOrNull().?;
434436 if (best_contents.hit_count > 1) {
435437 // worth it to make it generic
436 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key.* });
438 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });
437439 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
438440 try std.fs.cwd().writeFile(full_path, best_contents.bytes);
439441 best_contents.is_generic = true;
......@@ -443,17 +445,17 @@ pub fn main() !void {
443445 missed_opportunity_bytes += this_missed_bytes;
444446 std.debug.warn("Missed opportunity ({:2}): {s}\n", .{
445447 std.fmt.fmtIntSizeDec(this_missed_bytes),
446 path_kv.key.*,
448 path_kv.key_ptr.*,
447449 });
448450 } else break;
449451 }
450452 }
451 var hash_it = path_kv.value.*.iterator();
453 var hash_it = path_kv.value_ptr.*.iterator();
452454 while (hash_it.next()) |hash_kv| {
453 const contents = hash_to_contents.get(hash_kv.value.*).?;
455 const contents = hash_to_contents.get(hash_kv.value_ptr.*).?;
454456 if (contents.is_generic) continue;
455457
456 const dest_target = hash_kv.key.*;
458 const dest_target = hash_kv.key_ptr.*;
457459 const arch_name = switch (dest_target.arch) {
458460 .specific => |a| @tagName(a),
459461 else => @tagName(dest_target.arch),
......@@ -463,7 +465,7 @@ pub fn main() !void {
463465 @tagName(dest_target.os),
464466 @tagName(dest_target.abi),
465467 });
466 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, out_subpath, path_kv.key.* });
468 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, out_subpath, path_kv.key_ptr.* });
467469 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
468470 try std.fs.cwd().writeFile(full_path, contents.bytes);
469471 }
tools/update_cpu_features.zig+11-11
......@@ -902,19 +902,19 @@ fn processOneTarget(job: Job) anyerror!void {
902902 {
903903 var it = root_map.iterator();
904904 root_it: while (it.next()) |kv| {
905 if (kv.key.len == 0) continue;
906 if (kv.key.*[0] == '!') continue;
907 if (kv.value.* != .Object) continue;
908 if (hasSuperclass(&kv.value.Object, "SubtargetFeature")) {
909 const llvm_name = kv.value.Object.get("Name").?.String;
905 if (kv.key_ptr.len == 0) continue;
906 if (kv.key_ptr.*[0] == '!') continue;
907 if (kv.value_ptr.* != .Object) continue;
908 if (hasSuperclass(&kv.value_ptr.Object, "SubtargetFeature")) {
909 const llvm_name = kv.value_ptr.Object.get("Name").?.String;
910910 if (llvm_name.len == 0) continue;
911911
912912 var zig_name = try llvmNameToZigName(arena, llvm_name);
913 var desc = kv.value.Object.get("Desc").?.String;
913 var desc = kv.value_ptr.Object.get("Desc").?.String;
914914 var deps = std.ArrayList([]const u8).init(arena);
915915 var omit = false;
916916 var flatten = false;
917 const implies = kv.value.Object.get("Implies").?.Array;
917 const implies = kv.value_ptr.Object.get("Implies").?.Array;
918918 for (implies.items) |imply| {
919919 const other_key = imply.Object.get("def").?.String;
920920 const other_obj = &root_map.getPtr(other_key).?.Object;
......@@ -960,13 +960,13 @@ fn processOneTarget(job: Job) anyerror!void {
960960 try all_features.append(feature);
961961 }
962962 }
963 if (hasSuperclass(&kv.value.Object, "Processor")) {
964 const llvm_name = kv.value.Object.get("Name").?.String;
963 if (hasSuperclass(&kv.value_ptr.Object, "Processor")) {
964 const llvm_name = kv.value_ptr.Object.get("Name").?.String;
965965 if (llvm_name.len == 0) continue;
966966
967967 var zig_name = try llvmNameToZigName(arena, llvm_name);
968968 var deps = std.ArrayList([]const u8).init(arena);
969 const features = kv.value.Object.get("Features").?.Array;
969 const features = kv.value_ptr.Object.get("Features").?.Array;
970970 for (features.items) |feature| {
971971 const feature_key = feature.Object.get("def").?.String;
972972 const feature_obj = &root_map.getPtr(feature_key).?.Object;
......@@ -979,7 +979,7 @@ fn processOneTarget(job: Job) anyerror!void {
979979 )) orelse continue;
980980 try deps.append(feature_zig_name);
981981 }
982 const tune_features = kv.value.Object.get("TuneFeatures").?.Array;
982 const tune_features = kv.value_ptr.Object.get("TuneFeatures").?.Array;
983983 for (tune_features.items) |feature| {
984984 const feature_key = feature.Object.get("def").?.String;
985985 const feature_obj = &root_map.getPtr(feature_key).?.Object;
tools/update_spirv_features.zig+3
......@@ -68,6 +68,9 @@ pub fn main() !void {
6868 usageAndExit(std.io.getStdErr(), args[0], 1);
6969 }
7070
71 // Required for json parsing.
72 @setEvalBranchQuota(10000);
73
7174 const registry_path = try fs.path.join(allocator, &.{ spirv_headers_root, "include", "spirv", "unified1", "spirv.core.grammar.json" });
7275 const registry_json = try std.fs.cwd().readFileAlloc(allocator, registry_path, std.math.maxInt(usize));
7376 var tokens = std.json.TokenStream.init(registry_json);