authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-23 20:15:59+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-23 21:57:24+02:00
logd40f204ec05d5913046c17ae46bba3b14cdaf384
tree15df55915afb4a7dad4ee55ab39fa911ba4e658e
parent133579d7c05a92e33bd8a4cfaf5c460f48150de7
signaturelock-open Commit is signed but in an unrecognized format.

self hosted compiler: small miscellaneous fixes


10 files changed, 62 insertions(+), 53 deletions(-)

src-self-hosted/codegen.zig+5-4
......@@ -6,6 +6,7 @@ const ir = @import("ir.zig");
66const Value = @import("value.zig").Value;
77const Type = @import("type.zig").Type;
88const Scope = @import("scope.zig").Scope;
9const util = @import("util.zig");
910const event = std.event;
1011const assert = std.debug.assert;
1112const DW = std.dwarf;
......@@ -30,11 +31,11 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
3031 llvm.SetTarget(module, comp.llvm_triple.ptr());
3132 llvm.SetDataLayout(module, comp.target_layout_str);
3233
33 // if (comp.target.getObjectFormat() == .coff) {
34 // llvm.AddModuleCodeViewFlag(module);
35 // } else {
34 if (util.getObjectFormat(comp.target) == .coff) {
35 llvm.AddModuleCodeViewFlag(module);
36 } else {
3637 llvm.AddModuleDebugInfoFlag(module);
37 // }
38 }
3839
3940 const builder = llvm.CreateBuilderInContext(context) orelse return error.OutOfMemory;
4041 defer llvm.DisposeBuilder(builder);
src-self-hosted/compilation.zig-1
......@@ -858,7 +858,6 @@ pub const Compilation = struct {
858858 defer locked_table.release();
859859
860860 var decl_group = event.Group(BuildError!void).init(self.gpa());
861 defer decl_group.wait() catch {};
862861
863862 try self.rebuildChangedDecls(
864863 &decl_group,
src-self-hosted/libc_installation.zig+1-1
......@@ -146,7 +146,7 @@ pub const LibCInstallation = struct {
146146 pub async fn findNative(self: *LibCInstallation, allocator: *Allocator) !void {
147147 self.initEmpty();
148148 var group = event.Group(FindError!void).init(allocator);
149 // errdefer group.deinit();
149 errdefer group.wait() catch {};
150150 var windows_sdk: ?*c.ZigWindowsSDK = null;
151151 errdefer if (windows_sdk) |sdk| c.zig_free_windows_sdk(@ptrCast(?[*]c.ZigWindowsSDK, sdk));
152152
src-self-hosted/link.zig+8-9
......@@ -78,7 +78,7 @@ pub async fn link(comp: *Compilation) !void {
7878 std.debug.warn("\n");
7979 }
8080
81 const extern_ofmt = toExternObjectFormatType(.elf); //comp.target.getObjectFormat());
81 const extern_ofmt = toExternObjectFormatType(util.getObjectFormat(comp.target));
8282 const args_slice = ctx.args.toSlice();
8383
8484 {
......@@ -130,14 +130,13 @@ fn toExternObjectFormatType(ofmt: ObjectFormat) c.ZigLLVM_ObjectFormatType {
130130}
131131
132132fn constructLinkerArgs(ctx: *Context) !void {
133 return constructLinkerArgsElf(ctx);
134 // switch (ctx.comp.target.getObjectFormat()) {
135 // .unknown => unreachable,
136 // .coff => return constructLinkerArgsCoff(ctx),
137 // .elf => return constructLinkerArgsElf(ctx),
138 // .macho => return constructLinkerArgsMachO(ctx),
139 // .wasm => return constructLinkerArgsWasm(ctx),
140 // }
133 switch (util.getObjectFormat(ctx.comp.target)) {
134 .unknown => unreachable,
135 .coff => return constructLinkerArgsCoff(ctx),
136 .elf => return constructLinkerArgsElf(ctx),
137 .macho => return constructLinkerArgsMachO(ctx),
138 .wasm => return constructLinkerArgsWasm(ctx),
139 }
141140}
142141
143142fn constructLinkerArgsElf(ctx: *Context) !void {
src-self-hosted/llvm.zig+1-2
......@@ -1,6 +1,5 @@
11const c = @import("c.zig");
2const std = @import("std");
3const assert = std.debug.assert;
2const assert = @import("std").debug.assert;
43
54// we wrap the c module for 3 reasons:
65// 1. to avoid accidentally calling the non-thread-safe functions
src-self-hosted/main.zig+21-21
......@@ -260,47 +260,47 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
260260 process.exit(0);
261261 }
262262
263 const build_mode = blk: {
263 const build_mode: std.builtin.Mode = blk: {
264264 if (flags.single("mode")) |mode_flag| {
265265 if (mem.eql(u8, mode_flag, "debug")) {
266 break :blk std.builtin.Mode.Debug;
266 break :blk .Debug;
267267 } else if (mem.eql(u8, mode_flag, "release-fast")) {
268 break :blk std.builtin.Mode.ReleaseFast;
268 break :blk .ReleaseFast;
269269 } else if (mem.eql(u8, mode_flag, "release-safe")) {
270 break :blk std.builtin.Mode.ReleaseSafe;
270 break :blk .ReleaseSafe;
271271 } else if (mem.eql(u8, mode_flag, "release-small")) {
272 break :blk std.builtin.Mode.ReleaseSmall;
272 break :blk .ReleaseSmall;
273273 } else unreachable;
274274 } else {
275 break :blk std.builtin.Mode.Debug;
275 break :blk .Debug;
276276 }
277277 };
278278
279 const color = blk: {
279 const color: errmsg.Color = blk: {
280280 if (flags.single("color")) |color_flag| {
281281 if (mem.eql(u8, color_flag, "auto")) {
282 break :blk errmsg.Color.Auto;
282 break :blk .Auto;
283283 } else if (mem.eql(u8, color_flag, "on")) {
284 break :blk errmsg.Color.On;
284 break :blk .On;
285285 } else if (mem.eql(u8, color_flag, "off")) {
286 break :blk errmsg.Color.Off;
286 break :blk .Off;
287287 } else unreachable;
288288 } else {
289 break :blk errmsg.Color.Auto;
289 break :blk .Auto;
290290 }
291291 };
292292
293 const emit_type = blk: {
293 const emit_type: Compilation.Emit = blk: {
294294 if (flags.single("emit")) |emit_flag| {
295295 if (mem.eql(u8, emit_flag, "asm")) {
296 break :blk Compilation.Emit.Assembly;
296 break :blk .Assembly;
297297 } else if (mem.eql(u8, emit_flag, "bin")) {
298 break :blk Compilation.Emit.Binary;
298 break :blk .Binary;
299299 } else if (mem.eql(u8, emit_flag, "llvm-ir")) {
300 break :blk Compilation.Emit.LlvmIr;
300 break :blk .LlvmIr;
301301 } else unreachable;
302302 } else {
303 break :blk Compilation.Emit.Binary;
303 break :blk .Binary;
304304 }
305305 };
306306
......@@ -587,17 +587,17 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
587587 process.exit(0);
588588 }
589589
590 const color = blk: {
590 const color: errmsg.Color = blk: {
591591 if (flags.single("color")) |color_flag| {
592592 if (mem.eql(u8, color_flag, "auto")) {
593 break :blk errmsg.Color.Auto;
593 break :blk .Auto;
594594 } else if (mem.eql(u8, color_flag, "on")) {
595 break :blk errmsg.Color.On;
595 break :blk .On;
596596 } else if (mem.eql(u8, color_flag, "off")) {
597 break :blk errmsg.Color.Off;
597 break :blk .Off;
598598 } else unreachable;
599599 } else {
600 break :blk errmsg.Color.Auto;
600 break :blk .Auto;
601601 }
602602 };
603603
src-self-hosted/test.zig+6-10
......@@ -16,7 +16,7 @@ test "stage2" {
1616 try @import("../test/stage2/compile_errors.zig").addCases(&ctx);
1717 try @import("../test/stage2/compare_output.zig").addCases(&ctx);
1818
19 try ctx.run();
19 async ctx.run();
2020}
2121
2222const file1 = "1.zig";
......@@ -44,7 +44,7 @@ pub const TestContext = struct {
4444 errdefer self.zig_compiler.deinit();
4545
4646 self.group = std.event.Group(anyerror!void).init(allocator);
47 errdefer self.group.wait();
47 errdefer self.group.wait() catch {};
4848
4949 self.zig_lib_dir = try introspect.resolveZigLibDir(allocator);
5050 errdefer allocator.free(self.zig_lib_dir);
......@@ -59,14 +59,10 @@ pub const TestContext = struct {
5959 self.zig_compiler.deinit();
6060 }
6161
62 fn run(self: *TestContext) !void {
63 const handle = try std.event.Loop.instance.?.call(waitForGroup, self);
64 await handle;
65 return self.any_err;
66 }
67
68 async fn waitForGroup(self: *TestContext) void {
62 fn run(self: *TestContext) void {
63 std.event.Loop.instance.?.startCpuBoundOperation();
6964 self.any_err = self.group.wait();
65 return self.any_err;
7066 }
7167
7268 fn testCompileError(
......@@ -173,7 +169,7 @@ pub const TestContext = struct {
173169 },
174170 Compilation.Event.Error => |err| return err,
175171 Compilation.Event.Fail => |msgs| {
176 var stderr = try std.io.getStdErr();
172 const stderr = std.io.getStdErr();
177173 try stderr.write("build incorrectly failed:\n");
178174 for (msgs) |msg| {
179175 defer msg.destroy();
src-self-hosted/translate_c.zig-1
......@@ -12,7 +12,6 @@ pub const Mode = enum {
1212 translate,
1313};
1414
15// TODO merge with Type.Fn.CallingConvention
1615const CallingConvention = std.builtin.TypeInfo.CallingConvention;
1716
1817pub const ClangErrMsg = Stage2ErrorMsg;
src-self-hosted/type.zig+3-4
......@@ -399,8 +399,7 @@ pub const Type = struct {
399399 .Generic => |generic| {
400400 self.non_key = NonKey{ .Generic = {} };
401401 const cc_str = ccFnTypeStr(generic.cc);
402 try name_stream.write(cc_str);
403 try name_stream.write("fn(");
402 try name_stream.print("{}fn(", cc_str);
404403 var param_i: usize = 0;
405404 while (param_i < generic.param_count) : (param_i += 1) {
406405 const arg = if (param_i == 0) "var" else ", var";
......@@ -408,7 +407,7 @@ pub const Type = struct {
408407 }
409408 try name_stream.write(")");
410409 if (key.alignment) |alignment| {
411 try name_stream.print(" align<{}>", alignment);
410 try name_stream.print(" align({})", alignment);
412411 }
413412 try name_stream.write(" var");
414413 },
......@@ -429,7 +428,7 @@ pub const Type = struct {
429428 }
430429 try name_stream.write(")");
431430 if (key.alignment) |alignment| {
432 try name_stream.print(" align<{}>", alignment);
431 try name_stream.print(" align({})", alignment);
433432 }
434433 try name_stream.print(" {}", normal.return_type.name);
435434 },
src-self-hosted/util.zig+17
......@@ -32,6 +32,23 @@ pub fn getFloatAbi(self: Target) FloatAbi {
3232 };
3333}
3434
35pub fn getObjectFormat(self: Target) Target.ObjectFormat {
36 return switch (self) {
37 .Native => @import("builtin").object_format,
38 .Cross => {
39 if (target.isWindows() or target.isUefi()) {
40 break .coff;
41 } else if (target.isDarwin()) {
42 break .macho;
43 }
44 if (target.isWasm()) {
45 break .wasm;
46 }
47 break .elf;
48 },
49 };
50}
51
3552pub fn getDynamicLinkerPath(self: Target) ?[]const u8 {
3653 const env = self.getAbi();
3754 const arch = self.getArch();