authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-08 00:18:14+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-08 00:18:14+02:00
log86d9563d1539cd7581dc120023bb830fae77ba0f
treee06c9f1131da348cc8ee7e0c705dbf58572b0c77
parentbca672372aa57e97fcfb76672fe02f8ca6c2d00e
signaturelock-open Commit is signed but in an unrecognized format.

self hosted compiler: various small fixes


7 files changed, 38 insertions(+), 48 deletions(-)

src-self-hosted/codegen.zig+7-7
......@@ -11,12 +11,12 @@ const assert = std.debug.assert;
1111const DW = std.dwarf;
1212const maxInt = std.math.maxInt;
1313
14pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) !void {
14pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) Compilation.BuildError!void {
1515 fn_val.base.ref();
1616 defer fn_val.base.deref(comp);
1717 defer code.destroy(comp.gpa());
1818
19 var output_path = try comp.createRandomOutputPath(comp.target.objFileExt());
19 var output_path = try comp.createRandomOutputPath(comp.target.oFileExt());
2020 errdefer output_path.deinit();
2121
2222 const llvm_handle = try comp.zig_compiler.getAnyLlvmContext();
......@@ -30,11 +30,11 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
3030 llvm.SetTarget(module, comp.llvm_triple.ptr());
3131 llvm.SetDataLayout(module, comp.target_layout_str);
3232
33 if (comp.target.getObjectFormat() == .coff) {
34 llvm.AddModuleCodeViewFlag(module);
35 } else {
33 // if (comp.target.getObjectFormat() == .coff) {
34 // llvm.AddModuleCodeViewFlag(module);
35 // } else {
3636 llvm.AddModuleDebugInfoFlag(module);
37 }
37 // }
3838
3939 const builder = llvm.CreateBuilderInContext(context) orelse return error.OutOfMemory;
4040 defer llvm.DisposeBuilder(builder);
......@@ -113,7 +113,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
113113 comp.target_machine,
114114 module,
115115 output_path.ptr(),
116 .EmitBinary,
116 llvm.EmitBinary,
117117 &err_msg,
118118 is_debug,
119119 is_small,
src-self-hosted/compilation.zig+7-7
......@@ -857,7 +857,7 @@ pub const Compilation = struct {
857857 defer locked_table.release();
858858
859859 var decl_group = event.Group(BuildError!void).init(self.gpa());
860 defer decl_group.deinit();
860 defer decl_group.wait() catch {};
861861
862862 try self.rebuildChangedDecls(
863863 &decl_group,
......@@ -937,7 +937,7 @@ pub const Compilation = struct {
937937 .parent_scope = &decl_scope.base,
938938 .tree_scope = tree_scope,
939939 },
940 .value = Decl.Fn.Val{ .Unresolved = {} },
940 .value = .Unresolved,
941941 .fn_proto = fn_proto,
942942 };
943943 tree_scope.base.ref();
......@@ -1100,7 +1100,7 @@ pub const Compilation = struct {
11001100 async fn addCompileErrorAsync(
11011101 self: *Compilation,
11021102 msg: *Msg,
1103 ) !void {
1103 ) BuildError!void {
11041104 errdefer msg.destroy();
11051105
11061106 const compile_errors = self.compile_errors.acquire();
......@@ -1109,7 +1109,7 @@ pub const Compilation = struct {
11091109 try compile_errors.value.append(msg);
11101110 }
11111111
1112 async fn verifyUniqueSymbol(self: *Compilation, decl: *Decl) !void {
1112 async fn verifyUniqueSymbol(self: *Compilation, decl: *Decl) BuildError!void {
11131113 const exported_symbol_names = self.exported_symbol_names.acquire();
11141114 defer exported_symbol_names.release();
11151115
......@@ -1264,7 +1264,7 @@ pub const Compilation = struct {
12641264 }
12651265
12661266 /// This declaration has been blessed as going into the final code generation.
1267 pub async fn resolveDecl(comp: *Compilation, decl: *Decl) !void {
1267 pub async fn resolveDecl(comp: *Compilation, decl: *Decl) BuildError!void {
12681268 if (decl.resolution.start()) |ptr| return ptr.*;
12691269
12701270 decl.resolution.data = try generateDecl(comp, decl);
......@@ -1363,7 +1363,7 @@ async fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void {
13631363 try comp.prelink_group.call(addFnToLinkSet, comp, fn_val);
13641364}
13651365
1366async fn addFnToLinkSet(comp: *Compilation, fn_val: *Value.Fn) void {
1366async fn addFnToLinkSet(comp: *Compilation, fn_val: *Value.Fn) Compilation.BuildError!void {
13671367 fn_val.base.ref();
13681368 defer fn_val.base.deref(comp);
13691369
......@@ -1421,7 +1421,7 @@ async fn analyzeFnType(
14211421 .return_type = return_type,
14221422 .params = params.toOwnedSlice(),
14231423 .is_var_args = false, // TODO
1424 .cc = Type.Fn.CallingConvention.Auto, // TODO
1424 .cc = .Unspecified, // TODO
14251425 },
14261426 },
14271427 };
src-self-hosted/decl.zig+6-3
......@@ -69,12 +69,15 @@ pub const Decl = struct {
6969
7070 pub const Fn = struct {
7171 base: Decl,
72 value: union(enum) {
72 value: Val,
73 fn_proto: *ast.Node.FnProto,
74
75 // TODO https://github.com/ziglang/zig/issues/683 and then make this anonymous
76 pub const Val = union(enum) {
7377 Unresolved,
7478 Fn: *Value.Fn,
7579 FnProto: *Value.FnProto,
76 },
77 fn_proto: *ast.Node.FnProto,
80 };
7881
7982 pub fn externLibName(self: Fn, tree: *ast.Tree) ?[]const u8 {
8083 return if (self.fn_proto.extern_export_inline_token) |tok_index| x: {
src-self-hosted/ir.zig+5-5
......@@ -521,7 +521,7 @@ pub const Inst = struct {
521521 .Const => @panic("TODO"),
522522 .Param => |param| {
523523 const new_inst = try ira.irb.build(
524 .VarPtr,
524 Inst.VarPtr,
525525 self.base.scope,
526526 self.base.span,
527527 Inst.VarPtr.Params{ .var_scope = self.params.var_scope },
......@@ -1134,7 +1134,7 @@ pub const Builder = struct {
11341134 .VarType => return error.Unimplemented,
11351135 .ErrorType => return error.Unimplemented,
11361136 .FnProto => return error.Unimplemented,
1137 .PromiseType => return error.Unimplemented,
1137 .AnyFrameType => return error.Unimplemented,
11381138 .IntegerLiteral => {
11391139 const int_lit = @fieldParentPtr(ast.Node.IntegerLiteral, "base", node);
11401140 return irb.lvalWrap(scope, try irb.genIntLit(int_lit, scope), lval);
......@@ -1812,9 +1812,9 @@ pub const Builder = struct {
18121812 for (@field(inst.params, @memberName(I.Params, i))) |other|
18131813 other.ref(self);
18141814 },
1815 .Mut,
1816 .Vol,
1817 .Size,
1815 Type.Pointer.Mut,
1816 Type.Pointer.Vol,
1817 Type.Pointer.Size,
18181818 LVal,
18191819 *Decl,
18201820 *Scope.Var,
src-self-hosted/link.zig+12-10
......@@ -6,6 +6,7 @@ const Target = std.Target;
66const ObjectFormat = Target.ObjectFormat;
77const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
88const assert = std.debug.assert;
9const util = @import("util.zig");
910
1011const Context = struct {
1112 comp: *Compilation,
......@@ -44,10 +45,10 @@ pub async fn link(comp: *Compilation) !void {
4445 try ctx.out_file_path.append(comp.target.exeFileExt());
4546 },
4647 .Lib => {
47 try ctx.out_file_path.append(comp.target.libFileExt(comp.is_static));
48 try ctx.out_file_path.append(if (comp.is_static) comp.target.staticLibSuffix() else comp.target.dynamicLibSuffix());
4849 },
4950 .Obj => {
50 try ctx.out_file_path.append(comp.target.objFileExt());
51 try ctx.out_file_path.append(comp.target.oFileExt());
5152 },
5253 }
5354 }
......@@ -77,7 +78,7 @@ pub async fn link(comp: *Compilation) !void {
7778 std.debug.warn("\n");
7879 }
7980
80 const extern_ofmt = toExternObjectFormatType(comp.target.getObjectFormat());
81 const extern_ofmt = toExternObjectFormatType(.elf); //comp.target.getObjectFormat());
8182 const args_slice = ctx.args.toSlice();
8283
8384 {
......@@ -129,13 +130,14 @@ fn toExternObjectFormatType(ofmt: ObjectFormat) c.ZigLLVM_ObjectFormatType {
129130}
130131
131132fn constructLinkerArgs(ctx: *Context) !void {
132 switch (ctx.comp.target.getObjectFormat()) {
133 .unknown => unreachable,
134 .coff => return constructLinkerArgsCoff(ctx),
135 .elf => return constructLinkerArgsElf(ctx),
136 .macho => return constructLinkerArgsMachO(ctx),
137 .wasm => return constructLinkerArgsWasm(ctx),
138 }
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 // }
139141}
140142
141143fn constructLinkerArgsElf(ctx: *Context) !void {
src-self-hosted/type.zig+1-1
......@@ -350,7 +350,7 @@ pub const Type = struct {
350350
351351 fn ccFnTypeStr(cc: CallingConvention) []const u8 {
352352 return switch (cc) {
353 .Auto => "",
353 .Unspecified => "",
354354 .C => "extern ",
355355 .Cold => "coldcc ",
356356 .Naked => "nakedcc ",
src-self-hosted/util.zig-15
......@@ -1,7 +1,6 @@
11const std = @import("std");
22const Target = std.Target;
33const llvm = @import("llvm.zig");
4// const builtin = @import("builtin");
54
65pub const FloatAbi = enum {
76 Hard,
......@@ -9,20 +8,6 @@ pub const FloatAbi = enum {
98 SoftFp,
109};
1110
12// pub const Cross = struct {
13// arch: Target.Arch,
14// os: Target.Os,
15// abi: Target.Abi,
16// object_format: builtin.ObjectFormat,
17// };
18
19// pub fn getObjectFormat(self: Target) builtin.ObjectFormat {
20// return switch (self) {
21// .Native => builtin.object_format,
22// .Cross => |t| t.object_format,
23// };
24// }
25
2611/// TODO expose the arch and subarch separately
2712pub fn isArmOrThumb(self: Target) bool {
2813 return switch (self.getArch()) {