| ... | ... | @@ -118,6 +118,7 @@ const debug_usage = normal_usage ++ |
| 118 | 118 | \\ changelist Compute mappings from old ZIR to new ZIR |
| 119 | 119 | \\ dump-zir Dump a file containing cached ZIR |
| 120 | 120 | \\ detect-cpu Compare Zig's CPU feature detection vs LLVM |
| 121 | \\ llvm-ints Dump a list of LLVMABIAlignmentOfType for all integers |
| 121 | 122 | \\ |
| 122 | 123 | ; |
| 123 | 124 | |
| ... | ... | @@ -359,6 +360,8 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 359 | 360 | return cmdChangelist(gpa, arena, cmd_args); |
| 360 | 361 | } else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "dump-zir")) { |
| 361 | 362 | return cmdDumpZir(gpa, arena, cmd_args); |
| 363 | } else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "llvm-ints")) { |
| 364 | return cmdDumpLlvmInts(gpa, arena, cmd_args); |
| 362 | 365 | } else { |
| 363 | 366 | std.log.info("{s}", .{usage}); |
| 364 | 367 | fatal("unknown command: {s}", .{args[1]}); |
| ... | ... | @@ -6292,6 +6295,48 @@ fn printCpu(cpu: std.Target.Cpu) !void { |
| 6292 | 6295 | try bw.flush(); |
| 6293 | 6296 | } |
| 6294 | 6297 | |
| 6298 | fn cmdDumpLlvmInts( |
| 6299 | gpa: Allocator, |
| 6300 | arena: Allocator, |
| 6301 | args: []const []const u8, |
| 6302 | ) !void { |
| 6303 | _ = gpa; |
| 6304 | |
| 6305 | if (!build_options.have_llvm) |
| 6306 | fatal("compiler does not use LLVM; cannot dump LLVM integer sizes", .{}); |
| 6307 | |
| 6308 | const triple = try arena.dupeZ(u8, args[0]); |
| 6309 | |
| 6310 | const llvm = @import("codegen/llvm/bindings.zig"); |
| 6311 | |
| 6312 | for ([_]std.Target.Cpu.Arch{ .aarch64, .x86 }) |arch| { |
| 6313 | @import("codegen/llvm.zig").initializeLLVMTarget(arch); |
| 6314 | } |
| 6315 | |
| 6316 | const target: *llvm.Target = t: { |
| 6317 | var target: *llvm.Target = undefined; |
| 6318 | var error_message: [*:0]const u8 = undefined; |
| 6319 | if (llvm.Target.getFromTriple(triple, &target, &error_message) != .False) @panic("bad"); |
| 6320 | break :t target; |
| 6321 | }; |
| 6322 | const tm = llvm.TargetMachine.create(target, triple, null, null, .None, .Default, .Default, false, false, .Default, null); |
| 6323 | const dl = tm.createTargetDataLayout(); |
| 6324 | const context = llvm.Context.create(); |
| 6325 | |
| 6326 | var bw = io.bufferedWriter(io.getStdOut().writer()); |
| 6327 | const stdout = bw.writer(); |
| 6328 | |
| 6329 | for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| { |
| 6330 | const int_type = context.intType(bits); |
| 6331 | const alignment = dl.abiAlignmentOfType(int_type); |
| 6332 | try stdout.print("LLVMABIAlignmentOfType(i{d}) == {d}\n", .{ bits, alignment }); |
| 6333 | } |
| 6334 | |
| 6335 | try bw.flush(); |
| 6336 | |
| 6337 | return cleanExit(); |
| 6338 | } |
| 6339 | |
| 6295 | 6340 | /// This is only enabled for debug builds. |
| 6296 | 6341 | fn cmdDumpZir( |
| 6297 | 6342 | gpa: Allocator, |