self hosted compiler: various small fixes
This commit is contained in:
parent
bca672372a
commit
86d9563d15
@ -11,12 +11,12 @@ const assert = std.debug.assert;
|
||||
const DW = std.dwarf;
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) !void {
|
||||
pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) Compilation.BuildError!void {
|
||||
fn_val.base.ref();
|
||||
defer fn_val.base.deref(comp);
|
||||
defer code.destroy(comp.gpa());
|
||||
|
||||
var output_path = try comp.createRandomOutputPath(comp.target.objFileExt());
|
||||
var output_path = try comp.createRandomOutputPath(comp.target.oFileExt());
|
||||
errdefer output_path.deinit();
|
||||
|
||||
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)
|
||||
llvm.SetTarget(module, comp.llvm_triple.ptr());
|
||||
llvm.SetDataLayout(module, comp.target_layout_str);
|
||||
|
||||
if (comp.target.getObjectFormat() == .coff) {
|
||||
llvm.AddModuleCodeViewFlag(module);
|
||||
} else {
|
||||
// if (comp.target.getObjectFormat() == .coff) {
|
||||
// llvm.AddModuleCodeViewFlag(module);
|
||||
// } else {
|
||||
llvm.AddModuleDebugInfoFlag(module);
|
||||
}
|
||||
// }
|
||||
|
||||
const builder = llvm.CreateBuilderInContext(context) orelse return error.OutOfMemory;
|
||||
defer llvm.DisposeBuilder(builder);
|
||||
@ -113,7 +113,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
|
||||
comp.target_machine,
|
||||
module,
|
||||
output_path.ptr(),
|
||||
.EmitBinary,
|
||||
llvm.EmitBinary,
|
||||
&err_msg,
|
||||
is_debug,
|
||||
is_small,
|
||||
|
@ -857,7 +857,7 @@ pub const Compilation = struct {
|
||||
defer locked_table.release();
|
||||
|
||||
var decl_group = event.Group(BuildError!void).init(self.gpa());
|
||||
defer decl_group.deinit();
|
||||
defer decl_group.wait() catch {};
|
||||
|
||||
try self.rebuildChangedDecls(
|
||||
&decl_group,
|
||||
@ -937,7 +937,7 @@ pub const Compilation = struct {
|
||||
.parent_scope = &decl_scope.base,
|
||||
.tree_scope = tree_scope,
|
||||
},
|
||||
.value = Decl.Fn.Val{ .Unresolved = {} },
|
||||
.value = .Unresolved,
|
||||
.fn_proto = fn_proto,
|
||||
};
|
||||
tree_scope.base.ref();
|
||||
@ -1100,7 +1100,7 @@ pub const Compilation = struct {
|
||||
async fn addCompileErrorAsync(
|
||||
self: *Compilation,
|
||||
msg: *Msg,
|
||||
) !void {
|
||||
) BuildError!void {
|
||||
errdefer msg.destroy();
|
||||
|
||||
const compile_errors = self.compile_errors.acquire();
|
||||
@ -1109,7 +1109,7 @@ pub const Compilation = struct {
|
||||
try compile_errors.value.append(msg);
|
||||
}
|
||||
|
||||
async fn verifyUniqueSymbol(self: *Compilation, decl: *Decl) !void {
|
||||
async fn verifyUniqueSymbol(self: *Compilation, decl: *Decl) BuildError!void {
|
||||
const exported_symbol_names = self.exported_symbol_names.acquire();
|
||||
defer exported_symbol_names.release();
|
||||
|
||||
@ -1264,7 +1264,7 @@ pub const Compilation = struct {
|
||||
}
|
||||
|
||||
/// This declaration has been blessed as going into the final code generation.
|
||||
pub async fn resolveDecl(comp: *Compilation, decl: *Decl) !void {
|
||||
pub async fn resolveDecl(comp: *Compilation, decl: *Decl) BuildError!void {
|
||||
if (decl.resolution.start()) |ptr| return ptr.*;
|
||||
|
||||
decl.resolution.data = try generateDecl(comp, decl);
|
||||
@ -1363,7 +1363,7 @@ async fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void {
|
||||
try comp.prelink_group.call(addFnToLinkSet, comp, fn_val);
|
||||
}
|
||||
|
||||
async fn addFnToLinkSet(comp: *Compilation, fn_val: *Value.Fn) void {
|
||||
async fn addFnToLinkSet(comp: *Compilation, fn_val: *Value.Fn) Compilation.BuildError!void {
|
||||
fn_val.base.ref();
|
||||
defer fn_val.base.deref(comp);
|
||||
|
||||
@ -1421,7 +1421,7 @@ async fn analyzeFnType(
|
||||
.return_type = return_type,
|
||||
.params = params.toOwnedSlice(),
|
||||
.is_var_args = false, // TODO
|
||||
.cc = Type.Fn.CallingConvention.Auto, // TODO
|
||||
.cc = .Unspecified, // TODO
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -69,12 +69,15 @@ pub const Decl = struct {
|
||||
|
||||
pub const Fn = struct {
|
||||
base: Decl,
|
||||
value: union(enum) {
|
||||
value: Val,
|
||||
fn_proto: *ast.Node.FnProto,
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/683 and then make this anonymous
|
||||
pub const Val = union(enum) {
|
||||
Unresolved,
|
||||
Fn: *Value.Fn,
|
||||
FnProto: *Value.FnProto,
|
||||
},
|
||||
fn_proto: *ast.Node.FnProto,
|
||||
};
|
||||
|
||||
pub fn externLibName(self: Fn, tree: *ast.Tree) ?[]const u8 {
|
||||
return if (self.fn_proto.extern_export_inline_token) |tok_index| x: {
|
||||
|
@ -521,7 +521,7 @@ pub const Inst = struct {
|
||||
.Const => @panic("TODO"),
|
||||
.Param => |param| {
|
||||
const new_inst = try ira.irb.build(
|
||||
.VarPtr,
|
||||
Inst.VarPtr,
|
||||
self.base.scope,
|
||||
self.base.span,
|
||||
Inst.VarPtr.Params{ .var_scope = self.params.var_scope },
|
||||
@ -1134,7 +1134,7 @@ pub const Builder = struct {
|
||||
.VarType => return error.Unimplemented,
|
||||
.ErrorType => return error.Unimplemented,
|
||||
.FnProto => return error.Unimplemented,
|
||||
.PromiseType => return error.Unimplemented,
|
||||
.AnyFrameType => return error.Unimplemented,
|
||||
.IntegerLiteral => {
|
||||
const int_lit = @fieldParentPtr(ast.Node.IntegerLiteral, "base", node);
|
||||
return irb.lvalWrap(scope, try irb.genIntLit(int_lit, scope), lval);
|
||||
@ -1812,9 +1812,9 @@ pub const Builder = struct {
|
||||
for (@field(inst.params, @memberName(I.Params, i))) |other|
|
||||
other.ref(self);
|
||||
},
|
||||
.Mut,
|
||||
.Vol,
|
||||
.Size,
|
||||
Type.Pointer.Mut,
|
||||
Type.Pointer.Vol,
|
||||
Type.Pointer.Size,
|
||||
LVal,
|
||||
*Decl,
|
||||
*Scope.Var,
|
||||
|
@ -6,6 +6,7 @@ const Target = std.Target;
|
||||
const ObjectFormat = Target.ObjectFormat;
|
||||
const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
|
||||
const assert = std.debug.assert;
|
||||
const util = @import("util.zig");
|
||||
|
||||
const Context = struct {
|
||||
comp: *Compilation,
|
||||
@ -44,10 +45,10 @@ pub async fn link(comp: *Compilation) !void {
|
||||
try ctx.out_file_path.append(comp.target.exeFileExt());
|
||||
},
|
||||
.Lib => {
|
||||
try ctx.out_file_path.append(comp.target.libFileExt(comp.is_static));
|
||||
try ctx.out_file_path.append(if (comp.is_static) comp.target.staticLibSuffix() else comp.target.dynamicLibSuffix());
|
||||
},
|
||||
.Obj => {
|
||||
try ctx.out_file_path.append(comp.target.objFileExt());
|
||||
try ctx.out_file_path.append(comp.target.oFileExt());
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -77,7 +78,7 @@ pub async fn link(comp: *Compilation) !void {
|
||||
std.debug.warn("\n");
|
||||
}
|
||||
|
||||
const extern_ofmt = toExternObjectFormatType(comp.target.getObjectFormat());
|
||||
const extern_ofmt = toExternObjectFormatType(.elf); //comp.target.getObjectFormat());
|
||||
const args_slice = ctx.args.toSlice();
|
||||
|
||||
{
|
||||
@ -129,13 +130,14 @@ fn toExternObjectFormatType(ofmt: ObjectFormat) c.ZigLLVM_ObjectFormatType {
|
||||
}
|
||||
|
||||
fn constructLinkerArgs(ctx: *Context) !void {
|
||||
switch (ctx.comp.target.getObjectFormat()) {
|
||||
.unknown => unreachable,
|
||||
.coff => return constructLinkerArgsCoff(ctx),
|
||||
.elf => return constructLinkerArgsElf(ctx),
|
||||
.macho => return constructLinkerArgsMachO(ctx),
|
||||
.wasm => return constructLinkerArgsWasm(ctx),
|
||||
}
|
||||
return constructLinkerArgsElf(ctx);
|
||||
// switch (ctx.comp.target.getObjectFormat()) {
|
||||
// .unknown => unreachable,
|
||||
// .coff => return constructLinkerArgsCoff(ctx),
|
||||
// .elf => return constructLinkerArgsElf(ctx),
|
||||
// .macho => return constructLinkerArgsMachO(ctx),
|
||||
// .wasm => return constructLinkerArgsWasm(ctx),
|
||||
// }
|
||||
}
|
||||
|
||||
fn constructLinkerArgsElf(ctx: *Context) !void {
|
||||
|
@ -350,7 +350,7 @@ pub const Type = struct {
|
||||
|
||||
fn ccFnTypeStr(cc: CallingConvention) []const u8 {
|
||||
return switch (cc) {
|
||||
.Auto => "",
|
||||
.Unspecified => "",
|
||||
.C => "extern ",
|
||||
.Cold => "coldcc ",
|
||||
.Naked => "nakedcc ",
|
||||
|
@ -1,7 +1,6 @@
|
||||
const std = @import("std");
|
||||
const Target = std.Target;
|
||||
const llvm = @import("llvm.zig");
|
||||
// const builtin = @import("builtin");
|
||||
|
||||
pub const FloatAbi = enum {
|
||||
Hard,
|
||||
@ -9,20 +8,6 @@ pub const FloatAbi = enum {
|
||||
SoftFp,
|
||||
};
|
||||
|
||||
// pub const Cross = struct {
|
||||
// arch: Target.Arch,
|
||||
// os: Target.Os,
|
||||
// abi: Target.Abi,
|
||||
// object_format: builtin.ObjectFormat,
|
||||
// };
|
||||
|
||||
// pub fn getObjectFormat(self: Target) builtin.ObjectFormat {
|
||||
// return switch (self) {
|
||||
// .Native => builtin.object_format,
|
||||
// .Cross => |t| t.object_format,
|
||||
// };
|
||||
// }
|
||||
|
||||
/// TODO expose the arch and subarch separately
|
||||
pub fn isArmOrThumb(self: Target) bool {
|
||||
return switch (self.getArch()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user