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,...@@ -87,6 +87,7 @@ clang_preprocessor_mode: ClangPreprocessorMode,
87/// Whether to print clang argvs to stdout.87/// Whether to print clang argvs to stdout.
88verbose_cc: bool,88verbose_cc: bool,
89verbose_air: bool,89verbose_air: bool,
90verbose_intern_pool: bool,
90verbose_llvm_ir: ?[]const u8,91verbose_llvm_ir: ?[]const u8,
91verbose_llvm_bc: ?[]const u8,92verbose_llvm_bc: ?[]const u8,
92verbose_cimport: bool,93verbose_cimport: bool,
...@@ -593,6 +594,7 @@ pub const InitOptions = struct {...@@ -593,6 +594,7 @@ pub const InitOptions = struct {
593 verbose_cc: bool = false,594 verbose_cc: bool = false,
594 verbose_link: bool = false,595 verbose_link: bool = false,
595 verbose_air: bool = false,596 verbose_air: bool = false,
597 verbose_intern_pool: bool = false,
596 verbose_llvm_ir: ?[]const u8 = null,598 verbose_llvm_ir: ?[]const u8 = null,
597 verbose_llvm_bc: ?[]const u8 = null,599 verbose_llvm_bc: ?[]const u8 = null,
598 verbose_cimport: bool = false,600 verbose_cimport: bool = false,
...@@ -1574,6 +1576,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1574,6 +1576,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1574 .clang_preprocessor_mode = options.clang_preprocessor_mode,1576 .clang_preprocessor_mode = options.clang_preprocessor_mode,
1575 .verbose_cc = options.verbose_cc,1577 .verbose_cc = options.verbose_cc,
1576 .verbose_air = options.verbose_air,1578 .verbose_air = options.verbose_air,
1579 .verbose_intern_pool = options.verbose_intern_pool,
1577 .verbose_llvm_ir = options.verbose_llvm_ir,1580 .verbose_llvm_ir = options.verbose_llvm_ir,
1578 .verbose_llvm_bc = options.verbose_llvm_bc,1581 .verbose_llvm_bc = options.verbose_llvm_bc,
1579 .verbose_cimport = options.verbose_cimport,1582 .verbose_cimport = options.verbose_cimport,
...@@ -2026,10 +2029,12 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void...@@ -2026,10 +2029,12 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
2026 try comp.performAllTheWork(main_progress_node);2029 try comp.performAllTheWork(main_progress_node);
20272030
2028 if (comp.bin_file.options.module) |module| {2031 if (comp.bin_file.options.module) |module| {
2029 std.debug.print("intern pool stats for '{s}':\n", .{2032 if (builtin.mode == .Debug and comp.verbose_intern_pool) {
2030 comp.bin_file.options.root_name,2033 std.debug.print("intern pool stats for '{s}':\n", .{
2031 });2034 comp.bin_file.options.root_name,
2032 module.intern_pool.dump();2035 });
2036 module.intern_pool.dump();
2037 }
20332038
2034 if (comp.bin_file.options.is_test and comp.totalErrorCount() == 0) {2039 if (comp.bin_file.options.is_test and comp.totalErrorCount() == 0) {
2035 // The `test_functions` decl has been intentionally postponed until now,2040 // The `test_functions` decl has been intentionally postponed until now,
...@@ -5422,6 +5427,7 @@ fn buildOutputFromZig(...@@ -5422,6 +5427,7 @@ fn buildOutputFromZig(
5422 .verbose_cc = comp.verbose_cc,5427 .verbose_cc = comp.verbose_cc,
5423 .verbose_link = comp.bin_file.options.verbose_link,5428 .verbose_link = comp.bin_file.options.verbose_link,
5424 .verbose_air = comp.verbose_air,5429 .verbose_air = comp.verbose_air,
5430 .verbose_intern_pool = comp.verbose_intern_pool,
5425 .verbose_llvm_ir = comp.verbose_llvm_ir,5431 .verbose_llvm_ir = comp.verbose_llvm_ir,
5426 .verbose_llvm_bc = comp.verbose_llvm_bc,5432 .verbose_llvm_bc = comp.verbose_llvm_bc,
5427 .verbose_cimport = comp.verbose_cimport,5433 .verbose_cimport = comp.verbose_cimport,
...@@ -5500,6 +5506,7 @@ pub fn build_crt_file(...@@ -5500,6 +5506,7 @@ pub fn build_crt_file(
5500 .verbose_cc = comp.verbose_cc,5506 .verbose_cc = comp.verbose_cc,
5501 .verbose_link = comp.bin_file.options.verbose_link,5507 .verbose_link = comp.bin_file.options.verbose_link,
5502 .verbose_air = comp.verbose_air,5508 .verbose_air = comp.verbose_air,
5509 .verbose_intern_pool = comp.verbose_intern_pool,
5503 .verbose_llvm_ir = comp.verbose_llvm_ir,5510 .verbose_llvm_ir = comp.verbose_llvm_ir,
5504 .verbose_llvm_bc = comp.verbose_llvm_bc,5511 .verbose_llvm_bc = comp.verbose_llvm_bc,
5505 .verbose_cimport = comp.verbose_cimport,5512 .verbose_cimport = comp.verbose_cimport,
src/main.zig+5
...@@ -569,6 +569,7 @@ const usage_build_generic =...@@ -569,6 +569,7 @@ const usage_build_generic =
569 \\ --verbose-link Display linker invocations569 \\ --verbose-link Display linker invocations
570 \\ --verbose-cc Display C compiler invocations570 \\ --verbose-cc Display C compiler invocations
571 \\ --verbose-air Enable compiler debug output for Zig AIR571 \\ --verbose-air Enable compiler debug output for Zig AIR
572 \\ --verbose-intern-pool Enable compiler debug output for InternPool
572 \\ --verbose-llvm-ir[=path] Enable compiler debug output for unoptimized LLVM IR573 \\ --verbose-llvm-ir[=path] Enable compiler debug output for unoptimized LLVM IR
573 \\ --verbose-llvm-bc=[path] Enable compiler debug output for unoptimized LLVM BC574 \\ --verbose-llvm-bc=[path] Enable compiler debug output for unoptimized LLVM BC
574 \\ --verbose-cimport Enable compiler debug output for C imports575 \\ --verbose-cimport Enable compiler debug output for C imports
...@@ -735,6 +736,7 @@ fn buildOutputType(...@@ -735,6 +736,7 @@ fn buildOutputType(
735 var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and std.process.hasEnvVarConstant("ZIG_VERBOSE_LINK");736 var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and std.process.hasEnvVarConstant("ZIG_VERBOSE_LINK");
736 var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and std.process.hasEnvVarConstant("ZIG_VERBOSE_CC");737 var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and std.process.hasEnvVarConstant("ZIG_VERBOSE_CC");
737 var verbose_air = false;738 var verbose_air = false;
739 var verbose_intern_pool = false;
738 var verbose_llvm_ir: ?[]const u8 = null;740 var verbose_llvm_ir: ?[]const u8 = null;
739 var verbose_llvm_bc: ?[]const u8 = null;741 var verbose_llvm_bc: ?[]const u8 = null;
740 var verbose_cimport = false;742 var verbose_cimport = false;
...@@ -1460,6 +1462,8 @@ fn buildOutputType(...@@ -1460,6 +1462,8 @@ fn buildOutputType(
1460 verbose_cc = true;1462 verbose_cc = true;
1461 } else if (mem.eql(u8, arg, "--verbose-air")) {1463 } else if (mem.eql(u8, arg, "--verbose-air")) {
1462 verbose_air = true;1464 verbose_air = true;
1465 } else if (mem.eql(u8, arg, "--verbose-intern-pool")) {
1466 verbose_intern_pool = true;
1463 } else if (mem.eql(u8, arg, "--verbose-llvm-ir")) {1467 } else if (mem.eql(u8, arg, "--verbose-llvm-ir")) {
1464 verbose_llvm_ir = "-";1468 verbose_llvm_ir = "-";
1465 } else if (mem.startsWith(u8, arg, "--verbose-llvm-ir=")) {1469 } else if (mem.startsWith(u8, arg, "--verbose-llvm-ir=")) {
...@@ -3156,6 +3160,7 @@ fn buildOutputType(...@@ -3156,6 +3160,7 @@ fn buildOutputType(
3156 .verbose_cc = verbose_cc,3160 .verbose_cc = verbose_cc,
3157 .verbose_link = verbose_link,3161 .verbose_link = verbose_link,
3158 .verbose_air = verbose_air,3162 .verbose_air = verbose_air,
3163 .verbose_intern_pool = verbose_intern_pool,
3159 .verbose_llvm_ir = verbose_llvm_ir,3164 .verbose_llvm_ir = verbose_llvm_ir,
3160 .verbose_llvm_bc = verbose_llvm_bc,3165 .verbose_llvm_bc = verbose_llvm_bc,
3161 .verbose_cimport = verbose_cimport,3166 .verbose_cimport = verbose_cimport,