aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-12-10 15:25:06 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-01-01 17:51:18 -0700
commit12de7e3472cb2292e75578d33a8b8cc91f1ef0b0 (patch)
tree77d38282ed0b8cc4911df38b702c09762b52c681 /src/codegen/llvm.zig
parentb92e30ff0bd2b77a486451b21d17666a311407f3 (diff)
downloadzig-12de7e3472cb2292e75578d33a8b8cc91f1ef0b0.tar.gz
zig-12de7e3472cb2292e75578d33a8b8cc91f1ef0b0.zip
WIP: move many global settings to become per-Module
Much of the logic from Compilation.create() is extracted into Compilation.Config.resolve() which accepts many optional settings and produces concrete settings. This separate step is needed by API users of Compilation so that they can pass the resolved global settings to the Module creation function, which itself needs to resolve per-Module settings. Since the target and other things are no longer global settings, I did not want them stored in link.File (in the `options` field). That options field was already a kludge; those options should be resolved into concrete settings. This commit also starts to work on that, deleting link.Options, moving the fields into Compilation and ObjectFormat-specific structs instead. Some fields were ephemeral and should not have been stored at all, such as symbol_size_hint. The link.File object of Compilation is now a `?*link.File` and `null` when -fno-emit-bin is passed. It is now arena-allocated along with Compilation itself, avoiding some messy cleanup code that was there before. On the command line, it is now possible to configure the standard library itself by using `--mod std` just like any other module. This meant that the CLI needed to create the standard library module rather than having Compilation create it. There are a lot of changes in this commit and it's still not done. I didn't realize how quickly this changeset was going to balloon out of control, and there are still many lines that need to be changed before it even compiles successfully. * introduce std.Build.Cache.HashHelper.oneShot * add error_tracing to std.Build.Module * extract build.zig file generation into src/Builtin.zig * each CSourceFile and RcSourceFile now has a Module owner, which determines some of the C compiler flags.
Diffstat (limited to 'src/codegen/llvm.zig')
-rw-r--r--src/codegen/llvm.zig38
1 files changed, 12 insertions, 26 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 70eab9489c..cf6f38a53e 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -853,16 +853,9 @@ pub const Object = struct {
/// want to iterate over it while adding entries to it.
pub const DITypeMap = std.AutoArrayHashMapUnmanaged(InternPool.Index, AnnotatedDITypePtr);
- pub fn create(gpa: Allocator, options: link.Options) !*Object {
- const obj = try gpa.create(Object);
- errdefer gpa.destroy(obj);
- obj.* = try Object.init(gpa, options);
- return obj;
- }
-
- pub fn init(gpa: Allocator, options: link.Options) !Object {
- const llvm_target_triple = try targetTriple(gpa, options.target);
- defer gpa.free(llvm_target_triple);
+ pub fn create(arena: Allocator, options: link.File.OpenOptions) !*Object {
+ const gpa = options.comp.gpa;
+ const llvm_target_triple = try targetTriple(arena, options.target);
var builder = try Builder.init(.{
.allocator = gpa,
@@ -899,19 +892,14 @@ pub const Object = struct {
// TODO: the only concern I have with this is WASI as either host or target, should
// we leave the paths as relative then?
const compile_unit_dir_z = blk: {
- var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
if (options.module) |mod| m: {
- const d = try mod.root_mod.root.joinStringZ(builder.gpa, "");
+ const d = try mod.root_mod.root.joinStringZ(arena, "");
if (d.len == 0) break :m;
if (std.fs.path.isAbsolute(d)) break :blk d;
- const abs = std.fs.realpath(d, &buf) catch break :blk d;
- builder.gpa.free(d);
- break :blk try builder.gpa.dupeZ(u8, abs);
+ break :blk std.fs.realpathAlloc(arena, d) catch d;
}
- const cwd = try std.process.getCwd(&buf);
- break :blk try builder.gpa.dupeZ(u8, cwd);
+ break :blk try std.process.getCwdAlloc(arena);
};
- defer builder.gpa.free(compile_unit_dir_z);
builder.llvm.di_compile_unit = builder.llvm.di_builder.?.createCompileUnit(
DW.LANG.C99,
@@ -989,7 +977,8 @@ pub const Object = struct {
}
}
- return .{
+ const obj = try arena.create(Object);
+ obj.* = .{
.gpa = gpa,
.builder = builder,
.module = options.module.?,
@@ -1009,9 +998,11 @@ pub const Object = struct {
.null_opt_usize = .no_init,
.struct_field_map = .{},
};
+ return obj;
}
- pub fn deinit(self: *Object, gpa: Allocator) void {
+ pub fn deinit(self: *Object) void {
+ const gpa = self.gpa;
self.di_map.deinit(gpa);
self.di_type_map.deinit(gpa);
if (self.builder.useLibLlvm()) {
@@ -1028,11 +1019,6 @@ pub const Object = struct {
self.* = undefined;
}
- pub fn destroy(self: *Object, gpa: Allocator) void {
- self.deinit(gpa);
- gpa.destroy(self);
- }
-
fn locPath(
arena: Allocator,
opt_loc: ?Compilation.EmitLoc,
@@ -2899,7 +2885,7 @@ pub const Object = struct {
fn getStackTraceType(o: *Object) Allocator.Error!Type {
const mod = o.module;
- const std_mod = mod.main_mod.deps.get("std").?;
+ const std_mod = mod.std_mod;
const std_file = (mod.importPkg(std_mod) catch unreachable).file;
const builtin_str = try mod.intern_pool.getOrPutString(mod.gpa, "builtin");