aboutsummaryrefslogtreecommitdiff
path: root/src/link.zig
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2022-05-21 20:44:01 +0200
committerLuuk de Gram <luuk@degram.dev>2022-06-24 08:12:17 +0200
commit8d03e4fc6b361e6cf96865acc05820556ae33863 (patch)
tree1f6d431c2f2aef13df992f3d571f6291c66f5e7e /src/link.zig
parent359b61aec3494197aaca336dabaa39d0515706ff (diff)
downloadzig-8d03e4fc6b361e6cf96865acc05820556ae33863.tar.gz
zig-8d03e4fc6b361e6cf96865acc05820556ae33863.zip
link: Implement API to get global symbol index
Diffstat (limited to 'src/link.zig')
-rw-r--r--src/link.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/link.zig b/src/link.zig
index ad1fc417f3..8bad44aa21 100644
--- a/src/link.zig
+++ b/src/link.zig
@@ -438,6 +438,24 @@ pub const File = struct {
}
}
+ /// Called from within CodeGen to retrieve the symbol index of a global symbol.
+ /// If no symbol exists yet with this name, a new one will be created instead.
+ pub fn getGlobalSymbol(base: *File, name: []const u8) UpdateDeclError!u32 {
+ log.debug("getGlobalSymbol '{s}'", .{name});
+ switch (base.tag) {
+ // zig fmt: off
+ .coff => unreachable,
+ .elf => unreachable,
+ .macho => unreachable,
+ .plan9 => unreachable,
+ .spirv => unreachable,
+ .c => unreachable,
+ .wasm => return @fieldParentPtr(Wasm, "base", base).getGlobalSymbol(name),
+ .nvptx => unreachable,
+ // zig fmt: on
+ }
+ }
+
/// May be called before or after updateDeclExports but must be called
/// after allocateDeclIndexes for any given Decl.
pub fn updateDecl(base: *File, module: *Module, decl_index: Module.Decl.Index) UpdateDeclError!void {