From 0134e5d2a1a5042b1485b7bb121870d2eaeb00b6 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Tue, 3 Oct 2023 14:55:18 +0200 Subject: codegen: separate getAnonDeclVAddr into lowerAnonDecl and the former Implement the stub for Elf. I believe that separating the concerns, namely, having an interface function that is responsible for signalling the linker to lower the anon decl only, and a separate function to obtain the decl's vaddr is preferable since it allows us to handle codegen errors in a simpler way. --- src/link.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/link.zig') diff --git a/src/link.zig b/src/link.zig index 3c4a6d18f4..1cc187c3f4 100644 --- a/src/link.zig +++ b/src/link.zig @@ -937,6 +937,22 @@ pub const File = struct { } } + pub const LowerResult = @import("codegen.zig").Result; + + pub fn lowerAnonDecl(base: *File, decl_val: InternPool.Index, src_loc: Module.SrcLoc) !LowerResult { + if (build_options.only_c) unreachable; + switch (base.tag) { + .coff => return @fieldParentPtr(Coff, "base", base).lowerAnonDecl(decl_val, src_loc), + .elf => return @fieldParentPtr(Elf, "base", base).lowerAnonDecl(decl_val, src_loc), + .macho => return @fieldParentPtr(MachO, "base", base).lowerAnonDecl(decl_val, src_loc), + .plan9 => return @fieldParentPtr(Plan9, "base", base).lowerAnonDecl(decl_val, src_loc), + .c => unreachable, + .wasm => return @fieldParentPtr(Wasm, "base", base).lowerAnonDecl(decl_val, src_loc), + .spirv => unreachable, + .nvptx => unreachable, + } + } + pub fn getAnonDeclVAddr(base: *File, decl_val: InternPool.Index, reloc_info: RelocInfo) !u64 { if (build_options.only_c) unreachable; switch (base.tag) { -- cgit v1.2.3