| ... | @@ -34,6 +34,7 @@ pub const File = struct { | ... | @@ -34,6 +34,7 @@ pub const File = struct { |
| 34 | | 34 | |
| 35 | pub const LinkBlock = union { | 35 | pub const LinkBlock = union { |
| 36 | elf: Elf.TextBlock, | 36 | elf: Elf.TextBlock, |
| | 37 | coff: void, // @TODO |
| 37 | macho: MachO.TextBlock, | 38 | macho: MachO.TextBlock, |
| 38 | c: void, | 39 | c: void, |
| 39 | wasm: void, | 40 | wasm: void, |
| ... | @@ -41,6 +42,7 @@ pub const File = struct { | ... | @@ -41,6 +42,7 @@ pub const File = struct { |
| 41 | | 42 | |
| 42 | pub const LinkFn = union { | 43 | pub const LinkFn = union { |
| 43 | elf: Elf.SrcFn, | 44 | elf: Elf.SrcFn, |
| | 45 | coff: void, // @TODO |
| 44 | macho: MachO.SrcFn, | 46 | macho: MachO.SrcFn, |
| 45 | c: void, | 47 | c: void, |
| 46 | wasm: ?Wasm.FnData, | 48 | wasm: ?Wasm.FnData, |
| ... | @@ -66,7 +68,7 @@ pub const File = struct { | ... | @@ -66,7 +68,7 @@ pub const File = struct { |
| 66 | pub fn openPath(allocator: *Allocator, dir: fs.Dir, sub_path: []const u8, options: Options) !*File { | 68 | pub fn openPath(allocator: *Allocator, dir: fs.Dir, sub_path: []const u8, options: Options) !*File { |
| 67 | switch (options.object_format) { | 69 | switch (options.object_format) { |
| 68 | .unknown => unreachable, | 70 | .unknown => unreachable, |
| 69 | .coff => return error.TODOImplementCoff, | 71 | .coff => return Coff.openPath(allocator, dir, sub_path, options), |
| 70 | .elf => return Elf.openPath(allocator, dir, sub_path, options), | 72 | .elf => return Elf.openPath(allocator, dir, sub_path, options), |
| 71 | .macho => return MachO.openPath(allocator, dir, sub_path, options), | 73 | .macho => return MachO.openPath(allocator, dir, sub_path, options), |
| 72 | .wasm => return Wasm.openPath(allocator, dir, sub_path, options), | 74 | .wasm => return Wasm.openPath(allocator, dir, sub_path, options), |
| ... | @@ -85,7 +87,7 @@ pub const File = struct { | ... | @@ -85,7 +87,7 @@ pub const File = struct { |
| 85 | | 87 | |
| 86 | pub fn makeWritable(base: *File, dir: fs.Dir, sub_path: []const u8) !void { | 88 | pub fn makeWritable(base: *File, dir: fs.Dir, sub_path: []const u8) !void { |
| 87 | switch (base.tag) { | 89 | switch (base.tag) { |
| 88 | .elf, .macho => { | 90 | .coff, .elf, .macho => { |
| 89 | if (base.file != null) return; | 91 | if (base.file != null) return; |
| 90 | base.file = try dir.createFile(sub_path, .{ | 92 | base.file = try dir.createFile(sub_path, .{ |
| 91 | .truncate = false, | 93 | .truncate = false, |
| ... | @@ -112,6 +114,7 @@ pub const File = struct { | ... | @@ -112,6 +114,7 @@ pub const File = struct { |
| 112 | /// after allocateDeclIndexes for any given Decl. | 114 | /// after allocateDeclIndexes for any given Decl. |
| 113 | pub fn updateDecl(base: *File, module: *Module, decl: *Module.Decl) !void { | 115 | pub fn updateDecl(base: *File, module: *Module, decl: *Module.Decl) !void { |
| 114 | switch (base.tag) { | 116 | switch (base.tag) { |
| | 117 | .coff => return @fieldParentPtr(Coff, "base", base).updateDecl(module, decl), |
| 115 | .elf => return @fieldParentPtr(Elf, "base", base).updateDecl(module, decl), | 118 | .elf => return @fieldParentPtr(Elf, "base", base).updateDecl(module, decl), |
| 116 | .macho => return @fieldParentPtr(MachO, "base", base).updateDecl(module, decl), | 119 | .macho => return @fieldParentPtr(MachO, "base", base).updateDecl(module, decl), |
| 117 | .c => return @fieldParentPtr(C, "base", base).updateDecl(module, decl), | 120 | .c => return @fieldParentPtr(C, "base", base).updateDecl(module, decl), |
| ... | @@ -121,6 +124,7 @@ pub const File = struct { | ... | @@ -121,6 +124,7 @@ pub const File = struct { |
| 121 | | 124 | |
| 122 | pub fn updateDeclLineNumber(base: *File, module: *Module, decl: *Module.Decl) !void { | 125 | pub fn updateDeclLineNumber(base: *File, module: *Module, decl: *Module.Decl) !void { |
| 123 | switch (base.tag) { | 126 | switch (base.tag) { |
| | 127 | .coff => return @fieldParentPtr(Coff, "base", base).updateDeclLineNumber(module, decl), |
| 124 | .elf => return @fieldParentPtr(Elf, "base", base).updateDeclLineNumber(module, decl), | 128 | .elf => return @fieldParentPtr(Elf, "base", base).updateDeclLineNumber(module, decl), |
| 125 | .macho => return @fieldParentPtr(MachO, "base", base).updateDeclLineNumber(module, decl), | 129 | .macho => return @fieldParentPtr(MachO, "base", base).updateDeclLineNumber(module, decl), |
| 126 | .c, .wasm => {}, | 130 | .c, .wasm => {}, |
| ... | @@ -131,6 +135,7 @@ pub const File = struct { | ... | @@ -131,6 +135,7 @@ pub const File = struct { |
| 131 | /// any given Decl. | 135 | /// any given Decl. |
| 132 | pub fn allocateDeclIndexes(base: *File, decl: *Module.Decl) !void { | 136 | pub fn allocateDeclIndexes(base: *File, decl: *Module.Decl) !void { |
| 133 | switch (base.tag) { | 137 | switch (base.tag) { |
| | 138 | .coff => return @fieldParentPtr(Coff, "base", base).allocateDeclIndexes(decl), |
| 134 | .elf => return @fieldParentPtr(Elf, "base", base).allocateDeclIndexes(decl), | 139 | .elf => return @fieldParentPtr(Elf, "base", base).allocateDeclIndexes(decl), |
| 135 | .macho => return @fieldParentPtr(MachO, "base", base).allocateDeclIndexes(decl), | 140 | .macho => return @fieldParentPtr(MachO, "base", base).allocateDeclIndexes(decl), |
| 136 | .c, .wasm => {}, | 141 | .c, .wasm => {}, |
| ... | @@ -140,6 +145,7 @@ pub const File = struct { | ... | @@ -140,6 +145,7 @@ pub const File = struct { |
| 140 | pub fn deinit(base: *File) void { | 145 | pub fn deinit(base: *File) void { |
| 141 | if (base.file) |f| f.close(); | 146 | if (base.file) |f| f.close(); |
| 142 | switch (base.tag) { | 147 | switch (base.tag) { |
| | 148 | .coff => @fieldParentPtr(Coff, "base", base).deinit(), |
| 143 | .elf => @fieldParentPtr(Elf, "base", base).deinit(), | 149 | .elf => @fieldParentPtr(Elf, "base", base).deinit(), |
| 144 | .macho => @fieldParentPtr(MachO, "base", base).deinit(), | 150 | .macho => @fieldParentPtr(MachO, "base", base).deinit(), |
| 145 | .c => @fieldParentPtr(C, "base", base).deinit(), | 151 | .c => @fieldParentPtr(C, "base", base).deinit(), |
| ... | @@ -149,6 +155,11 @@ pub const File = struct { | ... | @@ -149,6 +155,11 @@ pub const File = struct { |
| 149 | | 155 | |
| 150 | pub fn destroy(base: *File) void { | 156 | pub fn destroy(base: *File) void { |
| 151 | switch (base.tag) { | 157 | switch (base.tag) { |
| | 158 | .coff => { |
| | 159 | const parent = @fieldParentPtr(Coff, "base", base); |
| | 160 | parent.deinit(); |
| | 161 | base.allocator.destroy(parent); |
| | 162 | }, |
| 152 | .elf => { | 163 | .elf => { |
| 153 | const parent = @fieldParentPtr(Elf, "base", base); | 164 | const parent = @fieldParentPtr(Elf, "base", base); |
| 154 | parent.deinit(); | 165 | parent.deinit(); |
| ... | @@ -177,6 +188,7 @@ pub const File = struct { | ... | @@ -177,6 +188,7 @@ pub const File = struct { |
| 177 | defer tracy.end(); | 188 | defer tracy.end(); |
| 178 | | 189 | |
| 179 | try switch (base.tag) { | 190 | try switch (base.tag) { |
| | 191 | .coff => @fieldParentPtr(Coff, "base", base).flush(module), |
| 180 | .elf => @fieldParentPtr(Elf, "base", base).flush(module), | 192 | .elf => @fieldParentPtr(Elf, "base", base).flush(module), |
| 181 | .macho => @fieldParentPtr(MachO, "base", base).flush(module), | 193 | .macho => @fieldParentPtr(MachO, "base", base).flush(module), |
| 182 | .c => @fieldParentPtr(C, "base", base).flush(module), | 194 | .c => @fieldParentPtr(C, "base", base).flush(module), |
| ... | @@ -186,6 +198,7 @@ pub const File = struct { | ... | @@ -186,6 +198,7 @@ pub const File = struct { |
| 186 | | 198 | |
| 187 | pub fn freeDecl(base: *File, decl: *Module.Decl) void { | 199 | pub fn freeDecl(base: *File, decl: *Module.Decl) void { |
| 188 | switch (base.tag) { | 200 | switch (base.tag) { |
| | 201 | .coff => @fieldParentPtr(Coff, "base", base).freeDecl(decl), |
| 189 | .elf => @fieldParentPtr(Elf, "base", base).freeDecl(decl), | 202 | .elf => @fieldParentPtr(Elf, "base", base).freeDecl(decl), |
| 190 | .macho => @fieldParentPtr(MachO, "base", base).freeDecl(decl), | 203 | .macho => @fieldParentPtr(MachO, "base", base).freeDecl(decl), |
| 191 | .c => unreachable, | 204 | .c => unreachable, |
| ... | @@ -195,6 +208,7 @@ pub const File = struct { | ... | @@ -195,6 +208,7 @@ pub const File = struct { |
| 195 | | 208 | |
| 196 | pub fn errorFlags(base: *File) ErrorFlags { | 209 | pub fn errorFlags(base: *File) ErrorFlags { |
| 197 | return switch (base.tag) { | 210 | return switch (base.tag) { |
| | 211 | .coff => @fieldParentPtr(Coff, "base", base).error_flags, |
| 198 | .elf => @fieldParentPtr(Elf, "base", base).error_flags, | 212 | .elf => @fieldParentPtr(Elf, "base", base).error_flags, |
| 199 | .macho => @fieldParentPtr(MachO, "base", base).error_flags, | 213 | .macho => @fieldParentPtr(MachO, "base", base).error_flags, |
| 200 | .c => return .{ .no_entry_point_found = false }, | 214 | .c => return .{ .no_entry_point_found = false }, |
| ... | @@ -211,6 +225,7 @@ pub const File = struct { | ... | @@ -211,6 +225,7 @@ pub const File = struct { |
| 211 | exports: []const *Module.Export, | 225 | exports: []const *Module.Export, |
| 212 | ) !void { | 226 | ) !void { |
| 213 | switch (base.tag) { | 227 | switch (base.tag) { |
| | 228 | .coff => return @fieldParentPtr(Coff, "base", base).updateDeclExports(module, decl, exports), |
| 214 | .elf => return @fieldParentPtr(Elf, "base", base).updateDeclExports(module, decl, exports), | 229 | .elf => return @fieldParentPtr(Elf, "base", base).updateDeclExports(module, decl, exports), |
| 215 | .macho => return @fieldParentPtr(MachO, "base", base).updateDeclExports(module, decl, exports), | 230 | .macho => return @fieldParentPtr(MachO, "base", base).updateDeclExports(module, decl, exports), |
| 216 | .c => return {}, | 231 | .c => return {}, |
| ... | @@ -220,6 +235,7 @@ pub const File = struct { | ... | @@ -220,6 +235,7 @@ pub const File = struct { |
| 220 | | 235 | |
| 221 | pub fn getDeclVAddr(base: *File, decl: *const Module.Decl) u64 { | 236 | pub fn getDeclVAddr(base: *File, decl: *const Module.Decl) u64 { |
| 222 | switch (base.tag) { | 237 | switch (base.tag) { |
| | 238 | .coff => return @fieldParentPtr(Coff, "base", base).getDeclVAddr(decl), |
| 223 | .elf => return @fieldParentPtr(Elf, "base", base).getDeclVAddr(decl), | 239 | .elf => return @fieldParentPtr(Elf, "base", base).getDeclVAddr(decl), |
| 224 | .macho => return @fieldParentPtr(MachO, "base", base).getDeclVAddr(decl), | 240 | .macho => return @fieldParentPtr(MachO, "base", base).getDeclVAddr(decl), |
| 225 | .c => unreachable, | 241 | .c => unreachable, |
| ... | @@ -228,6 +244,7 @@ pub const File = struct { | ... | @@ -228,6 +244,7 @@ pub const File = struct { |
| 228 | } | 244 | } |
| 229 | | 245 | |
| 230 | pub const Tag = enum { | 246 | pub const Tag = enum { |
| | 247 | coff, |
| 231 | elf, | 248 | elf, |
| 232 | macho, | 249 | macho, |
| 233 | c, | 250 | c, |
| ... | @@ -239,6 +256,7 @@ pub const File = struct { | ... | @@ -239,6 +256,7 @@ pub const File = struct { |
| 239 | }; | 256 | }; |
| 240 | | 257 | |
| 241 | pub const C = @import("link/C.zig"); | 258 | pub const C = @import("link/C.zig"); |
| | 259 | pub const Coff = @import("link/Coff.zig"); |
| 242 | pub const Elf = @import("link/Elf.zig"); | 260 | pub const Elf = @import("link/Elf.zig"); |
| 243 | pub const MachO = @import("link/MachO.zig"); | 261 | pub const MachO = @import("link/MachO.zig"); |
| 244 | pub const Wasm = @import("link/Wasm.zig"); | 262 | pub const Wasm = @import("link/Wasm.zig"); |