authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-13 15:26:22-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:19-07:00
logb162c3c820d8a6446bbdfba90b3c135ebcd76fcb
tree1e3963fcd0f77ce45b7d9d432734adf33324b62e
parentbc4d2b646d5d09ecb86a3806886fed37e522fdc9

update bin_file.options references in Module (Zcu)


3 files changed, 18 insertions(+), 12 deletions(-)

src/Module.zig+5-9
...@@ -3335,7 +3335,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr...@@ -3335,7 +3335,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr
33353335
3336 const comp = mod.comp;3336 const comp = mod.comp;
33373337
3338 const no_bin_file = (comp.bin_file.options.emit == null and3338 const no_bin_file = (comp.bin_file == null and
3339 comp.emit_asm == null and3339 comp.emit_asm == null and
3340 comp.emit_llvm_ir == null and3340 comp.emit_llvm_ir == null and
3341 comp.emit_llvm_bc == null);3341 comp.emit_llvm_bc == null);
...@@ -4311,14 +4311,14 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err...@@ -4311,14 +4311,14 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
4311 1 => blk: {4311 1 => blk: {
4312 // test decl with no name. Skip the part where we check against4312 // test decl with no name. Skip the part where we check against
4313 // the test name filter.4313 // the test name filter.
4314 if (!comp.bin_file.options.is_test) break :blk false;4314 if (!comp.config.is_test) break :blk false;
4315 if (decl_mod != mod.main_mod) break :blk false;4315 if (decl_mod != mod.main_mod) break :blk false;
4316 try mod.test_functions.put(gpa, new_decl_index, {});4316 try mod.test_functions.put(gpa, new_decl_index, {});
4317 break :blk true;4317 break :blk true;
4318 },4318 },
4319 else => blk: {4319 else => blk: {
4320 if (!is_named_test) break :blk false;4320 if (!is_named_test) break :blk false;
4321 if (!comp.bin_file.options.is_test) break :blk false;4321 if (!comp.config.is_test) break :blk false;
4322 if (decl_mod != mod.main_mod) break :blk false;4322 if (decl_mod != mod.main_mod) break :blk false;
4323 if (comp.test_filter) |test_filter| {4323 if (comp.test_filter) |test_filter| {
4324 if (mem.indexOf(u8, ip.stringToSlice(decl_name), test_filter) == null) {4324 if (mem.indexOf(u8, ip.stringToSlice(decl_name), test_filter) == null) {
...@@ -4627,7 +4627,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4627,7 +4627,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
46274627
4628 // If we don't get an error return trace from a caller, create our own.4628 // If we don't get an error return trace from a caller, create our own.
4629 if (func.analysis(ip).calls_or_awaits_errorable_fn and4629 if (func.analysis(ip).calls_or_awaits_errorable_fn and
4630 mod.comp.bin_file.options.error_return_tracing and4630 mod.comp.config.error_tracing and
4631 !sema.fn_ret_ty.isError(mod))4631 !sema.fn_ret_ty.isError(mod))
4632 {4632 {
4633 sema.setupErrorReturnTrace(&inner_block, last_arg_index) catch |err| switch (err) {4633 sema.setupErrorReturnTrace(&inner_block, last_arg_index) catch |err| switch (err) {
...@@ -5475,7 +5475,7 @@ pub fn populateTestFunctions(...@@ -5475,7 +5475,7 @@ pub fn populateTestFunctions(
5475pub fn linkerUpdateDecl(mod: *Module, decl_index: Decl.Index) !void {5475pub fn linkerUpdateDecl(mod: *Module, decl_index: Decl.Index) !void {
5476 const comp = mod.comp;5476 const comp = mod.comp;
54775477
5478 const no_bin_file = (comp.bin_file.options.emit == null and5478 const no_bin_file = (comp.bin_file == null and
5479 comp.emit_asm == null and5479 comp.emit_asm == null and
5480 comp.emit_llvm_ir == null and5480 comp.emit_llvm_ir == null and
5481 comp.emit_llvm_bc == null);5481 comp.emit_llvm_bc == null);
...@@ -5597,10 +5597,6 @@ pub fn addGlobalAssembly(mod: *Module, decl_index: Decl.Index, source: []const u...@@ -5597,10 +5597,6 @@ pub fn addGlobalAssembly(mod: *Module, decl_index: Decl.Index, source: []const u
5597 }5597 }
5598}5598}
55995599
5600pub fn wantDllExports(mod: Module) bool {
5601 return mod.comp.bin_file.options.dll_export_fns and mod.getTarget().os.tag == .windows;
5602}
5603
5604pub fn getDeclExports(mod: Module, decl_index: Decl.Index) []const *Export {5600pub fn getDeclExports(mod: Module, decl_index: Decl.Index) []const *Export {
5605 if (mod.decl_exports.get(decl_index)) |l| {5601 if (mod.decl_exports.get(decl_index)) |l| {
5606 return l.items;5602 return l.items;
src/codegen/llvm.zig+10-3
...@@ -15,6 +15,7 @@ const link = @import("../link.zig");...@@ -15,6 +15,7 @@ const link = @import("../link.zig");
15const Compilation = @import("../Compilation.zig");15const Compilation = @import("../Compilation.zig");
16const build_options = @import("build_options");16const build_options = @import("build_options");
17const Module = @import("../Module.zig");17const Module = @import("../Module.zig");
18const Zcu = Module;
18const InternPool = @import("../InternPool.zig");19const InternPool = @import("../InternPool.zig");
19const Package = @import("../Package.zig");20const Package = @import("../Package.zig");
20const TypedValue = @import("../TypedValue.zig");21const TypedValue = @import("../TypedValue.zig");
...@@ -1723,7 +1724,7 @@ pub const Object = struct {...@@ -1723,7 +1724,7 @@ pub const Object = struct {
1723 try global_index.rename(decl_name, &self.builder);1724 try global_index.rename(decl_name, &self.builder);
1724 global_index.setLinkage(.external, &self.builder);1725 global_index.setLinkage(.external, &self.builder);
1725 global_index.setUnnamedAddr(.default, &self.builder);1726 global_index.setUnnamedAddr(.default, &self.builder);
1726 if (mod.wantDllExports()) global_index.setDllStorageClass(.default, &self.builder);1727 if (wantDllExports(mod)) global_index.setDllStorageClass(.default, &self.builder);
1727 if (self.di_map.get(decl)) |di_node| {1728 if (self.di_map.get(decl)) |di_node| {
1728 const decl_name_slice = decl_name.slice(&self.builder).?;1729 const decl_name_slice = decl_name.slice(&self.builder).?;
1729 if (try decl.isFunction(mod)) {1730 if (try decl.isFunction(mod)) {
...@@ -1789,7 +1790,7 @@ pub const Object = struct {...@@ -1789,7 +1790,7 @@ pub const Object = struct {
1789 );1790 );
1790 try global_index.rename(fqn, &self.builder);1791 try global_index.rename(fqn, &self.builder);
1791 global_index.setLinkage(.internal, &self.builder);1792 global_index.setLinkage(.internal, &self.builder);
1792 if (mod.wantDllExports()) global_index.setDllStorageClass(.default, &self.builder);1793 if (wantDllExports(mod)) global_index.setDllStorageClass(.default, &self.builder);
1793 global_index.setUnnamedAddr(.unnamed_addr, &self.builder);1794 global_index.setUnnamedAddr(.unnamed_addr, &self.builder);
1794 if (decl.val.getVariable(mod)) |decl_var| {1795 if (decl.val.getVariable(mod)) |decl_var| {
1795 const decl_namespace = mod.namespacePtr(decl.namespace_index);1796 const decl_namespace = mod.namespacePtr(decl.namespace_index);
...@@ -1848,7 +1849,7 @@ pub const Object = struct {...@@ -1848,7 +1849,7 @@ pub const Object = struct {
1848 exports: []const *Module.Export,1849 exports: []const *Module.Export,
1849 ) link.File.UpdateExportsError!void {1850 ) link.File.UpdateExportsError!void {
1850 global_index.setUnnamedAddr(.default, &o.builder);1851 global_index.setUnnamedAddr(.default, &o.builder);
1851 if (mod.wantDllExports()) global_index.setDllStorageClass(.dllexport, &o.builder);1852 if (wantDllExports(mod)) global_index.setDllStorageClass(.dllexport, &o.builder);
1852 global_index.setLinkage(switch (exports[0].opts.linkage) {1853 global_index.setLinkage(switch (exports[0].opts.linkage) {
1853 .Internal => unreachable,1854 .Internal => unreachable,
1854 .Strong => .external,1855 .Strong => .external,
...@@ -11767,3 +11768,9 @@ fn constraintAllowsRegister(constraint: []const u8) bool {...@@ -11767,3 +11768,9 @@ fn constraintAllowsRegister(constraint: []const u8) bool {
11767 }11768 }
11768 } else return false;11769 } else return false;
11769}11770}
11771
11772fn wantDllExports(zcu: *const Zcu) bool {
11773 const lf = zcu.bin_file.?;
11774 const coff = lf.cast(link.File.Coff) orelse return false;
11775 return coff.dll_export_fns;
11776}
src/link/Coff.zig+3
...@@ -9,6 +9,7 @@ llvm_object: ?*LlvmObject = null,...@@ -9,6 +9,7 @@ llvm_object: ?*LlvmObject = null,
9base: link.File,9base: link.File,
10image_base: u64,10image_base: u64,
11error_flags: link.File.ErrorFlags = .{},11error_flags: link.File.ErrorFlags = .{},
12dll_export_fns: bool,
1213
13ptr_width: PtrWidth,14ptr_width: PtrWidth,
14page_size: u32,15page_size: u32,
...@@ -400,6 +401,8 @@ pub fn createEmpty(arena: Allocator, options: link.File.OpenOptions) !*Coff {...@@ -400,6 +401,8 @@ pub fn createEmpty(arena: Allocator, options: link.File.OpenOptions) !*Coff {
400 .Lib => 0x10000000,401 .Lib => 0x10000000,
401 .Obj => 0,402 .Obj => 0,
402 },403 },
404
405 .dll_export_fns = options.dll_export_fns,
403 };406 };
404407
405 const use_llvm = comp.config.use_llvm;408 const use_llvm = comp.config.use_llvm;