control verbosity of LLVM code

This commit is contained in:
David Gonzalez Martin 2024-01-29 07:24:15 +01:00
parent 3acc68f52e
commit 48fa7d1762
2 changed files with 17 additions and 9 deletions

View File

@ -392,9 +392,10 @@ pub const Package = struct {
}; };
const LoggerScope = enum { const LoggerScope = enum {
compilation,
lexer, lexer,
parser, parser,
compilation,
llvm,
}; };
const Logger = enum { const Logger = enum {
@ -416,6 +417,7 @@ fn getLoggerScopeType(comptime logger_scope: LoggerScope) type {
.compilation => @This(), .compilation => @This(),
.lexer => lexer, .lexer => lexer,
.parser => parser, .parser => parser,
.llvm => llvm,
}; };
} }
} }

View File

@ -3,6 +3,8 @@ const equal = std.mem.eql;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const assert = std.debug.assert; const assert = std.debug.assert;
const Compilation = @import("../Compilation.zig"); const Compilation = @import("../Compilation.zig");
const log = Compilation.log;
const logln = Compilation.logln;
const Module = Compilation.Module; const Module = Compilation.Module;
const data_structures = @import("../data_structures.zig"); const data_structures = @import("../data_structures.zig");
const ArrayList = data_structures.ArrayList; const ArrayList = data_structures.ArrayList;
@ -10,6 +12,16 @@ const AutoHashMap = data_structures.AutoHashMap;
const bindings = @import("llvm_bindings.zig"); const bindings = @import("llvm_bindings.zig");
pub const Logger = enum {
print_module,
function,
pub var bitset = std.EnumSet(Logger).initMany(&.{
.print_module,
.function,
});
};
pub const LLVM = struct { pub const LLVM = struct {
context: *LLVM.Context, context: *LLVM.Context,
module: *LLVM.Module, module: *LLVM.Module,
@ -3415,10 +3427,7 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo
llvm.scope = subprogram.toLocalScope().toScope(); llvm.scope = subprogram.toLocalScope().toScope();
} }
const print_function_name = true; logln(.llvm, .function, "[LLVM] Compiling {s}...\n", .{name});
if (print_function_name) {
std.debug.print("[LLVM] Compiling {s}...\n", .{name});
}
llvm.arg_index = 0; llvm.arg_index = 0;
llvm.alloca_map.clearRetainingCapacity(); llvm.alloca_map.clearRetainingCapacity();
@ -3461,13 +3470,10 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo
di_builder.finalize(); di_builder.finalize();
} }
const print_module = true;
if (print_module) {
var module_len: usize = 0; var module_len: usize = 0;
const module_ptr = llvm.module.toString(&module_len); const module_ptr = llvm.module.toString(&module_len);
const module_string = module_ptr[0..module_len]; const module_string = module_ptr[0..module_len];
std.debug.print("{s}\n", .{module_string}); logln(.llvm, .print_module, "{s}", .{module_string});
}
const verify_module = true; const verify_module = true;
if (verify_module) { if (verify_module) {