diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-11-24 14:40:16 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-24 14:40:16 -0500 |
| commit | 2b1faa1f20ce22c07d7767e8af3bc64614b0ca0e (patch) | |
| tree | c0bc74564724f5aed82506e7fb991f6e99a746c0 /src-self-hosted/codegen.zig | |
| parent | 29d7b5a80c9faf640c3db0de14cd229e90b2d8c3 (diff) | |
| parent | 0cbf00a3ec3f6640556e39efaa6e936b0b42630b (diff) | |
| download | zig-2b1faa1f20ce22c07d7767e8af3bc64614b0ca0e.tar.gz zig-2b1faa1f20ce22c07d7767e8af3bc64614b0ca0e.zip | |
Merge pull request #3748 from Vexu/modernize-stage2
Updates and cleanup in self hosted compiler
Diffstat (limited to 'src-self-hosted/codegen.zig')
| -rw-r--r-- | src-self-hosted/codegen.zig | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src-self-hosted/codegen.zig b/src-self-hosted/codegen.zig index 90f5309faf..77b1d4fd74 100644 --- a/src-self-hosted/codegen.zig +++ b/src-self-hosted/codegen.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const builtin = @import("builtin"); const Compilation = @import("compilation.zig").Compilation; const llvm = @import("llvm.zig"); const c = @import("c.zig"); @@ -7,17 +6,18 @@ const ir = @import("ir.zig"); const Value = @import("value.zig").Value; const Type = @import("type.zig").Type; const Scope = @import("scope.zig").Scope; +const util = @import("util.zig"); const event = std.event; 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 await (async comp.createRandomOutputPath(comp.target.objFileExt()) catch unreachable); + var output_path = try comp.createRandomOutputPath(comp.target.oFileExt()); errdefer output_path.deinit(); const llvm_handle = try comp.zig_compiler.getAnyLlvmContext(); @@ -31,7 +31,7 @@ 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() == builtin.ObjectFormat.coff) { + if (util.getObjectFormat(comp.target) == .coff) { llvm.AddModuleCodeViewFlag(module); } else { llvm.AddModuleDebugInfoFlag(module); @@ -59,7 +59,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) comp.name.ptr(), comp.root_package.root_src_dir.ptr(), ) orelse return error.OutOfMemory; - const is_optimized = comp.build_mode != builtin.Mode.Debug; + const is_optimized = comp.build_mode != .Debug; const compile_unit = llvm.CreateCompileUnit( dibuilder, DW.LANG_C99, @@ -79,7 +79,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) .builder = builder, .dibuilder = dibuilder, .context = context, - .lock = event.Lock.init(comp.loop), + .lock = event.Lock.init(), .arena = &code.arena.allocator, }; @@ -105,8 +105,8 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) assert(comp.emit_file_type == Compilation.Emit.Binary); // TODO support other types - const is_small = comp.build_mode == builtin.Mode.ReleaseSmall; - const is_debug = comp.build_mode == builtin.Mode.Debug; + const is_small = comp.build_mode == .ReleaseSmall; + const is_debug = comp.build_mode == .Debug; var err_msg: [*]u8 = undefined; // TODO integrate this with evented I/O @@ -234,8 +234,8 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) // create debug variable declarations for variables and allocate all local variables for (var_list) |var_scope, i| { const var_type = switch (var_scope.data) { - Scope.Var.Data.Const => unreachable, - Scope.Var.Data.Param => |param| param.typ, + .Const => unreachable, + .Param => |param| param.typ, }; // if (!type_has_bits(var->value->type)) { // continue; @@ -266,7 +266,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) var_scope.data.Param.llvm_value = llvm.GetParam(llvm_fn, @intCast(c_uint, i)); } else { // gen_type = var->value->type; - var_scope.data.Param.llvm_value = try renderAlloca(ofile, var_type, var_scope.name, Type.Pointer.Align.Abi); + var_scope.data.Param.llvm_value = try renderAlloca(ofile, var_type, var_scope.name, .Abi); } // if (var->decl_node) { // var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope), @@ -300,8 +300,8 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) ofile, llvm_param, scope_var.data.Param.llvm_value, - Type.Pointer.Align.Abi, - Type.Pointer.Vol.Non, + .Abi, + .Non, ); } @@ -383,8 +383,8 @@ fn renderLoadUntyped( ) !*llvm.Value { const result = llvm.BuildLoad(ofile.builder, ptr, name) orelse return error.OutOfMemory; switch (vol) { - Type.Pointer.Vol.Non => {}, - Type.Pointer.Vol.Volatile => llvm.SetVolatile(result, 1), + .Non => {}, + .Volatile => llvm.SetVolatile(result, 1), } llvm.SetAlignment(result, resolveAlign(ofile, alignment, llvm.GetElementType(llvm.TypeOf(ptr)))); return result; @@ -414,8 +414,8 @@ pub fn renderStoreUntyped( ) !*llvm.Value { const result = llvm.BuildStore(ofile.builder, value, ptr) orelse return error.OutOfMemory; switch (vol) { - Type.Pointer.Vol.Non => {}, - Type.Pointer.Vol.Volatile => llvm.SetVolatile(result, 1), + .Non => {}, + .Volatile => llvm.SetVolatile(result, 1), } llvm.SetAlignment(result, resolveAlign(ofile, alignment, llvm.TypeOf(value))); return result; @@ -445,7 +445,7 @@ pub fn renderAlloca( pub fn resolveAlign(ofile: *ObjectFile, alignment: Type.Pointer.Align, llvm_type: *llvm.Type) u32 { return switch (alignment) { - Type.Pointer.Align.Abi => return llvm.ABIAlignmentOfType(ofile.comp.target_data_ref, llvm_type), - Type.Pointer.Align.Override => |a| a, + .Abi => return llvm.ABIAlignmentOfType(ofile.comp.target_data_ref, llvm_type), + .Override => |a| a, }; } |
