aboutsummaryrefslogtreecommitdiff
path: root/src/link
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-05-22 07:58:02 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:47:54 -0700
commit6e0de1d11694a58745da76d601ebab7562feed09 (patch)
treecd6cf352788d8f47bad97a95e4390dd3f6a309c5 /src/link
parent5555bdca047f8dbf8d7adfa8f248f5ce9b692b9e (diff)
downloadzig-6e0de1d11694a58745da76d601ebab7562feed09.tar.gz
zig-6e0de1d11694a58745da76d601ebab7562feed09.zip
InternPool: port most of value tags
Diffstat (limited to 'src/link')
-rw-r--r--src/link/C.zig10
-rw-r--r--src/link/Coff.zig18
-rw-r--r--src/link/Dwarf.zig8
-rw-r--r--src/link/Elf.zig18
-rw-r--r--src/link/MachO.zig28
-rw-r--r--src/link/NvPtx.zig4
-rw-r--r--src/link/Plan9.zig14
-rw-r--r--src/link/SpirV.zig6
-rw-r--r--src/link/Wasm.zig40
9 files changed, 76 insertions, 70 deletions
diff --git a/src/link/C.zig b/src/link/C.zig
index 1a25bfe231..c871d8a02a 100644
--- a/src/link/C.zig
+++ b/src/link/C.zig
@@ -87,12 +87,13 @@ pub fn freeDecl(self: *C, decl_index: Module.Decl.Index) void {
}
}
-pub fn updateFunc(self: *C, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
+pub fn updateFunc(self: *C, module: *Module, func_index: Module.Fn.Index, air: Air, liveness: Liveness) !void {
const tracy = trace(@src());
defer tracy.end();
const gpa = self.base.allocator;
+ const func = module.funcPtr(func_index);
const decl_index = func.owner_decl;
const gop = try self.decl_table.getOrPut(gpa, decl_index);
if (!gop.found_existing) {
@@ -111,7 +112,7 @@ pub fn updateFunc(self: *C, module: *Module, func: *Module.Fn, air: Air, livenes
.value_map = codegen.CValueMap.init(gpa),
.air = air,
.liveness = liveness,
- .func = func,
+ .func_index = func_index,
.object = .{
.dg = .{
.gpa = gpa,
@@ -555,7 +556,8 @@ fn flushDecl(
export_names: std.StringHashMapUnmanaged(void),
) FlushDeclError!void {
const gpa = self.base.allocator;
- const decl = self.base.options.module.?.declPtr(decl_index);
+ const mod = self.base.options.module.?;
+ const decl = mod.declPtr(decl_index);
// Before flushing any particular Decl we must ensure its
// dependencies are already flushed, so that the order in the .c
// file comes out correctly.
@@ -569,7 +571,7 @@ fn flushDecl(
try self.flushLazyFns(f, decl_block.lazy_fns);
try f.all_buffers.ensureUnusedCapacity(gpa, 1);
- if (!(decl.isExtern() and export_names.contains(mem.span(decl.name))))
+ if (!(decl.isExtern(mod) and export_names.contains(mem.span(decl.name))))
f.appendBufAssumeCapacity(decl_block.fwd_decl.items);
}
diff --git a/src/link/Coff.zig b/src/link/Coff.zig
index efaeebc62e..f4ee2fde97 100644
--- a/src/link/Coff.zig
+++ b/src/link/Coff.zig
@@ -1032,18 +1032,19 @@ fn freeAtom(self: *Coff, atom_index: Atom.Index) void {
self.getAtomPtr(atom_index).sym_index = 0;
}
-pub fn updateFunc(self: *Coff, mod: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
+pub fn updateFunc(self: *Coff, mod: *Module, func_index: Module.Fn.Index, air: Air, liveness: Liveness) !void {
if (build_options.skip_non_native and builtin.object_format != .coff) {
@panic("Attempted to compile for object format that was disabled by build configuration");
}
if (build_options.have_llvm) {
if (self.llvm_object) |llvm_object| {
- return llvm_object.updateFunc(mod, func, air, liveness);
+ return llvm_object.updateFunc(mod, func_index, air, liveness);
}
}
const tracy = trace(@src());
defer tracy.end();
+ const func = mod.funcPtr(func_index);
const decl_index = func.owner_decl;
const decl = mod.declPtr(decl_index);
@@ -1057,7 +1058,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func: *Module.Fn, air: Air, livenes
const res = try codegen.generateFunction(
&self.base,
decl.srcLoc(mod),
- func,
+ func_index,
air,
liveness,
&code_buffer,
@@ -1155,11 +1156,10 @@ pub fn updateDecl(
const decl = mod.declPtr(decl_index);
- if (decl.val.tag() == .extern_fn) {
+ if (decl.getExternFunc(mod)) |_| {
return; // TODO Should we do more when front-end analyzed extern decl?
}
- if (decl.val.castTag(.variable)) |payload| {
- const variable = payload.data;
+ if (decl.getVariable(mod)) |variable| {
if (variable.is_extern) {
return; // TODO Should we do more when front-end analyzed extern decl?
}
@@ -1172,7 +1172,7 @@ pub fn updateDecl(
var code_buffer = std.ArrayList(u8).init(self.base.allocator);
defer code_buffer.deinit();
- const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;
+ const decl_val = if (decl.getVariable(mod)) |variable| variable.init.toValue() else decl.val;
const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
.ty = decl.ty,
.val = decl_val,
@@ -1313,7 +1313,7 @@ fn getDeclOutputSection(self: *Coff, decl_index: Module.Decl.Index) u16 {
// TODO: what if this is a function pointer?
.Fn => break :blk self.text_section_index.?,
else => {
- if (val.castTag(.variable)) |_| {
+ if (decl.getVariable(mod)) |_| {
break :blk self.data_section_index.?;
}
break :blk self.rdata_section_index.?;
@@ -1425,7 +1425,7 @@ pub fn updateDeclExports(
// detect the default subsystem.
for (exports) |exp| {
const exported_decl = mod.declPtr(exp.exported_decl);
- if (exported_decl.getFunction() == null) continue;
+ if (exported_decl.getFunctionIndex(mod) == .none) continue;
const winapi_cc = switch (self.base.options.target.cpu.arch) {
.x86 => std.builtin.CallingConvention.Stdcall,
else => std.builtin.CallingConvention.C,
diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig
index ed2883f4da..d6dd6979ea 100644
--- a/src/link/Dwarf.zig
+++ b/src/link/Dwarf.zig
@@ -971,7 +971,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index)
// For functions we need to add a prologue to the debug line program.
try dbg_line_buffer.ensureTotalCapacity(26);
- const func = decl.val.castTag(.function).?.data;
+ const func = decl.getFunction(mod).?;
log.debug("decl.src_line={d}, func.lbrace_line={d}, func.rbrace_line={d}", .{
decl.src_line,
func.lbrace_line,
@@ -1514,7 +1514,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []cons
}
}
-pub fn updateDeclLineNumber(self: *Dwarf, module: *Module, decl_index: Module.Decl.Index) !void {
+pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index) !void {
const tracy = trace(@src());
defer tracy.end();
@@ -1522,8 +1522,8 @@ pub fn updateDeclLineNumber(self: *Dwarf, module: *Module, decl_index: Module.De
const atom = self.getAtom(.src_fn, atom_index);
if (atom.len == 0) return;
- const decl = module.declPtr(decl_index);
- const func = decl.val.castTag(.function).?.data;
+ const decl = mod.declPtr(decl_index);
+ const func = decl.getFunction(mod).?;
log.debug("decl.src_line={d}, func.lbrace_line={d}, func.rbrace_line={d}", .{
decl.src_line,
func.lbrace_line,
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index b27967884e..476b939038 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -2465,7 +2465,7 @@ fn getDeclShdrIndex(self: *Elf, decl_index: Module.Decl.Index) u16 {
// TODO: what if this is a function pointer?
.Fn => break :blk self.text_section_index.?,
else => {
- if (val.castTag(.variable)) |_| {
+ if (decl.getVariable(mod)) |_| {
break :blk self.data_section_index.?;
}
break :blk self.rodata_section_index.?;
@@ -2574,17 +2574,18 @@ fn updateDeclCode(self: *Elf, decl_index: Module.Decl.Index, code: []const u8, s
return local_sym;
}
-pub fn updateFunc(self: *Elf, mod: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
+pub fn updateFunc(self: *Elf, mod: *Module, func_index: Module.Fn.Index, air: Air, liveness: Liveness) !void {
if (build_options.skip_non_native and builtin.object_format != .elf) {
@panic("Attempted to compile for object format that was disabled by build configuration");
}
if (build_options.have_llvm) {
- if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func, air, liveness);
+ if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
}
const tracy = trace(@src());
defer tracy.end();
+ const func = mod.funcPtr(func_index);
const decl_index = func.owner_decl;
const decl = mod.declPtr(decl_index);
@@ -2599,11 +2600,11 @@ pub fn updateFunc(self: *Elf, mod: *Module, func: *Module.Fn, air: Air, liveness
defer if (decl_state) |*ds| ds.deinit();
const res = if (decl_state) |*ds|
- try codegen.generateFunction(&self.base, decl.srcLoc(mod), func, air, liveness, &code_buffer, .{
+ try codegen.generateFunction(&self.base, decl.srcLoc(mod), func_index, air, liveness, &code_buffer, .{
.dwarf = ds,
})
else
- try codegen.generateFunction(&self.base, decl.srcLoc(mod), func, air, liveness, &code_buffer, .none);
+ try codegen.generateFunction(&self.base, decl.srcLoc(mod), func_index, air, liveness, &code_buffer, .none);
const code = switch (res) {
.ok => code_buffer.items,
@@ -2646,11 +2647,10 @@ pub fn updateDecl(
const decl = mod.declPtr(decl_index);
- if (decl.val.tag() == .extern_fn) {
+ if (decl.getExternFunc(mod)) |_| {
return; // TODO Should we do more when front-end analyzed extern decl?
}
- if (decl.val.castTag(.variable)) |payload| {
- const variable = payload.data;
+ if (decl.getVariable(mod)) |variable| {
if (variable.is_extern) {
return; // TODO Should we do more when front-end analyzed extern decl?
}
@@ -2667,7 +2667,7 @@ pub fn updateDecl(
defer if (decl_state) |*ds| ds.deinit();
// TODO implement .debug_info for global variables
- const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;
+ const decl_val = if (decl.getVariable(mod)) |variable| variable.init.toValue() else decl.val;
const res = if (decl_state) |*ds|
try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
.ty = decl.ty,
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
index e7723595db..ffbdcdb91f 100644
--- a/src/link/MachO.zig
+++ b/src/link/MachO.zig
@@ -1847,16 +1847,17 @@ fn addStubEntry(self: *MachO, target: SymbolWithLoc) !void {
self.markRelocsDirtyByTarget(target);
}
-pub fn updateFunc(self: *MachO, mod: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
+pub fn updateFunc(self: *MachO, mod: *Module, func_index: Module.Fn.Index, air: Air, liveness: Liveness) !void {
if (build_options.skip_non_native and builtin.object_format != .macho) {
@panic("Attempted to compile for object format that was disabled by build configuration");
}
if (build_options.have_llvm) {
- if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func, air, liveness);
+ if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
}
const tracy = trace(@src());
defer tracy.end();
+ const func = mod.funcPtr(func_index);
const decl_index = func.owner_decl;
const decl = mod.declPtr(decl_index);
@@ -1874,11 +1875,11 @@ pub fn updateFunc(self: *MachO, mod: *Module, func: *Module.Fn, air: Air, livene
defer if (decl_state) |*ds| ds.deinit();
const res = if (decl_state) |*ds|
- try codegen.generateFunction(&self.base, decl.srcLoc(mod), func, air, liveness, &code_buffer, .{
+ try codegen.generateFunction(&self.base, decl.srcLoc(mod), func_index, air, liveness, &code_buffer, .{
.dwarf = ds,
})
else
- try codegen.generateFunction(&self.base, decl.srcLoc(mod), func, air, liveness, &code_buffer, .none);
+ try codegen.generateFunction(&self.base, decl.srcLoc(mod), func_index, air, liveness, &code_buffer, .none);
var code = switch (res) {
.ok => code_buffer.items,
@@ -1983,18 +1984,17 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !vo
const decl = mod.declPtr(decl_index);
- if (decl.val.tag() == .extern_fn) {
+ if (decl.getExternFunc(mod)) |_| {
return; // TODO Should we do more when front-end analyzed extern decl?
}
- if (decl.val.castTag(.variable)) |payload| {
- const variable = payload.data;
+ if (decl.getVariable(mod)) |variable| {
if (variable.is_extern) {
return; // TODO Should we do more when front-end analyzed extern decl?
}
}
- const is_threadlocal = if (decl.val.castTag(.variable)) |payload|
- payload.data.is_threadlocal and !self.base.options.single_threaded
+ const is_threadlocal = if (decl.getVariable(mod)) |variable|
+ variable.is_threadlocal and !self.base.options.single_threaded
else
false;
if (is_threadlocal) return self.updateThreadlocalVariable(mod, decl_index);
@@ -2012,7 +2012,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !vo
null;
defer if (decl_state) |*ds| ds.deinit();
- const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;
+ const decl_val = if (decl.getVariable(mod)) |variable| variable.init.toValue() else decl.val;
const res = if (decl_state) |*ds|
try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
.ty = decl.ty,
@@ -2177,7 +2177,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D
const decl = module.declPtr(decl_index);
const decl_metadata = self.decls.get(decl_index).?;
- const decl_val = decl.val.castTag(.variable).?.data.init;
+ const decl_val = decl.getVariable(mod).?.init.toValue();
const res = if (decl_state) |*ds|
try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
.ty = decl.ty,
@@ -2278,8 +2278,8 @@ fn getDeclOutputSection(self: *MachO, decl_index: Module.Decl.Index) u8 {
}
}
- if (val.castTag(.variable)) |variable| {
- if (variable.data.is_threadlocal and !single_threaded) {
+ if (decl.getVariable(mod)) |variable| {
+ if (variable.is_threadlocal and !single_threaded) {
break :blk self.thread_data_section_index.?;
}
break :blk self.data_section_index.?;
@@ -2289,7 +2289,7 @@ fn getDeclOutputSection(self: *MachO, decl_index: Module.Decl.Index) u8 {
// TODO: what if this is a function pointer?
.Fn => break :blk self.text_section_index.?,
else => {
- if (val.castTag(.variable)) |_| {
+ if (decl.getVariable(mod)) |_| {
break :blk self.data_section_index.?;
}
break :blk self.data_const_section_index.?;
diff --git a/src/link/NvPtx.zig b/src/link/NvPtx.zig
index 69cd73a602..b74518d930 100644
--- a/src/link/NvPtx.zig
+++ b/src/link/NvPtx.zig
@@ -68,9 +68,9 @@ pub fn deinit(self: *NvPtx) void {
self.base.allocator.free(self.ptx_file_name);
}
-pub fn updateFunc(self: *NvPtx, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
+pub fn updateFunc(self: *NvPtx, module: *Module, func_index: Module.Fn.Index, air: Air, liveness: Liveness) !void {
if (!build_options.have_llvm) return;
- try self.llvm_object.updateFunc(module, func, air, liveness);
+ try self.llvm_object.updateFunc(module, func_index, air, liveness);
}
pub fn updateDecl(self: *NvPtx, module: *Module, decl_index: Module.Decl.Index) !void {
diff --git a/src/link/Plan9.zig b/src/link/Plan9.zig
index 968cbb0e7e..2071833b93 100644
--- a/src/link/Plan9.zig
+++ b/src/link/Plan9.zig
@@ -276,11 +276,12 @@ fn addPathComponents(self: *Plan9, path: []const u8, a: *std.ArrayList(u8)) !voi
}
}
-pub fn updateFunc(self: *Plan9, mod: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
+pub fn updateFunc(self: *Plan9, mod: *Module, func_index: Module.Fn.Index, air: Air, liveness: Liveness) !void {
if (build_options.skip_non_native and builtin.object_format != .plan9) {
@panic("Attempted to compile for object format that was disabled by build configuration");
}
+ const func = mod.funcPtr(func_index);
const decl_index = func.owner_decl;
const decl = mod.declPtr(decl_index);
self.freeUnnamedConsts(decl_index);
@@ -299,7 +300,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func: *Module.Fn, air: Air, livene
const res = try codegen.generateFunction(
&self.base,
decl.srcLoc(mod),
- func,
+ func_index,
air,
liveness,
&code_buffer,
@@ -391,11 +392,10 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I
pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !void {
const decl = mod.declPtr(decl_index);
- if (decl.val.tag() == .extern_fn) {
+ if (decl.getExternFunc(mod)) |_| {
return; // TODO Should we do more when front-end analyzed extern decl?
}
- if (decl.val.castTag(.variable)) |payload| {
- const variable = payload.data;
+ if (decl.getVariable(mod)) |variable| {
if (variable.is_extern) {
return; // TODO Should we do more when front-end analyzed extern decl?
}
@@ -407,7 +407,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !vo
var code_buffer = std.ArrayList(u8).init(self.base.allocator);
defer code_buffer.deinit();
- const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;
+ const decl_val = if (decl.getVariable(mod)) |variable| variable.init.toValue() else decl.val;
// TODO we need the symbol index for symbol in the table of locals for the containing atom
const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
.ty = decl.ty,
@@ -771,7 +771,7 @@ pub fn freeDecl(self: *Plan9, decl_index: Module.Decl.Index) void {
// in the deleteUnusedDecl function.
const mod = self.base.options.module.?;
const decl = mod.declPtr(decl_index);
- const is_fn = (decl.val.tag() == .function);
+ const is_fn = decl.getFunctionIndex(mod) != .none;
if (is_fn) {
var symidx_and_submap = self.fn_decl_table.get(decl.getFileScope(mod)).?;
var submap = symidx_and_submap.functions;
diff --git a/src/link/SpirV.zig b/src/link/SpirV.zig
index da25753b95..0a6608303e 100644
--- a/src/link/SpirV.zig
+++ b/src/link/SpirV.zig
@@ -103,11 +103,13 @@ pub fn deinit(self: *SpirV) void {
self.decl_link.deinit();
}
-pub fn updateFunc(self: *SpirV, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
+pub fn updateFunc(self: *SpirV, module: *Module, func_index: Module.Fn.Index, air: Air, liveness: Liveness) !void {
if (build_options.skip_non_native) {
@panic("Attempted to compile for architecture that was disabled by build configuration");
}
+ const func = module.funcPtr(func_index);
+
var decl_gen = codegen.DeclGen.init(self.base.allocator, module, &self.spv, &self.decl_link);
defer decl_gen.deinit();
@@ -136,7 +138,7 @@ pub fn updateDeclExports(
exports: []const *Module.Export,
) !void {
const decl = mod.declPtr(decl_index);
- if (decl.val.tag() == .function and decl.ty.fnCallingConvention(mod) == .Kernel) {
+ if (decl.getFunctionIndex(mod) != .none and decl.ty.fnCallingConvention(mod) == .Kernel) {
// TODO: Unify with resolveDecl in spirv.zig.
const entry = try self.decl_link.getOrPut(decl_index);
if (!entry.found_existing) {
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig
index ef97a7fa7f..78d1be978b 100644
--- a/src/link/Wasm.zig
+++ b/src/link/Wasm.zig
@@ -1324,17 +1324,18 @@ pub fn allocateSymbol(wasm: *Wasm) !u32 {
return index;
}
-pub fn updateFunc(wasm: *Wasm, mod: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
+pub fn updateFunc(wasm: *Wasm, mod: *Module, func_index: Module.Fn.Index, air: Air, liveness: Liveness) !void {
if (build_options.skip_non_native and builtin.object_format != .wasm) {
@panic("Attempted to compile for object format that was disabled by build configuration");
}
if (build_options.have_llvm) {
- if (wasm.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func, air, liveness);
+ if (wasm.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
}
const tracy = trace(@src());
defer tracy.end();
+ const func = mod.funcPtr(func_index);
const decl_index = func.owner_decl;
const decl = mod.declPtr(decl_index);
const atom_index = try wasm.getOrCreateAtomForDecl(decl_index);
@@ -1358,7 +1359,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func: *Module.Fn, air: Air, livenes
const result = try codegen.generateFunction(
&wasm.base,
decl.srcLoc(mod),
- func,
+ func_index,
air,
liveness,
&code_writer,
@@ -1403,9 +1404,9 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi
defer tracy.end();
const decl = mod.declPtr(decl_index);
- if (decl.val.castTag(.function)) |_| {
+ if (decl.getFunction(mod)) |_| {
return;
- } else if (decl.val.castTag(.extern_fn)) |_| {
+ } else if (decl.getExternFunc(mod)) |_| {
return;
}
@@ -1413,12 +1414,13 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi
const atom = wasm.getAtomPtr(atom_index);
atom.clear();
- if (decl.isExtern()) {
- const variable = decl.getVariable().?;
+ if (decl.isExtern(mod)) {
+ const variable = decl.getVariable(mod).?;
const name = mem.sliceTo(decl.name, 0);
- return wasm.addOrUpdateImport(name, atom.sym_index, variable.lib_name, null);
+ const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name);
+ return wasm.addOrUpdateImport(name, atom.sym_index, lib_name, null);
}
- const val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;
+ const val = if (decl.getVariable(mod)) |variable| variable.init.toValue() else decl.val;
var code_writer = std.ArrayList(u8).init(wasm.base.allocator);
defer code_writer.deinit();
@@ -1791,7 +1793,7 @@ pub fn freeDecl(wasm: *Wasm, decl_index: Module.Decl.Index) void {
assert(wasm.symbol_atom.remove(local_atom.symbolLoc()));
}
- if (decl.isExtern()) {
+ if (decl.isExtern(mod)) {
_ = wasm.imports.remove(atom.symbolLoc());
}
_ = wasm.resolved_symbols.swapRemove(atom.symbolLoc());
@@ -1852,7 +1854,7 @@ pub fn addOrUpdateImport(
/// Symbol index that is external
symbol_index: u32,
/// Optional library name (i.e. `extern "c" fn foo() void`
- lib_name: ?[*:0]const u8,
+ lib_name: ?[:0]const u8,
/// The index of the type that represents the function signature
/// when the extern is a function. When this is null, a data-symbol
/// is asserted instead.
@@ -1863,7 +1865,7 @@ pub fn addOrUpdateImport(
// Also mangle the name when the lib name is set and not equal to "C" so imports with the same
// name but different module can be resolved correctly.
const mangle_name = lib_name != null and
- !std.mem.eql(u8, std.mem.sliceTo(lib_name.?, 0), "c");
+ !std.mem.eql(u8, lib_name.?, "c");
const full_name = if (mangle_name) full_name: {
break :full_name try std.fmt.allocPrint(wasm.base.allocator, "{s}|{s}", .{ name, lib_name.? });
} else name;
@@ -1889,7 +1891,7 @@ pub fn addOrUpdateImport(
if (type_index) |ty_index| {
const gop = try wasm.imports.getOrPut(wasm.base.allocator, .{ .index = symbol_index, .file = null });
const module_name = if (lib_name) |l_name| blk: {
- break :blk mem.sliceTo(l_name, 0);
+ break :blk l_name;
} else wasm.host_name;
if (!gop.found_existing) {
gop.value_ptr.* = .{
@@ -2931,7 +2933,7 @@ pub fn getErrorTableSymbol(wasm: *Wasm) !u32 {
const atom_index = try wasm.createAtom();
const atom = wasm.getAtomPtr(atom_index);
- const slice_ty = Type.const_slice_u8_sentinel_0;
+ const slice_ty = Type.slice_const_u8_sentinel_0;
const mod = wasm.base.options.module.?;
atom.alignment = slice_ty.abiAlignment(mod);
const sym_index = atom.sym_index;
@@ -2988,7 +2990,7 @@ fn populateErrorNameTable(wasm: *Wasm) !void {
for (mod.error_name_list.items) |error_name| {
const len = @intCast(u32, error_name.len + 1); // names are 0-termianted
- const slice_ty = Type.const_slice_u8_sentinel_0;
+ const slice_ty = Type.slice_const_u8_sentinel_0;
const offset = @intCast(u32, atom.code.items.len);
// first we create the data for the slice of the name
try atom.code.appendNTimes(wasm.base.allocator, 0, 4); // ptr to name, will be relocated
@@ -3366,15 +3368,15 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
var decl_it = wasm.decls.iterator();
while (decl_it.next()) |entry| {
const decl = mod.declPtr(entry.key_ptr.*);
- if (decl.isExtern()) continue;
+ if (decl.isExtern(mod)) continue;
const atom_index = entry.value_ptr.*;
const atom = wasm.getAtomPtr(atom_index);
if (decl.ty.zigTypeTag(mod) == .Fn) {
try wasm.parseAtom(atom_index, .function);
- } else if (decl.getVariable()) |variable| {
- if (!variable.is_mutable) {
+ } else if (decl.getVariable(mod)) |variable| {
+ if (variable.is_const) {
try wasm.parseAtom(atom_index, .{ .data = .read_only });
- } else if (variable.init.isUndefDeep(mod)) {
+ } else if (variable.init.toValue().isUndefDeep(mod)) {
// for safe build modes, we store the atom in the data segment,
// whereas for unsafe build modes we store it in bss.
const is_initialized = wasm.base.options.optimize_mode == .Debug or