aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacob gw <jacoblevgw@gmail.com>2021-06-01 16:07:08 -0400
committerAndrew Kelley <andrew@ziglang.org>2021-07-08 14:10:49 -0700
commit34c21affa2429cf07042eb2f225ee59194998802 (patch)
treeb75283e0215fa3e5de31c1995e71a56f35942c28 /src
parent1f0b77b3b88112ef458f62c23df72003c843e7cc (diff)
downloadzig-34c21affa2429cf07042eb2f225ee59194998802.tar.gz
zig-34c21affa2429cf07042eb2f225ee59194998802.zip
initial plan9 boilerplate
The code now compiles and fails with Plan9ObjectFormatUnimplemented
Diffstat (limited to 'src')
-rw-r--r--src/Module.zig8
-rw-r--r--src/codegen/llvm.zig1
-rw-r--r--src/link.zig25
-rw-r--r--src/link/Plan9.zig65
-rw-r--r--src/target.zig2
-rw-r--r--src/type.zig1
6 files changed, 99 insertions, 3 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 8ae184a377..e95d6bf245 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -3437,6 +3437,9 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) InnerError!vo
// in `Decl` to notice that the line number did not change.
mod.comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl });
},
+ .plan9 => {
+ // TODO implement for plan9
+ },
.c, .wasm, .spirv => {},
}
}
@@ -3514,6 +3517,7 @@ pub fn clearDecl(
.coff => .{ .coff = link.File.Coff.TextBlock.empty },
.elf => .{ .elf = link.File.Elf.TextBlock.empty },
.macho => .{ .macho = link.File.MachO.TextBlock.empty },
+ .plan9 => @panic("plan9 link"),
.c => .{ .c = link.File.C.DeclBlock.empty },
.wasm => .{ .wasm = link.File.Wasm.DeclBlock.empty },
.spirv => .{ .spirv = {} },
@@ -3522,6 +3526,7 @@ pub fn clearDecl(
.coff => .{ .coff = {} },
.elf => .{ .elf = link.File.Elf.SrcFn.empty },
.macho => .{ .macho = link.File.MachO.SrcFn.empty },
+ .plan9 => @panic("plan9 fn_link"),
.c => .{ .c = link.File.C.FnBlock.empty },
.wasm => .{ .wasm = link.File.Wasm.FnData.empty },
.spirv => .{ .spirv = .{} },
@@ -3689,6 +3694,7 @@ fn allocateNewDecl(mod: *Module, namespace: *Scope.Namespace, src_node: ast.Node
.coff => .{ .coff = link.File.Coff.TextBlock.empty },
.elf => .{ .elf = link.File.Elf.TextBlock.empty },
.macho => .{ .macho = link.File.MachO.TextBlock.empty },
+ .plan9 => @panic("PLan9 export"),
.c => .{ .c = link.File.C.DeclBlock.empty },
.wasm => .{ .wasm = link.File.Wasm.DeclBlock.empty },
.spirv => .{ .spirv = {} },
@@ -3697,6 +3703,7 @@ fn allocateNewDecl(mod: *Module, namespace: *Scope.Namespace, src_node: ast.Node
.coff => .{ .coff = {} },
.elf => .{ .elf = link.File.Elf.SrcFn.empty },
.macho => .{ .macho = link.File.MachO.SrcFn.empty },
+ .plan9 => .{ .plan9 = link.File.Plan9.SrcFn.empty },
.c => .{ .c = link.File.C.FnBlock.empty },
.wasm => .{ .wasm = link.File.Wasm.FnData.empty },
.spirv => .{ .spirv = .{} },
@@ -3766,6 +3773,7 @@ pub fn analyzeExport(
.coff => .{ .coff = {} },
.elf => .{ .elf = link.File.Elf.Export{} },
.macho => .{ .macho = link.File.MachO.Export{} },
+ .plan9 => @panic("plan9 link"),
.c => .{ .c = {} },
.wasm => .{ .wasm = {} },
.spirv => .{ .spirv = {} },
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 2baedf8c9d..b8f96891f4 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -117,6 +117,7 @@ pub fn targetTriple(allocator: *Allocator, target: std.Target) ![:0]u8 {
.opencl => return error.LLVMBackendDoesNotSupportOpenCL,
.glsl450 => return error.LLVMBackendDoesNotSupportGLSL450,
.vulkan => return error.LLVMBackendDoesNotSupportVulkan,
+ .plan9 => return error.LLVMBackendDoesNotSupportPlan9,
.other => "unknown",
};
diff --git a/src/link.zig b/src/link.zig
index 9c1be16b9c..e5eb45ec91 100644
--- a/src/link.zig
+++ b/src/link.zig
@@ -150,6 +150,7 @@ pub const File = struct {
elf: Elf.SrcFn,
coff: Coff.SrcFn,
macho: MachO.SrcFn,
+ plan9: Plan9.SrcFn,
c: C.FnBlock,
wasm: Wasm.FnData,
spirv: SpirV.FnData,
@@ -159,6 +160,7 @@ pub const File = struct {
elf: Elf.Export,
coff: void,
macho: MachO.Export,
+ plan9: Plan9.Export,
c: void,
wasm: void,
spirv: void,
@@ -189,6 +191,7 @@ pub const File = struct {
.elf => &(try Elf.createEmpty(allocator, options)).base,
.macho => &(try MachO.createEmpty(allocator, options)).base,
.wasm => &(try Wasm.createEmpty(allocator, options)).base,
+ .plan9 => return &(try Plan9.createEmpty(allocator, options)).base,
.c => unreachable, // Reported error earlier.
.spirv => &(try SpirV.createEmpty(allocator, options)).base,
.hex => return error.HexObjectFormatUnimplemented,
@@ -209,6 +212,7 @@ pub const File = struct {
.spirv => &(try SpirV.createEmpty(allocator, options)).base,
.hex => return error.HexObjectFormatUnimplemented,
.raw => return error.RawObjectFormatUnimplemented,
+ .plan9 => return error.Plan9ObjectFormatUnimplemented,
};
}
// Open a temporary object file, not the final output file because we want to link with LLD.
@@ -225,6 +229,7 @@ pub const File = struct {
.spirv => &(try SpirV.openPath(allocator, sub_path, options)).base,
.hex => return error.HexObjectFormatUnimplemented,
.raw => return error.RawObjectFormatUnimplemented,
+ .plan9 => return error.Plan9ObjectFormatUnimplemented,
};
if (use_lld) {
@@ -243,7 +248,7 @@ pub const File = struct {
pub fn makeWritable(base: *File) !void {
switch (base.tag) {
- .coff, .elf, .macho => {
+ .coff, .elf, .macho, .plan9 => {
if (base.file != null) return;
const emit = base.options.emit orelse return;
base.file = try emit.directory.handle.createFile(emit.sub_path, .{
@@ -288,7 +293,7 @@ pub const File = struct {
f.close();
base.file = null;
},
- .coff, .elf => if (base.file) |f| {
+ .coff, .elf, .plan9 => if (base.file) |f| {
if (base.intermediary_basename != null) {
// The file we have open is not the final file that we want to
// make executable, so we don't have to close it.
@@ -313,6 +318,7 @@ pub const File = struct {
.c => return @fieldParentPtr(C, "base", base).updateDecl(module, decl),
.wasm => return @fieldParentPtr(Wasm, "base", base).updateDecl(module, decl),
.spirv => return @fieldParentPtr(SpirV, "base", base).updateDecl(module, decl),
+ .plan9 => return @fieldParentPtr(Plan9, "base", base).updateDecl(module, decl),
}
}
@@ -326,6 +332,7 @@ pub const File = struct {
.elf => return @fieldParentPtr(Elf, "base", base).updateDeclLineNumber(module, decl),
.macho => return @fieldParentPtr(MachO, "base", base).updateDeclLineNumber(module, decl),
.c => return @fieldParentPtr(C, "base", base).updateDeclLineNumber(module, decl),
+ .plan9 => @panic("PLAN 9 DEBUG INFO"),
.wasm, .spirv => {},
}
}
@@ -340,6 +347,7 @@ pub const File = struct {
.macho => return @fieldParentPtr(MachO, "base", base).allocateDeclIndexes(decl),
.c => return @fieldParentPtr(C, "base", base).allocateDeclIndexes(decl),
.wasm => return @fieldParentPtr(Wasm, "base", base).allocateDeclIndexes(decl),
+ .plan9 => return @fieldParentPtr(Plan9, "base", base).allocateDeclIndexes(decl),
.spirv => {},
}
}
@@ -393,6 +401,11 @@ pub const File = struct {
parent.deinit();
base.allocator.destroy(parent);
},
+ .plan9 => {
+ const parent = @fieldParentPtr(Plan9, "base", base);
+ parent.deinit();
+ base.allocator.destroy(parent);
+ },
}
}
@@ -425,6 +438,7 @@ pub const File = struct {
.c => return @fieldParentPtr(C, "base", base).flush(comp),
.wasm => return @fieldParentPtr(Wasm, "base", base).flush(comp),
.spirv => return @fieldParentPtr(SpirV, "base", base).flush(comp),
+ .plan9 => return @fieldParentPtr(Plan9, "base", base).flush(comp),
}
}
@@ -438,6 +452,7 @@ pub const File = struct {
.c => return @fieldParentPtr(C, "base", base).flushModule(comp),
.wasm => return @fieldParentPtr(Wasm, "base", base).flushModule(comp),
.spirv => return @fieldParentPtr(SpirV, "base", base).flushModule(comp),
+ .plan9 => return @fieldParentPtr(Plan9, "base", base).flushModule(comp),
}
}
@@ -451,6 +466,7 @@ pub const File = struct {
.c => @fieldParentPtr(C, "base", base).freeDecl(decl),
.wasm => @fieldParentPtr(Wasm, "base", base).freeDecl(decl),
.spirv => @fieldParentPtr(SpirV, "base", base).freeDecl(decl),
+ .plan9 => @fieldParentPtr(Plan9, "base", base).freeDecl(decl),
}
}
@@ -459,6 +475,7 @@ pub const File = struct {
.coff => return @fieldParentPtr(Coff, "base", base).error_flags,
.elf => return @fieldParentPtr(Elf, "base", base).error_flags,
.macho => return @fieldParentPtr(MachO, "base", base).error_flags,
+ .plan9 => return @fieldParentPtr(Plan9, "base", base).error_flags,
.c => return .{ .no_entry_point_found = false },
.wasm, .spirv => return ErrorFlags{},
}
@@ -481,6 +498,7 @@ pub const File = struct {
.c => return @fieldParentPtr(C, "base", base).updateDeclExports(module, decl, exports),
.wasm => return @fieldParentPtr(Wasm, "base", base).updateDeclExports(module, decl, exports),
.spirv => return @fieldParentPtr(SpirV, "base", base).updateDeclExports(module, decl, exports),
+ .plan9 => return @fieldParentPtr(Plan9, "base", base).updateDeclExports(module, decl, exports),
}
}
@@ -489,6 +507,7 @@ pub const File = struct {
.coff => return @fieldParentPtr(Coff, "base", base).getDeclVAddr(decl),
.elf => return @fieldParentPtr(Elf, "base", base).getDeclVAddr(decl),
.macho => return @fieldParentPtr(MachO, "base", base).getDeclVAddr(decl),
+ .plan9 => @panic("GET VADDR"),
.c => unreachable,
.wasm => unreachable,
.spirv => unreachable,
@@ -633,6 +652,7 @@ pub const File = struct {
c,
wasm,
spirv,
+ plan9,
};
pub const ErrorFlags = struct {
@@ -641,6 +661,7 @@ pub const File = struct {
pub const C = @import("link/C.zig");
pub const Coff = @import("link/Coff.zig");
+ pub const Plan9 = @import("link/Plan9.zig");
pub const Elf = @import("link/Elf.zig");
pub const MachO = @import("link/MachO.zig");
pub const SpirV = @import("link/SpirV.zig");
diff --git a/src/link/Plan9.zig b/src/link/Plan9.zig
new file mode 100644
index 0000000000..4459288f58
--- /dev/null
+++ b/src/link/Plan9.zig
@@ -0,0 +1,65 @@
+const Plan9 = @This();
+
+const std = @import("std");
+const link = @import("../link.zig");
+const Module = @import("../Module.zig");
+const Compilation = @import("../Compilation.zig");
+const File = link.File;
+const Allocator = std.mem.Allocator;
+
+const log = std.log.scoped(.link);
+
+base: link.File,
+error_flags: File.ErrorFlags = File.ErrorFlags{},
+
+pub const SrcFn = struct {
+ /// Offset from the beginning of the Debug Line Program header that contains this function.
+ off: u32,
+ /// Size of the line number program component belonging to this function, not
+ /// including padding.
+ len: u32,
+
+ /// Points to the previous and next neighbors, based on the offset from .debug_line.
+ /// This can be used to find, for example, the capacity of this `SrcFn`.
+ prev: ?*SrcFn,
+ next: ?*SrcFn,
+
+ pub const empty: SrcFn = .{
+ .off = 0,
+ .len = 0,
+ .prev = null,
+ .next = null,
+ };
+};
+
+pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Plan9 {
+ const self = try gpa.create(Plan9);
+ self.* = .{
+ .base = .{
+ .tag = .plan9,
+ .options = options,
+ .allocator = gpa,
+ .file = null,
+ },
+ };
+ return self;
+}
+
+pub fn updateDecl(self: *Plan9, module: *Module, decl: *Module.Decl) !void {}
+
+pub fn allocateDeclIndexes(self: *Plan9, decl: *Module.Decl) !void {}
+
+pub fn flush(self: *Plan9, comp: *Compilation) !void {}
+pub fn flushModule(self: *Plan9, comp: *Compilation) !void {}
+pub fn freeDecl(self: *Plan9, decl: *Module.Decl) void {}
+pub fn updateDeclExports(
+ self: *Plan9,
+ module: *Module,
+ decl: *Module.Decl,
+ exports: []const *Module.Export,
+) !void {}
+pub fn deinit(self: *Plan9) void {}
+
+pub const Export = struct {
+ sym_index: ?u32 = null,
+};
diff --git a/src/target.zig b/src/target.zig
index a61bbe7f09..06483d68ff 100644
--- a/src/target.zig
+++ b/src/target.zig
@@ -244,7 +244,7 @@ pub fn supportsStackProbing(target: std.Target) bool {
pub fn osToLLVM(os_tag: std.Target.Os.Tag) llvm.OSType {
return switch (os_tag) {
- .freestanding, .other, .opencl, .glsl450, .vulkan => .UnknownOS,
+ .freestanding, .other, .opencl, .glsl450, .vulkan, .plan9 => .UnknownOS,
.windows, .uefi => .Win32,
.ananas => .Ananas,
.cloudabi => .CloudABI,
diff --git a/src/type.zig b/src/type.zig
index 34b7dc178b..8ded2ee906 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -3290,6 +3290,7 @@ pub const CType = enum {
.openbsd,
.wasi,
.emscripten,
+ .plan9,
=> switch (self) {
.short,
.ushort,