| author | |
| committer | |
| log | d40f204ec05d5913046c17ae46bba3b14cdaf384 |
| tree | 15df55915afb4a7dad4ee55ab39fa911ba4e658e |
| parent | 133579d7c05a92e33bd8a4cfaf5c460f48150de7 |
| signature |
10 files changed, 62 insertions(+), 53 deletions(-)
src-self-hosted/codegen.zig+5-4| ... | ... | @@ -6,6 +6,7 @@ const ir = @import("ir.zig"); |
| 6 | 6 | const Value = @import("value.zig").Value; |
| 7 | 7 | const Type = @import("type.zig").Type; |
| 8 | 8 | const Scope = @import("scope.zig").Scope; |
| 9 | const util = @import("util.zig"); | |
| 9 | 10 | const event = std.event; |
| 10 | 11 | const assert = std.debug.assert; |
| 11 | 12 | const DW = std.dwarf; |
| ... | ... | @@ -30,11 +31,11 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 30 | 31 | llvm.SetTarget(module, comp.llvm_triple.ptr()); |
| 31 | 32 | llvm.SetDataLayout(module, comp.target_layout_str); |
| 32 | 33 | |
| 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 { | |
| 36 | 37 | llvm.AddModuleDebugInfoFlag(module); |
| 37 | // } | |
| 38 | } | |
| 38 | 39 | |
| 39 | 40 | const builder = llvm.CreateBuilderInContext(context) orelse return error.OutOfMemory; |
| 40 | 41 | defer llvm.DisposeBuilder(builder); |
src-self-hosted/compilation.zig-1| ... | ... | @@ -858,7 +858,6 @@ pub const Compilation = struct { |
| 858 | 858 | defer locked_table.release(); |
| 859 | 859 | |
| 860 | 860 | var decl_group = event.Group(BuildError!void).init(self.gpa()); |
| 861 | defer decl_group.wait() catch {}; | |
| 862 | 861 | |
| 863 | 862 | try self.rebuildChangedDecls( |
| 864 | 863 | &decl_group, |
src-self-hosted/libc_installation.zig+1-1| ... | ... | @@ -146,7 +146,7 @@ pub const LibCInstallation = struct { |
| 146 | 146 | pub async fn findNative(self: *LibCInstallation, allocator: *Allocator) !void { |
| 147 | 147 | self.initEmpty(); |
| 148 | 148 | var group = event.Group(FindError!void).init(allocator); |
| 149 | // errdefer group.deinit(); | |
| 149 | errdefer group.wait() catch {}; | |
| 150 | 150 | var windows_sdk: ?*c.ZigWindowsSDK = null; |
| 151 | 151 | errdefer if (windows_sdk) |sdk| c.zig_free_windows_sdk(@ptrCast(?[*]c.ZigWindowsSDK, sdk)); |
| 152 | 152 |
src-self-hosted/link.zig+8-9| ... | ... | @@ -78,7 +78,7 @@ pub async fn link(comp: *Compilation) !void { |
| 78 | 78 | std.debug.warn("\n"); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | const extern_ofmt = toExternObjectFormatType(.elf); //comp.target.getObjectFormat()); | |
| 81 | const extern_ofmt = toExternObjectFormatType(util.getObjectFormat(comp.target)); | |
| 82 | 82 | const args_slice = ctx.args.toSlice(); |
| 83 | 83 | |
| 84 | 84 | { |
| ... | ... | @@ -130,14 +130,13 @@ fn toExternObjectFormatType(ofmt: ObjectFormat) c.ZigLLVM_ObjectFormatType { |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | fn 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 | } | |
| 141 | 140 | } |
| 142 | 141 | |
| 143 | 142 | fn constructLinkerArgsElf(ctx: *Context) !void { |
src-self-hosted/llvm.zig+1-2| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | 1 | const c = @import("c.zig"); |
| 2 | const std = @import("std"); | |
| 3 | const assert = std.debug.assert; | |
| 2 | const assert = @import("std").debug.assert; | |
| 4 | 3 | |
| 5 | 4 | // we wrap the c module for 3 reasons: |
| 6 | 5 | // 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 |
| 260 | 260 | process.exit(0); |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | const build_mode = blk: { | |
| 263 | const build_mode: std.builtin.Mode = blk: { | |
| 264 | 264 | if (flags.single("mode")) |mode_flag| { |
| 265 | 265 | if (mem.eql(u8, mode_flag, "debug")) { |
| 266 | break :blk std.builtin.Mode.Debug; | |
| 266 | break :blk .Debug; | |
| 267 | 267 | } else if (mem.eql(u8, mode_flag, "release-fast")) { |
| 268 | break :blk std.builtin.Mode.ReleaseFast; | |
| 268 | break :blk .ReleaseFast; | |
| 269 | 269 | } else if (mem.eql(u8, mode_flag, "release-safe")) { |
| 270 | break :blk std.builtin.Mode.ReleaseSafe; | |
| 270 | break :blk .ReleaseSafe; | |
| 271 | 271 | } else if (mem.eql(u8, mode_flag, "release-small")) { |
| 272 | break :blk std.builtin.Mode.ReleaseSmall; | |
| 272 | break :blk .ReleaseSmall; | |
| 273 | 273 | } else unreachable; |
| 274 | 274 | } else { |
| 275 | break :blk std.builtin.Mode.Debug; | |
| 275 | break :blk .Debug; | |
| 276 | 276 | } |
| 277 | 277 | }; |
| 278 | 278 | |
| 279 | const color = blk: { | |
| 279 | const color: errmsg.Color = blk: { | |
| 280 | 280 | if (flags.single("color")) |color_flag| { |
| 281 | 281 | if (mem.eql(u8, color_flag, "auto")) { |
| 282 | break :blk errmsg.Color.Auto; | |
| 282 | break :blk .Auto; | |
| 283 | 283 | } else if (mem.eql(u8, color_flag, "on")) { |
| 284 | break :blk errmsg.Color.On; | |
| 284 | break :blk .On; | |
| 285 | 285 | } else if (mem.eql(u8, color_flag, "off")) { |
| 286 | break :blk errmsg.Color.Off; | |
| 286 | break :blk .Off; | |
| 287 | 287 | } else unreachable; |
| 288 | 288 | } else { |
| 289 | break :blk errmsg.Color.Auto; | |
| 289 | break :blk .Auto; | |
| 290 | 290 | } |
| 291 | 291 | }; |
| 292 | 292 | |
| 293 | const emit_type = blk: { | |
| 293 | const emit_type: Compilation.Emit = blk: { | |
| 294 | 294 | if (flags.single("emit")) |emit_flag| { |
| 295 | 295 | if (mem.eql(u8, emit_flag, "asm")) { |
| 296 | break :blk Compilation.Emit.Assembly; | |
| 296 | break :blk .Assembly; | |
| 297 | 297 | } else if (mem.eql(u8, emit_flag, "bin")) { |
| 298 | break :blk Compilation.Emit.Binary; | |
| 298 | break :blk .Binary; | |
| 299 | 299 | } else if (mem.eql(u8, emit_flag, "llvm-ir")) { |
| 300 | break :blk Compilation.Emit.LlvmIr; | |
| 300 | break :blk .LlvmIr; | |
| 301 | 301 | } else unreachable; |
| 302 | 302 | } else { |
| 303 | break :blk Compilation.Emit.Binary; | |
| 303 | break :blk .Binary; | |
| 304 | 304 | } |
| 305 | 305 | }; |
| 306 | 306 | |
| ... | ... | @@ -587,17 +587,17 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { |
| 587 | 587 | process.exit(0); |
| 588 | 588 | } |
| 589 | 589 | |
| 590 | const color = blk: { | |
| 590 | const color: errmsg.Color = blk: { | |
| 591 | 591 | if (flags.single("color")) |color_flag| { |
| 592 | 592 | if (mem.eql(u8, color_flag, "auto")) { |
| 593 | break :blk errmsg.Color.Auto; | |
| 593 | break :blk .Auto; | |
| 594 | 594 | } else if (mem.eql(u8, color_flag, "on")) { |
| 595 | break :blk errmsg.Color.On; | |
| 595 | break :blk .On; | |
| 596 | 596 | } else if (mem.eql(u8, color_flag, "off")) { |
| 597 | break :blk errmsg.Color.Off; | |
| 597 | break :blk .Off; | |
| 598 | 598 | } else unreachable; |
| 599 | 599 | } else { |
| 600 | break :blk errmsg.Color.Auto; | |
| 600 | break :blk .Auto; | |
| 601 | 601 | } |
| 602 | 602 | }; |
| 603 | 603 |
src-self-hosted/test.zig+6-10| ... | ... | @@ -16,7 +16,7 @@ test "stage2" { |
| 16 | 16 | try @import("../test/stage2/compile_errors.zig").addCases(&ctx); |
| 17 | 17 | try @import("../test/stage2/compare_output.zig").addCases(&ctx); |
| 18 | 18 | |
| 19 | try ctx.run(); | |
| 19 | async ctx.run(); | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | const file1 = "1.zig"; |
| ... | ... | @@ -44,7 +44,7 @@ pub const TestContext = struct { |
| 44 | 44 | errdefer self.zig_compiler.deinit(); |
| 45 | 45 | |
| 46 | 46 | self.group = std.event.Group(anyerror!void).init(allocator); |
| 47 | errdefer self.group.wait(); | |
| 47 | errdefer self.group.wait() catch {}; | |
| 48 | 48 | |
| 49 | 49 | self.zig_lib_dir = try introspect.resolveZigLibDir(allocator); |
| 50 | 50 | errdefer allocator.free(self.zig_lib_dir); |
| ... | ... | @@ -59,14 +59,10 @@ pub const TestContext = struct { |
| 59 | 59 | self.zig_compiler.deinit(); |
| 60 | 60 | } |
| 61 | 61 | |
| 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(); | |
| 69 | 64 | self.any_err = self.group.wait(); |
| 65 | return self.any_err; | |
| 70 | 66 | } |
| 71 | 67 | |
| 72 | 68 | fn testCompileError( |
| ... | ... | @@ -173,7 +169,7 @@ pub const TestContext = struct { |
| 173 | 169 | }, |
| 174 | 170 | Compilation.Event.Error => |err| return err, |
| 175 | 171 | Compilation.Event.Fail => |msgs| { |
| 176 | var stderr = try std.io.getStdErr(); | |
| 172 | const stderr = std.io.getStdErr(); | |
| 177 | 173 | try stderr.write("build incorrectly failed:\n"); |
| 178 | 174 | for (msgs) |msg| { |
| 179 | 175 | defer msg.destroy(); |
src-self-hosted/translate_c.zig-1| ... | ... | @@ -12,7 +12,6 @@ pub const Mode = enum { |
| 12 | 12 | translate, |
| 13 | 13 | }; |
| 14 | 14 | |
| 15 | // TODO merge with Type.Fn.CallingConvention | |
| 16 | 15 | const CallingConvention = std.builtin.TypeInfo.CallingConvention; |
| 17 | 16 | |
| 18 | 17 | pub const ClangErrMsg = Stage2ErrorMsg; |
src-self-hosted/type.zig+3-4| ... | ... | @@ -399,8 +399,7 @@ pub const Type = struct { |
| 399 | 399 | .Generic => |generic| { |
| 400 | 400 | self.non_key = NonKey{ .Generic = {} }; |
| 401 | 401 | 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); | |
| 404 | 403 | var param_i: usize = 0; |
| 405 | 404 | while (param_i < generic.param_count) : (param_i += 1) { |
| 406 | 405 | const arg = if (param_i == 0) "var" else ", var"; |
| ... | ... | @@ -408,7 +407,7 @@ pub const Type = struct { |
| 408 | 407 | } |
| 409 | 408 | try name_stream.write(")"); |
| 410 | 409 | if (key.alignment) |alignment| { |
| 411 | try name_stream.print(" align<{}>", alignment); | |
| 410 | try name_stream.print(" align({})", alignment); | |
| 412 | 411 | } |
| 413 | 412 | try name_stream.write(" var"); |
| 414 | 413 | }, |
| ... | ... | @@ -429,7 +428,7 @@ pub const Type = struct { |
| 429 | 428 | } |
| 430 | 429 | try name_stream.write(")"); |
| 431 | 430 | if (key.alignment) |alignment| { |
| 432 | try name_stream.print(" align<{}>", alignment); | |
| 431 | try name_stream.print(" align({})", alignment); | |
| 433 | 432 | } |
| 434 | 433 | try name_stream.print(" {}", normal.return_type.name); |
| 435 | 434 | }, |
src-self-hosted/util.zig+17| ... | ... | @@ -32,6 +32,23 @@ pub fn getFloatAbi(self: Target) FloatAbi { |
| 32 | 32 | }; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | pub 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 | ||
| 35 | 52 | pub fn getDynamicLinkerPath(self: Target) ?[]const u8 { |
| 36 | 53 | const env = self.getAbi(); |
| 37 | 54 | const arch = self.getArch(); |