diff --git a/src/Compilation.zig b/src/Compilation.zig index 3752e93a0d..5b168fe1f3 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -165,6 +165,7 @@ clang_preprocessor_mode: ClangPreprocessorMode, /// Whether to print clang argvs to stdout. verbose_cc: bool, verbose_air: bool, +verbose_air_output: ?*std.io.Writer = null, verbose_intern_pool: bool, verbose_generic_instances: bool, verbose_llvm_ir: ?[]const u8, @@ -2259,6 +2260,7 @@ pub fn create(gpa: Allocator, arena: Allocator, diag: *CreateDiagnostic, options .clang_preprocessor_mode = options.clang_preprocessor_mode, .verbose_cc = options.verbose_cc, .verbose_air = options.verbose_air, + .verbose_air_output = null, .verbose_intern_pool = options.verbose_intern_pool, .verbose_generic_instances = options.verbose_generic_instances, .verbose_llvm_ir = options.verbose_llvm_ir, diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index a4024be07a..1797f02e94 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -4468,11 +4468,17 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e defer if (liveness) |*l| l.deinit(gpa); if (build_options.enable_debug_extensions and comp.verbose_air) { - const stderr = std.debug.lockStderrWriter(&.{}); - defer std.debug.unlockStderrWriter(); - stderr.print("# Begin Function AIR: {f}:\n", .{fqn.fmt(ip)}) catch {}; - air.write(stderr, pt, liveness); - stderr.print("# End Function AIR: {f}\n\n", .{fqn.fmt(ip)}) catch {}; + if (comp.verbose_air_output) |writer| { + writer.print("# Begin Function AIR: {f}:\n", .{fqn.fmt(ip)}) catch {}; + air.write(writer, pt, null); + writer.print("# End Function AIR: {f}\n\n", .{fqn.fmt(ip)}) catch {}; + } else { + const stderr = std.debug.lockStderrWriter(&.{}); + defer std.debug.unlockStderrWriter(); + stderr.print("# Begin Function AIR: {f}:\n", .{fqn.fmt(ip)}) catch {}; + air.write(stderr, pt, liveness); + stderr.print("# End Function AIR: {f}\n\n", .{fqn.fmt(ip)}) catch {}; + } } if (std.debug.runtime_safety) verify_liveness: {