authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-26 17:44:23-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:56-07:00
loga596ea683c35d90c6af3e1fbeae2e06312ce392f
tree2da3ac1beb27115081051cb152a79ca8cb0521d0
parent8011faa0049df757bab78310af824b283220bcac

CLI: introduce --verbose-intern-pool

and stop dumping to stderr without the user's consent.

2 files changed, 16 insertions(+), 4 deletions(-)

src/Compilation.zig+11-4
......@@ -87,6 +87,7 @@ clang_preprocessor_mode: ClangPreprocessorMode,
8787/// Whether to print clang argvs to stdout.
8888verbose_cc: bool,
8989verbose_air: bool,
90verbose_intern_pool: bool,
9091verbose_llvm_ir: ?[]const u8,
9192verbose_llvm_bc: ?[]const u8,
9293verbose_cimport: bool,
......@@ -593,6 +594,7 @@ pub const InitOptions = struct {
593594 verbose_cc: bool = false,
594595 verbose_link: bool = false,
595596 verbose_air: bool = false,
597 verbose_intern_pool: bool = false,
596598 verbose_llvm_ir: ?[]const u8 = null,
597599 verbose_llvm_bc: ?[]const u8 = null,
598600 verbose_cimport: bool = false,
......@@ -1574,6 +1576,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
15741576 .clang_preprocessor_mode = options.clang_preprocessor_mode,
15751577 .verbose_cc = options.verbose_cc,
15761578 .verbose_air = options.verbose_air,
1579 .verbose_intern_pool = options.verbose_intern_pool,
15771580 .verbose_llvm_ir = options.verbose_llvm_ir,
15781581 .verbose_llvm_bc = options.verbose_llvm_bc,
15791582 .verbose_cimport = options.verbose_cimport,
......@@ -2026,10 +2029,12 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
20262029 try comp.performAllTheWork(main_progress_node);
20272030
20282031 if (comp.bin_file.options.module) |module| {
2029 std.debug.print("intern pool stats for '{s}':\n", .{
2030 comp.bin_file.options.root_name,
2031 });
2032 module.intern_pool.dump();
2032 if (builtin.mode == .Debug and comp.verbose_intern_pool) {
2033 std.debug.print("intern pool stats for '{s}':\n", .{
2034 comp.bin_file.options.root_name,
2035 });
2036 module.intern_pool.dump();
2037 }
20332038
20342039 if (comp.bin_file.options.is_test and comp.totalErrorCount() == 0) {
20352040 // The `test_functions` decl has been intentionally postponed until now,
......@@ -5422,6 +5427,7 @@ fn buildOutputFromZig(
54225427 .verbose_cc = comp.verbose_cc,
54235428 .verbose_link = comp.bin_file.options.verbose_link,
54245429 .verbose_air = comp.verbose_air,
5430 .verbose_intern_pool = comp.verbose_intern_pool,
54255431 .verbose_llvm_ir = comp.verbose_llvm_ir,
54265432 .verbose_llvm_bc = comp.verbose_llvm_bc,
54275433 .verbose_cimport = comp.verbose_cimport,
......@@ -5500,6 +5506,7 @@ pub fn build_crt_file(
55005506 .verbose_cc = comp.verbose_cc,
55015507 .verbose_link = comp.bin_file.options.verbose_link,
55025508 .verbose_air = comp.verbose_air,
5509 .verbose_intern_pool = comp.verbose_intern_pool,
55035510 .verbose_llvm_ir = comp.verbose_llvm_ir,
55045511 .verbose_llvm_bc = comp.verbose_llvm_bc,
55055512 .verbose_cimport = comp.verbose_cimport,
src/main.zig+5
......@@ -569,6 +569,7 @@ const usage_build_generic =
569569 \\ --verbose-link Display linker invocations
570570 \\ --verbose-cc Display C compiler invocations
571571 \\ --verbose-air Enable compiler debug output for Zig AIR
572 \\ --verbose-intern-pool Enable compiler debug output for InternPool
572573 \\ --verbose-llvm-ir[=path] Enable compiler debug output for unoptimized LLVM IR
573574 \\ --verbose-llvm-bc=[path] Enable compiler debug output for unoptimized LLVM BC
574575 \\ --verbose-cimport Enable compiler debug output for C imports
......@@ -735,6 +736,7 @@ fn buildOutputType(
735736 var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and std.process.hasEnvVarConstant("ZIG_VERBOSE_LINK");
736737 var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and std.process.hasEnvVarConstant("ZIG_VERBOSE_CC");
737738 var verbose_air = false;
739 var verbose_intern_pool = false;
738740 var verbose_llvm_ir: ?[]const u8 = null;
739741 var verbose_llvm_bc: ?[]const u8 = null;
740742 var verbose_cimport = false;
......@@ -1460,6 +1462,8 @@ fn buildOutputType(
14601462 verbose_cc = true;
14611463 } else if (mem.eql(u8, arg, "--verbose-air")) {
14621464 verbose_air = true;
1465 } else if (mem.eql(u8, arg, "--verbose-intern-pool")) {
1466 verbose_intern_pool = true;
14631467 } else if (mem.eql(u8, arg, "--verbose-llvm-ir")) {
14641468 verbose_llvm_ir = "-";
14651469 } else if (mem.startsWith(u8, arg, "--verbose-llvm-ir=")) {
......@@ -3156,6 +3160,7 @@ fn buildOutputType(
31563160 .verbose_cc = verbose_cc,
31573161 .verbose_link = verbose_link,
31583162 .verbose_air = verbose_air,
3163 .verbose_intern_pool = verbose_intern_pool,
31593164 .verbose_llvm_ir = verbose_llvm_ir,
31603165 .verbose_llvm_bc = verbose_llvm_bc,
31613166 .verbose_cimport = verbose_cimport,