| author | |
| committer | |
| log | 36849d8a7b5b0ed62d966ea9c402f192ade0cadf |
| tree | b03def98fe255f4572add7e7cae155e07964e93c |
| parent | 76f21852f6553fc22612bb82df19184fdb28719e |
| signature |
12 files changed, 244 insertions(+), 302 deletions(-)
src-self-hosted/codegen.zig+15-15| ... | ... | @@ -25,10 +25,10 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 25 | 25 | |
| 26 | 26 | const context = llvm_handle.node.data; |
| 27 | 27 | |
| 28 | const module = llvm.ModuleCreateWithNameInContext(comp.name.ptr(), context) orelse return error.OutOfMemory; | |
| 28 | const module = llvm.ModuleCreateWithNameInContext(comp.name.toSliceConst(), context) orelse return error.OutOfMemory; | |
| 29 | 29 | defer llvm.DisposeModule(module); |
| 30 | 30 | |
| 31 | llvm.SetTarget(module, comp.llvm_triple.ptr()); | |
| 31 | llvm.SetTarget(module, comp.llvm_triple.toSliceConst()); | |
| 32 | 32 | llvm.SetDataLayout(module, comp.target_layout_str); |
| 33 | 33 | |
| 34 | 34 | if (util.getObjectFormat(comp.target) == .coff) { |
| ... | ... | @@ -48,23 +48,23 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 48 | 48 | const producer = try std.Buffer.allocPrint( |
| 49 | 49 | &code.arena.allocator, |
| 50 | 50 | "zig {}.{}.{}", |
| 51 | u32(c.ZIG_VERSION_MAJOR), | |
| 52 | u32(c.ZIG_VERSION_MINOR), | |
| 53 | u32(c.ZIG_VERSION_PATCH), | |
| 51 | @as(u32, c.ZIG_VERSION_MAJOR), | |
| 52 | @as(u32, c.ZIG_VERSION_MINOR), | |
| 53 | @as(u32, c.ZIG_VERSION_PATCH), | |
| 54 | 54 | ); |
| 55 | 55 | const flags = ""; |
| 56 | 56 | const runtime_version = 0; |
| 57 | 57 | const compile_unit_file = llvm.CreateFile( |
| 58 | 58 | dibuilder, |
| 59 | comp.name.ptr(), | |
| 60 | comp.root_package.root_src_dir.ptr(), | |
| 59 | comp.name.toSliceConst(), | |
| 60 | comp.root_package.root_src_dir.toSliceConst(), | |
| 61 | 61 | ) orelse return error.OutOfMemory; |
| 62 | 62 | const is_optimized = comp.build_mode != .Debug; |
| 63 | 63 | const compile_unit = llvm.CreateCompileUnit( |
| 64 | 64 | dibuilder, |
| 65 | 65 | DW.LANG_C99, |
| 66 | 66 | compile_unit_file, |
| 67 | producer.ptr(), | |
| 67 | producer.toSliceConst(), | |
| 68 | 68 | is_optimized, |
| 69 | 69 | flags, |
| 70 | 70 | runtime_version, |
| ... | ... | @@ -99,7 +99,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 99 | 99 | |
| 100 | 100 | // verify the llvm module when safety is on |
| 101 | 101 | if (std.debug.runtime_safety) { |
| 102 | var error_ptr: ?[*]u8 = null; | |
| 102 | var error_ptr: ?[*:0]u8 = null; | |
| 103 | 103 | _ = llvm.VerifyModule(ofile.module, llvm.AbortProcessAction, &error_ptr); |
| 104 | 104 | } |
| 105 | 105 | |
| ... | ... | @@ -108,12 +108,12 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 108 | 108 | const is_small = comp.build_mode == .ReleaseSmall; |
| 109 | 109 | const is_debug = comp.build_mode == .Debug; |
| 110 | 110 | |
| 111 | var err_msg: [*]u8 = undefined; | |
| 111 | var err_msg: [*:0]u8 = undefined; | |
| 112 | 112 | // TODO integrate this with evented I/O |
| 113 | 113 | if (llvm.TargetMachineEmitToFile( |
| 114 | 114 | comp.target_machine, |
| 115 | 115 | module, |
| 116 | output_path.ptr(), | |
| 116 | output_path.toSliceConst(), | |
| 117 | 117 | llvm.EmitBinary, |
| 118 | 118 | &err_msg, |
| 119 | 119 | is_debug, |
| ... | ... | @@ -154,7 +154,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 154 | 154 | const llvm_fn_type = try fn_val.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 155 | 155 | const llvm_fn = llvm.AddFunction( |
| 156 | 156 | ofile.module, |
| 157 | fn_val.symbol_name.ptr(), | |
| 157 | fn_val.symbol_name.toSliceConst(), | |
| 158 | 158 | llvm_fn_type, |
| 159 | 159 | ) orelse return error.OutOfMemory; |
| 160 | 160 | |
| ... | ... | @@ -379,7 +379,7 @@ fn renderLoadUntyped( |
| 379 | 379 | ptr: *llvm.Value, |
| 380 | 380 | alignment: Type.Pointer.Align, |
| 381 | 381 | vol: Type.Pointer.Vol, |
| 382 | name: [*]const u8, | |
| 382 | name: [*:0]const u8, | |
| 383 | 383 | ) !*llvm.Value { |
| 384 | 384 | const result = llvm.BuildLoad(ofile.builder, ptr, name) orelse return error.OutOfMemory; |
| 385 | 385 | switch (vol) { |
| ... | ... | @@ -390,7 +390,7 @@ fn renderLoadUntyped( |
| 390 | 390 | return result; |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | fn renderLoad(ofile: *ObjectFile, ptr: *llvm.Value, ptr_type: *Type.Pointer, name: [*]const u8) !*llvm.Value { | |
| 393 | fn renderLoad(ofile: *ObjectFile, ptr: *llvm.Value, ptr_type: *Type.Pointer, name: [*:0]const u8) !*llvm.Value { | |
| 394 | 394 | return renderLoadUntyped(ofile, ptr, ptr_type.key.alignment, ptr_type.key.vol, name); |
| 395 | 395 | } |
| 396 | 396 | |
| ... | ... | @@ -438,7 +438,7 @@ pub fn renderAlloca( |
| 438 | 438 | ) !*llvm.Value { |
| 439 | 439 | const llvm_var_type = try var_type.getLlvmType(ofile.arena, ofile.context); |
| 440 | 440 | const name_with_null = try std.cstr.addNullByte(ofile.arena, name); |
| 441 | const result = llvm.BuildAlloca(ofile.builder, llvm_var_type, name_with_null.ptr) orelse return error.OutOfMemory; | |
| 441 | const result = llvm.BuildAlloca(ofile.builder, llvm_var_type, @ptrCast([*:0]const u8, name_with_null.ptr)) orelse return error.OutOfMemory; | |
| 442 | 442 | llvm.SetAlignment(result, resolveAlign(ofile, alignment, llvm_var_type)); |
| 443 | 443 | return result; |
| 444 | 444 | } |
src-self-hosted/compilation.zig+93-128| ... | ... | @@ -93,7 +93,7 @@ pub const ZigCompiler = struct { |
| 93 | 93 | return LlvmHandle{ .node = node }; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | pub async fn getNativeLibC(self: *ZigCompiler) !*LibCInstallation { | |
| 96 | pub fn getNativeLibC(self: *ZigCompiler) !*LibCInstallation { | |
| 97 | 97 | if (self.native_libc.start()) |ptr| return ptr; |
| 98 | 98 | try self.native_libc.data.findNative(self.allocator); |
| 99 | 99 | self.native_libc.resolve(); |
| ... | ... | @@ -135,26 +135,26 @@ pub const Compilation = struct { |
| 135 | 135 | /// lazily created when we need it |
| 136 | 136 | tmp_dir: event.Future(BuildError![]u8), |
| 137 | 137 | |
| 138 | version_major: u32, | |
| 139 | version_minor: u32, | |
| 140 | version_patch: u32, | |
| 138 | version_major: u32 = 0, | |
| 139 | version_minor: u32 = 0, | |
| 140 | version_patch: u32 = 0, | |
| 141 | 141 | |
| 142 | linker_script: ?[]const u8, | |
| 143 | out_h_path: ?[]const u8, | |
| 142 | linker_script: ?[]const u8 = null, | |
| 143 | out_h_path: ?[]const u8 = null, | |
| 144 | 144 | |
| 145 | is_test: bool, | |
| 146 | each_lib_rpath: bool, | |
| 147 | strip: bool, | |
| 145 | is_test: bool = false, | |
| 146 | each_lib_rpath: bool = false, | |
| 147 | strip: bool = false, | |
| 148 | 148 | is_static: bool, |
| 149 | linker_rdynamic: bool, | |
| 149 | linker_rdynamic: bool = false, | |
| 150 | 150 | |
| 151 | clang_argv: []const []const u8, | |
| 152 | lib_dirs: []const []const u8, | |
| 153 | rpath_list: []const []const u8, | |
| 154 | assembly_files: []const []const u8, | |
| 151 | clang_argv: []const []const u8 = [_][]const u8{}, | |
| 152 | lib_dirs: []const []const u8 = [_][]const u8{}, | |
| 153 | rpath_list: []const []const u8 = [_][]const u8{}, | |
| 154 | assembly_files: []const []const u8 = [_][]const u8{}, | |
| 155 | 155 | |
| 156 | 156 | /// paths that are explicitly provided by the user to link against |
| 157 | link_objects: []const []const u8, | |
| 157 | link_objects: []const []const u8 = [_][]const u8{}, | |
| 158 | 158 | |
| 159 | 159 | /// functions that have their own objects that we need to link |
| 160 | 160 | /// it uses an optional pointer so that tombstone removals are possible |
| ... | ... | @@ -162,33 +162,33 @@ pub const Compilation = struct { |
| 162 | 162 | |
| 163 | 163 | pub const FnLinkSet = std.TailQueue(?*Value.Fn); |
| 164 | 164 | |
| 165 | windows_subsystem_windows: bool, | |
| 166 | windows_subsystem_console: bool, | |
| 165 | windows_subsystem_windows: bool = false, | |
| 166 | windows_subsystem_console: bool = false, | |
| 167 | 167 | |
| 168 | 168 | link_libs_list: ArrayList(*LinkLib), |
| 169 | libc_link_lib: ?*LinkLib, | |
| 169 | libc_link_lib: ?*LinkLib = null, | |
| 170 | 170 | |
| 171 | err_color: errmsg.Color, | |
| 171 | err_color: errmsg.Color = .Auto, | |
| 172 | 172 | |
| 173 | verbose_tokenize: bool, | |
| 174 | verbose_ast_tree: bool, | |
| 175 | verbose_ast_fmt: bool, | |
| 176 | verbose_cimport: bool, | |
| 177 | verbose_ir: bool, | |
| 178 | verbose_llvm_ir: bool, | |
| 179 | verbose_link: bool, | |
| 173 | verbose_tokenize: bool = false, | |
| 174 | verbose_ast_tree: bool = false, | |
| 175 | verbose_ast_fmt: bool = false, | |
| 176 | verbose_cimport: bool = false, | |
| 177 | verbose_ir: bool = false, | |
| 178 | verbose_llvm_ir: bool = false, | |
| 179 | verbose_link: bool = false, | |
| 180 | 180 | |
| 181 | darwin_frameworks: []const []const u8, | |
| 182 | darwin_version_min: DarwinVersionMin, | |
| 181 | darwin_frameworks: []const []const u8 = [_][]const u8{}, | |
| 182 | darwin_version_min: DarwinVersionMin = .None, | |
| 183 | 183 | |
| 184 | test_filters: []const []const u8, | |
| 185 | test_name_prefix: ?[]const u8, | |
| 184 | test_filters: []const []const u8 = [_][]const u8{}, | |
| 185 | test_name_prefix: ?[]const u8 = null, | |
| 186 | 186 | |
| 187 | emit_file_type: Emit, | |
| 187 | emit_file_type: Emit = .Binary, | |
| 188 | 188 | |
| 189 | 189 | kind: Kind, |
| 190 | 190 | |
| 191 | link_out_file: ?[]const u8, | |
| 191 | link_out_file: ?[]const u8 = null, | |
| 192 | 192 | events: *event.Channel(Event), |
| 193 | 193 | |
| 194 | 194 | exported_symbol_names: event.Locked(Decl.Table), |
| ... | ... | @@ -213,7 +213,7 @@ pub const Compilation = struct { |
| 213 | 213 | |
| 214 | 214 | target_machine: *llvm.TargetMachine, |
| 215 | 215 | target_data_ref: *llvm.TargetData, |
| 216 | target_layout_str: [*]u8, | |
| 216 | target_layout_str: [*:0]u8, | |
| 217 | 217 | target_ptr_bits: u32, |
| 218 | 218 | |
| 219 | 219 | /// for allocating things which have the same lifetime as this Compilation |
| ... | ... | @@ -222,7 +222,7 @@ pub const Compilation = struct { |
| 222 | 222 | root_package: *Package, |
| 223 | 223 | std_package: *Package, |
| 224 | 224 | |
| 225 | override_libc: ?*LibCInstallation, | |
| 225 | override_libc: ?*LibCInstallation = null, | |
| 226 | 226 | |
| 227 | 227 | /// need to wait on this group before deinitializing |
| 228 | 228 | deinit_group: event.Group(void), |
| ... | ... | @@ -231,7 +231,7 @@ pub const Compilation = struct { |
| 231 | 231 | // main_loop_frame: @Frame(Compilation.mainLoop), |
| 232 | 232 | main_loop_future: event.Future(void), |
| 233 | 233 | |
| 234 | have_err_ret_tracing: bool, | |
| 234 | have_err_ret_tracing: bool = false, | |
| 235 | 235 | |
| 236 | 236 | /// not locked because it is read-only |
| 237 | 237 | primitive_type_table: TypeTable, |
| ... | ... | @@ -243,7 +243,7 @@ pub const Compilation = struct { |
| 243 | 243 | |
| 244 | 244 | c_int_types: [CInt.list.len]*Type.Int, |
| 245 | 245 | |
| 246 | // fs_watch: *fs.Watch(*Scope.Root), | |
| 246 | fs_watch: *fs.Watch(*Scope.Root), | |
| 247 | 247 | |
| 248 | 248 | const IntTypeTable = std.HashMap(*const Type.Int.Key, *Type.Int, Type.Int.Key.hash, Type.Int.Key.eql); |
| 249 | 249 | const ArrayTypeTable = std.HashMap(*const Type.Array.Key, *Type.Array, Type.Array.Key.hash, Type.Array.Key.eql); |
| ... | ... | @@ -392,43 +392,10 @@ pub const Compilation = struct { |
| 392 | 392 | |
| 393 | 393 | .name = undefined, |
| 394 | 394 | .llvm_triple = undefined, |
| 395 | ||
| 396 | .version_major = 0, | |
| 397 | .version_minor = 0, | |
| 398 | .version_patch = 0, | |
| 399 | ||
| 400 | .verbose_tokenize = false, | |
| 401 | .verbose_ast_tree = false, | |
| 402 | .verbose_ast_fmt = false, | |
| 403 | .verbose_cimport = false, | |
| 404 | .verbose_ir = false, | |
| 405 | .verbose_llvm_ir = false, | |
| 406 | .verbose_link = false, | |
| 407 | ||
| 408 | .linker_script = null, | |
| 409 | .out_h_path = null, | |
| 410 | .is_test = false, | |
| 411 | .each_lib_rpath = false, | |
| 412 | .strip = false, | |
| 413 | 395 | .is_static = is_static, |
| 414 | .linker_rdynamic = false, | |
| 415 | .clang_argv = [_][]const u8{}, | |
| 416 | .lib_dirs = [_][]const u8{}, | |
| 417 | .rpath_list = [_][]const u8{}, | |
| 418 | .assembly_files = [_][]const u8{}, | |
| 419 | .link_objects = [_][]const u8{}, | |
| 420 | 396 | .fn_link_set = event.Locked(FnLinkSet).init(FnLinkSet.init()), |
| 421 | .windows_subsystem_windows = false, | |
| 422 | .windows_subsystem_console = false, | |
| 423 | 397 | .link_libs_list = undefined, |
| 424 | .libc_link_lib = null, | |
| 425 | .err_color = errmsg.Color.Auto, | |
| 426 | .darwin_frameworks = [_][]const u8{}, | |
| 427 | .darwin_version_min = DarwinVersionMin.None, | |
| 428 | .test_filters = [_][]const u8{}, | |
| 429 | .test_name_prefix = null, | |
| 430 | .emit_file_type = Emit.Binary, | |
| 431 | .link_out_file = null, | |
| 398 | ||
| 432 | 399 | .exported_symbol_names = event.Locked(Decl.Table).init(Decl.Table.init(allocator)), |
| 433 | 400 | .prelink_group = event.Group(BuildError!void).init(allocator), |
| 434 | 401 | .deinit_group = event.Group(void).init(allocator), |
| ... | ... | @@ -458,11 +425,9 @@ pub const Compilation = struct { |
| 458 | 425 | .root_package = undefined, |
| 459 | 426 | .std_package = undefined, |
| 460 | 427 | |
| 461 | .override_libc = null, | |
| 462 | .have_err_ret_tracing = false, | |
| 463 | 428 | .primitive_type_table = undefined, |
| 464 | 429 | |
| 465 | // .fs_watch = undefined, | |
| 430 | .fs_watch = undefined, | |
| 466 | 431 | }; |
| 467 | 432 | comp.link_libs_list = ArrayList(*LinkLib).init(comp.arena()); |
| 468 | 433 | comp.primitive_type_table = TypeTable.init(comp.arena()); |
| ... | ... | @@ -534,8 +499,8 @@ pub const Compilation = struct { |
| 534 | 499 | comp.root_package = try Package.create(comp.arena(), ".", ""); |
| 535 | 500 | } |
| 536 | 501 | |
| 537 | // comp.fs_watch = try fs.Watch(*Scope.Root).create(16); | |
| 538 | // defer comp.fs_watch.destroy(); | |
| 502 | comp.fs_watch = try fs.Watch(*Scope.Root).init(allocator, 16); | |
| 503 | defer comp.fs_watch.deinit(); | |
| 539 | 504 | |
| 540 | 505 | try comp.initTypes(); |
| 541 | 506 | defer comp.primitive_type_table.deinit(); |
| ... | ... | @@ -559,7 +524,7 @@ pub const Compilation = struct { |
| 559 | 524 | } |
| 560 | 525 | |
| 561 | 526 | /// it does ref the result because it could be an arbitrary integer size |
| 562 | pub async fn getPrimitiveType(comp: *Compilation, name: []const u8) !?*Type { | |
| 527 | pub fn getPrimitiveType(comp: *Compilation, name: []const u8) !?*Type { | |
| 563 | 528 | if (name.len >= 2) { |
| 564 | 529 | switch (name[0]) { |
| 565 | 530 | 'i', 'u' => blk: { |
| ... | ... | @@ -795,47 +760,47 @@ pub const Compilation = struct { |
| 795 | 760 | self.events.put(Event{ .Error = err }); |
| 796 | 761 | } |
| 797 | 762 | |
| 798 | // // First, get an item from the watch channel, waiting on the channel. | |
| 799 | // var group = event.Group(BuildError!void).init(self.gpa()); | |
| 800 | // { | |
| 801 | // const ev = (self.fs_watch.channel.get()) catch |err| { | |
| 802 | // build_result = err; | |
| 803 | // continue; | |
| 804 | // }; | |
| 805 | // const root_scope = ev.data; | |
| 806 | // group.call(rebuildFile, self, root_scope) catch |err| { | |
| 807 | // build_result = err; | |
| 808 | // continue; | |
| 809 | // }; | |
| 810 | // } | |
| 811 | // // Next, get all the items from the channel that are buffered up. | |
| 812 | // while (self.fs_watch.channel.getOrNull()) |ev_or_err| { | |
| 813 | // if (ev_or_err) |ev| { | |
| 814 | // const root_scope = ev.data; | |
| 815 | // group.call(rebuildFile, self, root_scope) catch |err| { | |
| 816 | // build_result = err; | |
| 817 | // continue; | |
| 818 | // }; | |
| 819 | // } else |err| { | |
| 820 | // build_result = err; | |
| 821 | // continue; | |
| 822 | // } | |
| 823 | // } | |
| 824 | // build_result = group.wait(); | |
| 763 | // First, get an item from the watch channel, waiting on the channel. | |
| 764 | var group = event.Group(BuildError!void).init(self.gpa()); | |
| 765 | { | |
| 766 | const ev = (self.fs_watch.channel.get()) catch |err| { | |
| 767 | build_result = err; | |
| 768 | continue; | |
| 769 | }; | |
| 770 | const root_scope = ev.data; | |
| 771 | group.call(rebuildFile, self, root_scope) catch |err| { | |
| 772 | build_result = err; | |
| 773 | continue; | |
| 774 | }; | |
| 775 | } | |
| 776 | // Next, get all the items from the channel that are buffered up. | |
| 777 | while (self.fs_watch.channel.getOrNull()) |ev_or_err| { | |
| 778 | if (ev_or_err) |ev| { | |
| 779 | const root_scope = ev.data; | |
| 780 | group.call(rebuildFile, self, root_scope) catch |err| { | |
| 781 | build_result = err; | |
| 782 | continue; | |
| 783 | }; | |
| 784 | } else |err| { | |
| 785 | build_result = err; | |
| 786 | continue; | |
| 787 | } | |
| 788 | } | |
| 789 | build_result = group.wait(); | |
| 825 | 790 | } |
| 826 | 791 | } |
| 827 | 792 | |
| 828 | async fn rebuildFile(self: *Compilation, root_scope: *Scope.Root) !void { | |
| 793 | async fn rebuildFile(self: *Compilation, root_scope: *Scope.Root) BuildError!void { | |
| 829 | 794 | const tree_scope = blk: { |
| 830 | const source_code = ""; | |
| 831 | // const source_code = fs.readFile( | |
| 832 | // root_scope.realpath, | |
| 833 | // max_src_size, | |
| 834 | // ) catch |err| { | |
| 835 | // try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", @errorName(err)); | |
| 836 | // return; | |
| 837 | // }; | |
| 838 | // errdefer self.gpa().free(source_code); | |
| 795 | const source_code = fs.readFile( | |
| 796 | self.gpa(), | |
| 797 | root_scope.realpath, | |
| 798 | max_src_size, | |
| 799 | ) catch |err| { | |
| 800 | try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", @errorName(err)); | |
| 801 | return; | |
| 802 | }; | |
| 803 | errdefer self.gpa().free(source_code); | |
| 839 | 804 | |
| 840 | 805 | const tree = try std.zig.parse(self.gpa(), source_code); |
| 841 | 806 | errdefer { |
| ... | ... | @@ -873,7 +838,7 @@ pub const Compilation = struct { |
| 873 | 838 | try decl_group.wait(); |
| 874 | 839 | } |
| 875 | 840 | |
| 876 | async fn rebuildChangedDecls( | |
| 841 | fn rebuildChangedDecls( | |
| 877 | 842 | self: *Compilation, |
| 878 | 843 | group: *event.Group(BuildError!void), |
| 879 | 844 | locked_table: *Decl.Table, |
| ... | ... | @@ -962,7 +927,7 @@ pub const Compilation = struct { |
| 962 | 927 | } |
| 963 | 928 | } |
| 964 | 929 | |
| 965 | async fn initialCompile(self: *Compilation) !void { | |
| 930 | fn initialCompile(self: *Compilation) !void { | |
| 966 | 931 | if (self.root_src_path) |root_src_path| { |
| 967 | 932 | const root_scope = blk: { |
| 968 | 933 | // TODO async/await std.fs.realpath |
| ... | ... | @@ -981,7 +946,7 @@ pub const Compilation = struct { |
| 981 | 946 | } |
| 982 | 947 | } |
| 983 | 948 | |
| 984 | async fn maybeLink(self: *Compilation) !void { | |
| 949 | fn maybeLink(self: *Compilation) !void { | |
| 985 | 950 | (self.prelink_group.wait()) catch |err| switch (err) { |
| 986 | 951 | error.SemanticAnalysisFailed => {}, |
| 987 | 952 | else => return err, |
| ... | ... | @@ -1184,7 +1149,7 @@ pub const Compilation = struct { |
| 1184 | 1149 | |
| 1185 | 1150 | /// If the temporary directory for this compilation has not been created, it creates it. |
| 1186 | 1151 | /// Then it creates a random file name in that dir and returns it. |
| 1187 | pub async fn createRandomOutputPath(self: *Compilation, suffix: []const u8) !Buffer { | |
| 1152 | pub fn createRandomOutputPath(self: *Compilation, suffix: []const u8) !Buffer { | |
| 1188 | 1153 | const tmp_dir = try self.getTmpDir(); |
| 1189 | 1154 | const file_prefix = self.getRandomFileName(); |
| 1190 | 1155 | |
| ... | ... | @@ -1200,14 +1165,14 @@ pub const Compilation = struct { |
| 1200 | 1165 | /// If the temporary directory for this Compilation has not been created, creates it. |
| 1201 | 1166 | /// Then returns it. The directory is unique to this Compilation and cleaned up when |
| 1202 | 1167 | /// the Compilation deinitializes. |
| 1203 | async fn getTmpDir(self: *Compilation) ![]const u8 { | |
| 1168 | fn getTmpDir(self: *Compilation) ![]const u8 { | |
| 1204 | 1169 | if (self.tmp_dir.start()) |ptr| return ptr.*; |
| 1205 | 1170 | self.tmp_dir.data = self.getTmpDirImpl(); |
| 1206 | 1171 | self.tmp_dir.resolve(); |
| 1207 | 1172 | return self.tmp_dir.data; |
| 1208 | 1173 | } |
| 1209 | 1174 | |
| 1210 | async fn getTmpDirImpl(self: *Compilation) ![]u8 { | |
| 1175 | fn getTmpDirImpl(self: *Compilation) ![]u8 { | |
| 1211 | 1176 | const comp_dir_name = self.getRandomFileName(); |
| 1212 | 1177 | const zig_dir_path = try getZigDir(self.gpa()); |
| 1213 | 1178 | defer self.gpa().free(zig_dir_path); |
| ... | ... | @@ -1217,7 +1182,7 @@ pub const Compilation = struct { |
| 1217 | 1182 | return tmp_dir; |
| 1218 | 1183 | } |
| 1219 | 1184 | |
| 1220 | async fn getRandomFileName(self: *Compilation) [12]u8 { | |
| 1185 | fn getRandomFileName(self: *Compilation) [12]u8 { | |
| 1221 | 1186 | // here we replace the standard +/ with -_ so that it can be used in a file name |
| 1222 | 1187 | const b64_fs_encoder = std.base64.Base64Encoder.init( |
| 1223 | 1188 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", |
| ... | ... | @@ -1243,7 +1208,7 @@ pub const Compilation = struct { |
| 1243 | 1208 | } |
| 1244 | 1209 | |
| 1245 | 1210 | /// Returns a value which has been ref()'d once |
| 1246 | async fn analyzeConstValue( | |
| 1211 | fn analyzeConstValue( | |
| 1247 | 1212 | comp: *Compilation, |
| 1248 | 1213 | tree_scope: *Scope.AstTree, |
| 1249 | 1214 | scope: *Scope, |
| ... | ... | @@ -1256,7 +1221,7 @@ pub const Compilation = struct { |
| 1256 | 1221 | return analyzed_code.getCompTimeResult(comp); |
| 1257 | 1222 | } |
| 1258 | 1223 | |
| 1259 | async fn analyzeTypeExpr(comp: *Compilation, tree_scope: *Scope.AstTree, scope: *Scope, node: *ast.Node) !*Type { | |
| 1224 | fn analyzeTypeExpr(comp: *Compilation, tree_scope: *Scope.AstTree, scope: *Scope, node: *ast.Node) !*Type { | |
| 1260 | 1225 | const meta_type = &Type.MetaType.get(comp).base; |
| 1261 | 1226 | defer meta_type.base.deref(comp); |
| 1262 | 1227 | |
| ... | ... | @@ -1287,7 +1252,7 @@ fn parseVisibToken(tree: *ast.Tree, optional_token_index: ?ast.TokenIndex) Visib |
| 1287 | 1252 | } |
| 1288 | 1253 | |
| 1289 | 1254 | /// The function that actually does the generation. |
| 1290 | async fn generateDecl(comp: *Compilation, decl: *Decl) !void { | |
| 1255 | fn generateDecl(comp: *Compilation, decl: *Decl) !void { | |
| 1291 | 1256 | switch (decl.id) { |
| 1292 | 1257 | .Var => @panic("TODO"), |
| 1293 | 1258 | .Fn => { |
| ... | ... | @@ -1298,7 +1263,7 @@ async fn generateDecl(comp: *Compilation, decl: *Decl) !void { |
| 1298 | 1263 | } |
| 1299 | 1264 | } |
| 1300 | 1265 | |
| 1301 | async fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void { | |
| 1266 | fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void { | |
| 1302 | 1267 | const tree_scope = fn_decl.base.tree_scope; |
| 1303 | 1268 | |
| 1304 | 1269 | const body_node = fn_decl.fn_proto.body_node orelse return generateDeclFnProto(comp, fn_decl); |
| ... | ... | @@ -1315,7 +1280,7 @@ async fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void { |
| 1315 | 1280 | |
| 1316 | 1281 | // The Decl.Fn owns the initial 1 reference count |
| 1317 | 1282 | const fn_val = try Value.Fn.create(comp, fn_type, fndef_scope, symbol_name); |
| 1318 | fn_decl.value = Decl.Fn.Val{ .Fn = fn_val }; | |
| 1283 | fn_decl.value = .{ .Fn = fn_val }; | |
| 1319 | 1284 | symbol_name_consumed = true; |
| 1320 | 1285 | |
| 1321 | 1286 | // Define local parameter variables |
| ... | ... | @@ -1382,7 +1347,7 @@ fn getZigDir(allocator: *mem.Allocator) ![]u8 { |
| 1382 | 1347 | return std.fs.getAppDataDir(allocator, "zig"); |
| 1383 | 1348 | } |
| 1384 | 1349 | |
| 1385 | async fn analyzeFnType( | |
| 1350 | fn analyzeFnType( | |
| 1386 | 1351 | comp: *Compilation, |
| 1387 | 1352 | tree_scope: *Scope.AstTree, |
| 1388 | 1353 | scope: *Scope, |
| ... | ... | @@ -1444,7 +1409,7 @@ async fn analyzeFnType( |
| 1444 | 1409 | return fn_type; |
| 1445 | 1410 | } |
| 1446 | 1411 | |
| 1447 | async fn generateDeclFnProto(comp: *Compilation, fn_decl: *Decl.Fn) !void { | |
| 1412 | fn generateDeclFnProto(comp: *Compilation, fn_decl: *Decl.Fn) !void { | |
| 1448 | 1413 | const fn_type = try analyzeFnType( |
| 1449 | 1414 | comp, |
| 1450 | 1415 | fn_decl.base.tree_scope, |
| ... | ... | @@ -1459,6 +1424,6 @@ async fn generateDeclFnProto(comp: *Compilation, fn_decl: *Decl.Fn) !void { |
| 1459 | 1424 | |
| 1460 | 1425 | // The Decl.Fn owns the initial 1 reference count |
| 1461 | 1426 | const fn_proto_val = try Value.FnProto.create(comp, fn_type, symbol_name); |
| 1462 | fn_decl.value = Decl.Fn.Val{ .FnProto = fn_proto_val }; | |
| 1427 | fn_decl.value = .{ .FnProto = fn_proto_val }; | |
| 1463 | 1428 | symbol_name_consumed = true; |
| 1464 | 1429 | } |
src-self-hosted/decl.zig+3-6| ... | ... | @@ -69,15 +69,12 @@ pub const Decl = struct { |
| 69 | 69 | |
| 70 | 70 | pub const Fn = struct { |
| 71 | 71 | base: Decl, |
| 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) { | |
| 72 | value: union(enum) { | |
| 77 | 73 | Unresolved, |
| 78 | 74 | Fn: *Value.Fn, |
| 79 | 75 | FnProto: *Value.FnProto, |
| 80 | }; | |
| 76 | }, | |
| 77 | fn_proto: *ast.Node.FnProto, | |
| 81 | 78 | |
| 82 | 79 | pub fn externLibName(self: Fn, tree: *ast.Tree) ?[]const u8 { |
| 83 | 80 | return if (self.fn_proto.extern_export_inline_token) |tok_index| x: { |
src-self-hosted/ir.zig+22-21| ... | ... | @@ -110,7 +110,7 @@ pub const Inst = struct { |
| 110 | 110 | unreachable; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | pub async fn analyze(base: *Inst, ira: *Analyze) Analyze.Error!*Inst { | |
| 113 | pub fn analyze(base: *Inst, ira: *Analyze) Analyze.Error!*Inst { | |
| 114 | 114 | switch (base.id) { |
| 115 | 115 | .Return => return @fieldParentPtr(Return, "base", base).analyze(ira), |
| 116 | 116 | .Const => return @fieldParentPtr(Const, "base", base).analyze(ira), |
| ... | ... | @@ -422,7 +422,7 @@ pub const Inst = struct { |
| 422 | 422 | return false; |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | pub async fn analyze(self: *const Ref, ira: *Analyze) !*Inst { | |
| 425 | pub fn analyze(self: *const Ref, ira: *Analyze) !*Inst { | |
| 426 | 426 | const target = try self.params.target.getAsParam(); |
| 427 | 427 | |
| 428 | 428 | if (ira.getCompTimeValOrNullUndefOk(target)) |val| { |
| ... | ... | @@ -472,7 +472,7 @@ pub const Inst = struct { |
| 472 | 472 | return false; |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | pub async fn analyze(self: *const DeclRef, ira: *Analyze) !*Inst { | |
| 475 | pub fn analyze(self: *const DeclRef, ira: *Analyze) !*Inst { | |
| 476 | 476 | (ira.irb.comp.resolveDecl(self.params.decl)) catch |err| switch (err) { |
| 477 | 477 | error.OutOfMemory => return error.OutOfMemory, |
| 478 | 478 | else => return error.SemanticAnalysisFailed, |
| ... | ... | @@ -516,7 +516,7 @@ pub const Inst = struct { |
| 516 | 516 | return false; |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | pub async fn analyze(self: *const VarPtr, ira: *Analyze) !*Inst { | |
| 519 | pub fn analyze(self: *const VarPtr, ira: *Analyze) !*Inst { | |
| 520 | 520 | switch (self.params.var_scope.data) { |
| 521 | 521 | .Const => @panic("TODO"), |
| 522 | 522 | .Param => |param| { |
| ... | ... | @@ -563,7 +563,7 @@ pub const Inst = struct { |
| 563 | 563 | return false; |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | pub async fn analyze(self: *const LoadPtr, ira: *Analyze) !*Inst { | |
| 566 | pub fn analyze(self: *const LoadPtr, ira: *Analyze) !*Inst { | |
| 567 | 567 | const target = try self.params.target.getAsParam(); |
| 568 | 568 | const target_type = target.getKnownType(); |
| 569 | 569 | if (target_type.id != .Pointer) { |
| ... | ... | @@ -645,7 +645,7 @@ pub const Inst = struct { |
| 645 | 645 | return false; |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | pub async fn analyze(self: *const PtrType, ira: *Analyze) !*Inst { | |
| 648 | pub fn analyze(self: *const PtrType, ira: *Analyze) !*Inst { | |
| 649 | 649 | const child_type = try self.params.child_type.getAsConstType(ira); |
| 650 | 650 | // if (child_type->id == TypeTableEntryIdUnreachable) { |
| 651 | 651 | // ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed")); |
| ... | ... | @@ -927,7 +927,7 @@ pub const Variable = struct { |
| 927 | 927 | |
| 928 | 928 | pub const BasicBlock = struct { |
| 929 | 929 | ref_count: usize, |
| 930 | name_hint: [*]const u8, // must be a C string literal | |
| 930 | name_hint: [*:0]const u8, | |
| 931 | 931 | debug_id: usize, |
| 932 | 932 | scope: *Scope, |
| 933 | 933 | instruction_list: std.ArrayList(*Inst), |
| ... | ... | @@ -1051,7 +1051,7 @@ pub const Builder = struct { |
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | /// No need to clean up resources thanks to the arena allocator. |
| 1054 | pub fn createBasicBlock(self: *Builder, scope: *Scope, name_hint: [*]const u8) !*BasicBlock { | |
| 1054 | pub fn createBasicBlock(self: *Builder, scope: *Scope, name_hint: [*:0]const u8) !*BasicBlock { | |
| 1055 | 1055 | const basic_block = try self.arena().create(BasicBlock); |
| 1056 | 1056 | basic_block.* = BasicBlock{ |
| 1057 | 1057 | .ref_count = 0, |
| ... | ... | @@ -1186,6 +1186,7 @@ pub const Builder = struct { |
| 1186 | 1186 | } |
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | fn genCall(irb: *Builder, suffix_op: *ast.Node.SuffixOp, call: *ast.Node.SuffixOp.Op.Call, scope: *Scope) !*Inst { | |
| 1189 | 1190 | async fn genCall(irb: *Builder, suffix_op: *ast.Node.SuffixOp, call: *ast.Node.SuffixOp.Op.Call, scope: *Scope) !*Inst { |
| 1190 | 1191 | const fn_ref = try irb.genNode(suffix_op.lhs, scope, .None); |
| 1191 | 1192 | |
| ... | ... | @@ -1214,7 +1215,7 @@ pub const Builder = struct { |
| 1214 | 1215 | //return ir_lval_wrap(irb, scope, fn_call, lval); |
| 1215 | 1216 | } |
| 1216 | 1217 | |
| 1217 | async fn genPtrType( | |
| 1218 | fn genPtrType( | |
| 1218 | 1219 | irb: *Builder, |
| 1219 | 1220 | prefix_op: *ast.Node.PrefixOp, |
| 1220 | 1221 | ptr_info: ast.Node.PrefixOp.PtrInfo, |
| ... | ... | @@ -1307,9 +1308,9 @@ pub const Builder = struct { |
| 1307 | 1308 | var rest: []const u8 = undefined; |
| 1308 | 1309 | if (int_token.len >= 3 and int_token[0] == '0') { |
| 1309 | 1310 | base = switch (int_token[1]) { |
| 1310 | 'b' => u8(2), | |
| 1311 | 'o' => u8(8), | |
| 1312 | 'x' => u8(16), | |
| 1311 | 'b' => 2, | |
| 1312 | 'o' => 8, | |
| 1313 | 'x' => 16, | |
| 1313 | 1314 | else => unreachable, |
| 1314 | 1315 | }; |
| 1315 | 1316 | rest = int_token[2..]; |
| ... | ... | @@ -1339,7 +1340,7 @@ pub const Builder = struct { |
| 1339 | 1340 | return inst; |
| 1340 | 1341 | } |
| 1341 | 1342 | |
| 1342 | pub async fn genStrLit(irb: *Builder, str_lit: *ast.Node.StringLiteral, scope: *Scope) !*Inst { | |
| 1343 | pub fn genStrLit(irb: *Builder, str_lit: *ast.Node.StringLiteral, scope: *Scope) !*Inst { | |
| 1343 | 1344 | const str_token = irb.code.tree_scope.tree.tokenSlice(str_lit.token); |
| 1344 | 1345 | const src_span = Span.token(str_lit.token); |
| 1345 | 1346 | |
| ... | ... | @@ -1389,7 +1390,7 @@ pub const Builder = struct { |
| 1389 | 1390 | } |
| 1390 | 1391 | } |
| 1391 | 1392 | |
| 1392 | pub async fn genBlock(irb: *Builder, block: *ast.Node.Block, parent_scope: *Scope) !*Inst { | |
| 1393 | pub fn genBlock(irb: *Builder, block: *ast.Node.Block, parent_scope: *Scope) !*Inst { | |
| 1393 | 1394 | const block_scope = try Scope.Block.create(irb.comp, parent_scope); |
| 1394 | 1395 | |
| 1395 | 1396 | const outer_block_scope = &block_scope.base; |
| ... | ... | @@ -1499,7 +1500,7 @@ pub const Builder = struct { |
| 1499 | 1500 | return irb.buildConstVoid(child_scope, Span.token(block.rbrace), true); |
| 1500 | 1501 | } |
| 1501 | 1502 | |
| 1502 | pub async fn genControlFlowExpr( | |
| 1503 | pub fn genControlFlowExpr( | |
| 1503 | 1504 | irb: *Builder, |
| 1504 | 1505 | control_flow_expr: *ast.Node.ControlFlowExpression, |
| 1505 | 1506 | scope: *Scope, |
| ... | ... | @@ -1596,7 +1597,7 @@ pub const Builder = struct { |
| 1596 | 1597 | } |
| 1597 | 1598 | } |
| 1598 | 1599 | |
| 1599 | pub async fn genIdentifier(irb: *Builder, identifier: *ast.Node.Identifier, scope: *Scope, lval: LVal) !*Inst { | |
| 1600 | pub fn genIdentifier(irb: *Builder, identifier: *ast.Node.Identifier, scope: *Scope, lval: LVal) !*Inst { | |
| 1600 | 1601 | const src_span = Span.token(identifier.token); |
| 1601 | 1602 | const name = irb.code.tree_scope.tree.tokenSlice(identifier.token); |
| 1602 | 1603 | |
| ... | ... | @@ -1694,7 +1695,7 @@ pub const Builder = struct { |
| 1694 | 1695 | return result; |
| 1695 | 1696 | } |
| 1696 | 1697 | |
| 1697 | async fn genDefersForBlock( | |
| 1698 | fn genDefersForBlock( | |
| 1698 | 1699 | irb: *Builder, |
| 1699 | 1700 | inner_scope: *Scope, |
| 1700 | 1701 | outer_scope: *Scope, |
| ... | ... | @@ -1797,7 +1798,7 @@ pub const Builder = struct { |
| 1797 | 1798 | // Look at the params and ref() other instructions |
| 1798 | 1799 | comptime var i = 0; |
| 1799 | 1800 | inline while (i < @memberCount(I.Params)) : (i += 1) { |
| 1800 | const FieldType = comptime @typeOf(@field(I.Params(undefined), @memberName(I.Params, i))); | |
| 1801 | const FieldType = comptime @typeOf(@field(@as(I.Params, undefined), @memberName(I.Params, i))); | |
| 1801 | 1802 | switch (FieldType) { |
| 1802 | 1803 | *Inst => @field(inst.params, @memberName(I.Params, i)).ref(self), |
| 1803 | 1804 | *BasicBlock => @field(inst.params, @memberName(I.Params, i)).ref(self), |
| ... | ... | @@ -1909,7 +1910,7 @@ pub const Builder = struct { |
| 1909 | 1910 | VarScope: *Scope.Var, |
| 1910 | 1911 | }; |
| 1911 | 1912 | |
| 1912 | async fn findIdent(irb: *Builder, scope: *Scope, name: []const u8) Ident { | |
| 1913 | fn findIdent(irb: *Builder, scope: *Scope, name: []const u8) Ident { | |
| 1913 | 1914 | var s = scope; |
| 1914 | 1915 | while (true) { |
| 1915 | 1916 | switch (s.id) { |
| ... | ... | @@ -2519,7 +2520,7 @@ const Analyze = struct { |
| 2519 | 2520 | } |
| 2520 | 2521 | }; |
| 2521 | 2522 | |
| 2522 | pub async fn gen( | |
| 2523 | pub fn gen( | |
| 2523 | 2524 | comp: *Compilation, |
| 2524 | 2525 | body_node: *ast.Node, |
| 2525 | 2526 | tree_scope: *Scope.AstTree, |
| ... | ... | @@ -2541,7 +2542,7 @@ pub async fn gen( |
| 2541 | 2542 | return irb.finish(); |
| 2542 | 2543 | } |
| 2543 | 2544 | |
| 2544 | pub async fn analyze(comp: *Compilation, old_code: *Code, expected_type: ?*Type) !*Code { | |
| 2545 | pub fn analyze(comp: *Compilation, old_code: *Code, expected_type: ?*Type) !*Code { | |
| 2545 | 2546 | const old_entry_bb = old_code.basic_block_list.at(0); |
| 2546 | 2547 | |
| 2547 | 2548 | var ira = try Analyze.init(comp, old_code.tree_scope, expected_type); |
src-self-hosted/libc_installation.zig+2-2| ... | ... | @@ -143,7 +143,7 @@ pub const LibCInstallation = struct { |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /// Finds the default, native libc. |
| 146 | pub async fn findNative(self: *LibCInstallation, allocator: *Allocator) !void { | |
| 146 | pub fn findNative(self: *LibCInstallation, allocator: *Allocator) !void { | |
| 147 | 147 | self.initEmpty(); |
| 148 | 148 | var group = event.Group(FindError!void).init(allocator); |
| 149 | 149 | errdefer group.wait() catch {}; |
| ... | ... | @@ -393,7 +393,7 @@ pub const LibCInstallation = struct { |
| 393 | 393 | }; |
| 394 | 394 | |
| 395 | 395 | /// caller owns returned memory |
| 396 | async fn ccPrintFileName(allocator: *Allocator, o_file: []const u8, want_dirname: bool) ![]u8 { | |
| 396 | fn ccPrintFileName(allocator: *Allocator, o_file: []const u8, want_dirname: bool) ![]u8 { | |
| 397 | 397 | const cc_exe = std.os.getenv("CC") orelse "cc"; |
| 398 | 398 | const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={}", o_file); |
| 399 | 399 | defer allocator.free(arg1); |
src-self-hosted/link.zig+26-29| ... | ... | @@ -11,7 +11,7 @@ const util = @import("util.zig"); |
| 11 | 11 | const Context = struct { |
| 12 | 12 | comp: *Compilation, |
| 13 | 13 | arena: std.heap.ArenaAllocator, |
| 14 | args: std.ArrayList([*]const u8), | |
| 14 | args: std.ArrayList([*:0]const u8), | |
| 15 | 15 | link_in_crt: bool, |
| 16 | 16 | |
| 17 | 17 | link_err: error{OutOfMemory}!void, |
| ... | ... | @@ -21,7 +21,7 @@ const Context = struct { |
| 21 | 21 | out_file_path: std.Buffer, |
| 22 | 22 | }; |
| 23 | 23 | |
| 24 | pub async fn link(comp: *Compilation) !void { | |
| 24 | pub fn link(comp: *Compilation) !void { | |
| 25 | 25 | var ctx = Context{ |
| 26 | 26 | .comp = comp, |
| 27 | 27 | .arena = std.heap.ArenaAllocator.init(comp.gpa()), |
| ... | ... | @@ -33,7 +33,7 @@ pub async fn link(comp: *Compilation) !void { |
| 33 | 33 | .out_file_path = undefined, |
| 34 | 34 | }; |
| 35 | 35 | defer ctx.arena.deinit(); |
| 36 | ctx.args = std.ArrayList([*]const u8).init(&ctx.arena.allocator); | |
| 36 | ctx.args = std.ArrayList([*:0]const u8).init(&ctx.arena.allocator); | |
| 37 | 37 | ctx.link_msg = std.Buffer.initNull(&ctx.arena.allocator); |
| 38 | 38 | |
| 39 | 39 | if (comp.link_out_file) |out_file| { |
| ... | ... | @@ -171,7 +171,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void { |
| 171 | 171 | //} |
| 172 | 172 | |
| 173 | 173 | try ctx.args.append("-o"); |
| 174 | try ctx.args.append(ctx.out_file_path.ptr()); | |
| 174 | try ctx.args.append(ctx.out_file_path.toSliceConst()); | |
| 175 | 175 | |
| 176 | 176 | if (ctx.link_in_crt) { |
| 177 | 177 | const crt1o = if (ctx.comp.is_static) "crt1.o" else "Scrt1.o"; |
| ... | ... | @@ -214,10 +214,11 @@ fn constructLinkerArgsElf(ctx: *Context) !void { |
| 214 | 214 | |
| 215 | 215 | if (ctx.comp.haveLibC()) { |
| 216 | 216 | try ctx.args.append("-L"); |
| 217 | try ctx.args.append((try std.cstr.addNullByte(&ctx.arena.allocator, ctx.libc.lib_dir.?)).ptr); | |
| 217 | // TODO addNullByte should probably return [:0]u8 | |
| 218 | try ctx.args.append(@ptrCast([*:0]const u8, (try std.cstr.addNullByte(&ctx.arena.allocator, ctx.libc.lib_dir.?)).ptr)); | |
| 218 | 219 | |
| 219 | 220 | try ctx.args.append("-L"); |
| 220 | try ctx.args.append((try std.cstr.addNullByte(&ctx.arena.allocator, ctx.libc.static_lib_dir.?)).ptr); | |
| 221 | try ctx.args.append(@ptrCast([*:0]const u8, (try std.cstr.addNullByte(&ctx.arena.allocator, ctx.libc.static_lib_dir.?)).ptr)); | |
| 221 | 222 | |
| 222 | 223 | if (!ctx.comp.is_static) { |
| 223 | 224 | const dl = blk: { |
| ... | ... | @@ -226,7 +227,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void { |
| 226 | 227 | return error.LibCMissingDynamicLinker; |
| 227 | 228 | }; |
| 228 | 229 | try ctx.args.append("-dynamic-linker"); |
| 229 | try ctx.args.append((try std.cstr.addNullByte(&ctx.arena.allocator, dl)).ptr); | |
| 230 | try ctx.args.append(@ptrCast([*:0]const u8, (try std.cstr.addNullByte(&ctx.arena.allocator, dl)).ptr)); | |
| 230 | 231 | } |
| 231 | 232 | } |
| 232 | 233 | |
| ... | ... | @@ -238,7 +239,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void { |
| 238 | 239 | // .o files |
| 239 | 240 | for (ctx.comp.link_objects) |link_object| { |
| 240 | 241 | const link_obj_with_null = try std.cstr.addNullByte(&ctx.arena.allocator, link_object); |
| 241 | try ctx.args.append(link_obj_with_null.ptr); | |
| 242 | try ctx.args.append(@ptrCast([*:0]const u8, link_obj_with_null.ptr)); | |
| 242 | 243 | } |
| 243 | 244 | try addFnObjects(ctx); |
| 244 | 245 | |
| ... | ... | @@ -313,7 +314,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void { |
| 313 | 314 | fn addPathJoin(ctx: *Context, dirname: []const u8, basename: []const u8) !void { |
| 314 | 315 | const full_path = try std.fs.path.join(&ctx.arena.allocator, [_][]const u8{ dirname, basename }); |
| 315 | 316 | const full_path_with_null = try std.cstr.addNullByte(&ctx.arena.allocator, full_path); |
| 316 | try ctx.args.append(full_path_with_null.ptr); | |
| 317 | try ctx.args.append(@ptrCast([*:0]const u8, full_path_with_null.ptr)); | |
| 317 | 318 | } |
| 318 | 319 | |
| 319 | 320 | fn constructLinkerArgsCoff(ctx: *Context) !void { |
| ... | ... | @@ -339,12 +340,12 @@ fn constructLinkerArgsCoff(ctx: *Context) !void { |
| 339 | 340 | const is_library = ctx.comp.kind == .Lib; |
| 340 | 341 | |
| 341 | 342 | const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", ctx.out_file_path.toSliceConst()); |
| 342 | try ctx.args.append(out_arg.ptr); | |
| 343 | try ctx.args.append(@ptrCast([*:0]const u8, out_arg.ptr)); | |
| 343 | 344 | |
| 344 | 345 | if (ctx.comp.haveLibC()) { |
| 345 | try ctx.args.append((try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.msvc_lib_dir.?)).ptr); | |
| 346 | try ctx.args.append((try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.kernel32_lib_dir.?)).ptr); | |
| 347 | try ctx.args.append((try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.lib_dir.?)).ptr); | |
| 346 | try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.msvc_lib_dir.?)).ptr)); | |
| 347 | try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.kernel32_lib_dir.?)).ptr)); | |
| 348 | try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.lib_dir.?)).ptr)); | |
| 348 | 349 | } |
| 349 | 350 | |
| 350 | 351 | if (ctx.link_in_crt) { |
| ... | ... | @@ -353,17 +354,17 @@ fn constructLinkerArgsCoff(ctx: *Context) !void { |
| 353 | 354 | |
| 354 | 355 | if (ctx.comp.is_static) { |
| 355 | 356 | const cmt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "libcmt{}.lib\x00", d_str); |
| 356 | try ctx.args.append(cmt_lib_name.ptr); | |
| 357 | try ctx.args.append(@ptrCast([*:0]const u8, cmt_lib_name.ptr)); | |
| 357 | 358 | } else { |
| 358 | 359 | const msvcrt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "msvcrt{}.lib\x00", d_str); |
| 359 | try ctx.args.append(msvcrt_lib_name.ptr); | |
| 360 | try ctx.args.append(@ptrCast([*:0]const u8, msvcrt_lib_name.ptr)); | |
| 360 | 361 | } |
| 361 | 362 | |
| 362 | 363 | const vcruntime_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}vcruntime{}.lib\x00", lib_str, d_str); |
| 363 | try ctx.args.append(vcruntime_lib_name.ptr); | |
| 364 | try ctx.args.append(@ptrCast([*:0]const u8, vcruntime_lib_name.ptr)); | |
| 364 | 365 | |
| 365 | 366 | const crt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}ucrt{}.lib\x00", lib_str, d_str); |
| 366 | try ctx.args.append(crt_lib_name.ptr); | |
| 367 | try ctx.args.append(@ptrCast([*:0]const u8, crt_lib_name.ptr)); | |
| 367 | 368 | |
| 368 | 369 | // Visual C++ 2015 Conformance Changes |
| 369 | 370 | // https://msdn.microsoft.com/en-us/library/bb531344.aspx |
| ... | ... | @@ -395,7 +396,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void { |
| 395 | 396 | |
| 396 | 397 | for (ctx.comp.link_objects) |link_object| { |
| 397 | 398 | const link_obj_with_null = try std.cstr.addNullByte(&ctx.arena.allocator, link_object); |
| 398 | try ctx.args.append(link_obj_with_null.ptr); | |
| 399 | try ctx.args.append(@ptrCast([*:0]const u8, link_obj_with_null.ptr)); | |
| 399 | 400 | } |
| 400 | 401 | try addFnObjects(ctx); |
| 401 | 402 | |
| ... | ... | @@ -504,11 +505,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 504 | 505 | //} |
| 505 | 506 | |
| 506 | 507 | try ctx.args.append("-arch"); |
| 507 | const darwin_arch_str = try std.cstr.addNullByte( | |
| 508 | &ctx.arena.allocator, | |
| 509 | ctx.comp.target.getDarwinArchString(), | |
| 510 | ); | |
| 511 | try ctx.args.append(darwin_arch_str.ptr); | |
| 508 | try ctx.args.append(util.getDarwinArchString(ctx.comp.target)); | |
| 512 | 509 | |
| 513 | 510 | const platform = try DarwinPlatform.get(ctx.comp); |
| 514 | 511 | switch (platform.kind) { |
| ... | ... | @@ -517,7 +514,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 517 | 514 | .IPhoneOSSimulator => try ctx.args.append("-ios_simulator_version_min"), |
| 518 | 515 | } |
| 519 | 516 | const ver_str = try std.fmt.allocPrint(&ctx.arena.allocator, "{}.{}.{}\x00", platform.major, platform.minor, platform.micro); |
| 520 | try ctx.args.append(ver_str.ptr); | |
| 517 | try ctx.args.append(@ptrCast([*:0]const u8, ver_str.ptr)); | |
| 521 | 518 | |
| 522 | 519 | if (ctx.comp.kind == .Exe) { |
| 523 | 520 | if (ctx.comp.is_static) { |
| ... | ... | @@ -528,7 +525,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 528 | 525 | } |
| 529 | 526 | |
| 530 | 527 | try ctx.args.append("-o"); |
| 531 | try ctx.args.append(ctx.out_file_path.ptr()); | |
| 528 | try ctx.args.append(ctx.out_file_path.toSliceConst()); | |
| 532 | 529 | |
| 533 | 530 | //for (size_t i = 0; i < g->rpath_list.length; i += 1) { |
| 534 | 531 | // Buf *rpath = g->rpath_list.at(i); |
| ... | ... | @@ -572,7 +569,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 572 | 569 | |
| 573 | 570 | for (ctx.comp.link_objects) |link_object| { |
| 574 | 571 | const link_obj_with_null = try std.cstr.addNullByte(&ctx.arena.allocator, link_object); |
| 575 | try ctx.args.append(link_obj_with_null.ptr); | |
| 572 | try ctx.args.append(@ptrCast([*:0]const u8, link_obj_with_null.ptr)); | |
| 576 | 573 | } |
| 577 | 574 | try addFnObjects(ctx); |
| 578 | 575 | |
| ... | ... | @@ -593,10 +590,10 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 593 | 590 | } else { |
| 594 | 591 | if (mem.indexOfScalar(u8, lib.name, '/') == null) { |
| 595 | 592 | const arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-l{}\x00", lib.name); |
| 596 | try ctx.args.append(arg.ptr); | |
| 593 | try ctx.args.append(@ptrCast([*:0]const u8, arg.ptr)); | |
| 597 | 594 | } else { |
| 598 | 595 | const arg = try std.cstr.addNullByte(&ctx.arena.allocator, lib.name); |
| 599 | try ctx.args.append(arg.ptr); | |
| 596 | try ctx.args.append(@ptrCast([*:0]const u8, arg.ptr)); | |
| 600 | 597 | } |
| 601 | 598 | } |
| 602 | 599 | } |
| ... | ... | @@ -639,7 +636,7 @@ fn addFnObjects(ctx: *Context) !void { |
| 639 | 636 | ctx.comp.gpa().destroy(node); |
| 640 | 637 | continue; |
| 641 | 638 | }; |
| 642 | try ctx.args.append(fn_val.containing_object.ptr()); | |
| 639 | try ctx.args.append(fn_val.containing_object.toSliceConst()); | |
| 643 | 640 | it = node.next; |
| 644 | 641 | } |
| 645 | 642 | } |
src-self-hosted/llvm.zig+1-1| ... | ... | @@ -86,7 +86,7 @@ pub const AddGlobal = LLVMAddGlobal; |
| 86 | 86 | extern fn LLVMAddGlobal(M: *Module, Ty: *Type, Name: [*:0]const u8) ?*Value; |
| 87 | 87 | |
| 88 | 88 | pub const ConstStringInContext = LLVMConstStringInContext; |
| 89 | extern fn LLVMConstStringInContext(C: *Context, Str: [*:0]const u8, Length: c_uint, DontNullTerminate: Bool) ?*Value; | |
| 89 | extern fn LLVMConstStringInContext(C: *Context, Str: [*]const u8, Length: c_uint, DontNullTerminate: Bool) ?*Value; | |
| 90 | 90 | |
| 91 | 91 | pub const ConstInt = LLVMConstInt; |
| 92 | 92 | extern fn LLVMConstInt(IntTy: *Type, N: c_ulonglong, SignExtend: Bool) ?*Value; |
src-self-hosted/main.zig+49-65| ... | ... | @@ -126,7 +126,8 @@ pub fn main() !void { |
| 126 | 126 | |
| 127 | 127 | try stderr.print("unknown command: {}\n\n", args[1]); |
| 128 | 128 | try stderr.write(usage); |
| 129 | process.exit(1); | |
| 129 | process.argsFree(allocator, args); | |
| 130 | defer process.exit(1); | |
| 130 | 131 | } |
| 131 | 132 | |
| 132 | 133 | const usage_build_generic = |
| ... | ... | @@ -461,13 +462,12 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co |
| 461 | 462 | comp.link_objects = link_objects; |
| 462 | 463 | |
| 463 | 464 | comp.start(); |
| 464 | const frame = async processBuildEvents(comp, color); | |
| 465 | processBuildEvents(comp, color); | |
| 465 | 466 | } |
| 466 | 467 | |
| 467 | async fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void { | |
| 468 | fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void { | |
| 468 | 469 | var count: usize = 0; |
| 469 | while (true) { | |
| 470 | // TODO directly awaiting async should guarantee memory allocation elision | |
| 470 | while (true) { // TODO(Vexu) | |
| 471 | 471 | const build_event = comp.events.get(); |
| 472 | 472 | count += 1; |
| 473 | 473 | |
| ... | ... | @@ -567,10 +567,6 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void { |
| 567 | 567 | var zig_compiler = try ZigCompiler.init(allocator); |
| 568 | 568 | defer zig_compiler.deinit(); |
| 569 | 569 | |
| 570 | const frame = async findLibCAsync(&zig_compiler); | |
| 571 | } | |
| 572 | ||
| 573 | async fn findLibCAsync(zig_compiler: *ZigCompiler) void { | |
| 574 | 570 | const libc = zig_compiler.getNativeLibC() catch |err| { |
| 575 | 571 | stderr.print("unable to find libc: {}\n", @errorName(err)) catch process.exit(1); |
| 576 | 572 | process.exit(1); |
| ... | ... | @@ -644,11 +640,23 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { |
| 644 | 640 | process.exit(1); |
| 645 | 641 | } |
| 646 | 642 | |
| 647 | return asyncFmtMain( | |
| 648 | allocator, | |
| 649 | &flags, | |
| 650 | color, | |
| 651 | ); | |
| 643 | var fmt = Fmt{ | |
| 644 | .allocator = allocator, | |
| 645 | .seen = event.Locked(Fmt.SeenMap).init(Fmt.SeenMap.init(allocator)), | |
| 646 | .any_error = false, | |
| 647 | .color = color, | |
| 648 | }; | |
| 649 | ||
| 650 | const check_mode = flags.present("check"); | |
| 651 | ||
| 652 | var group = event.Group(FmtError!void).init(allocator); | |
| 653 | for (flags.positionals.toSliceConst()) |file_path| { | |
| 654 | try group.call(fmtPath, &fmt, file_path, check_mode); | |
| 655 | } | |
| 656 | try group.wait(); | |
| 657 | if (fmt.any_error) { | |
| 658 | process.exit(1); | |
| 659 | } | |
| 652 | 660 | } |
| 653 | 661 | |
| 654 | 662 | const FmtError = error{ |
| ... | ... | @@ -673,30 +681,6 @@ const FmtError = error{ |
| 673 | 681 | CurrentWorkingDirectoryUnlinked, |
| 674 | 682 | } || fs.File.OpenError; |
| 675 | 683 | |
| 676 | async fn asyncFmtMain( | |
| 677 | allocator: *Allocator, | |
| 678 | flags: *const Args, | |
| 679 | color: errmsg.Color, | |
| 680 | ) FmtError!void { | |
| 681 | var fmt = Fmt{ | |
| 682 | .allocator = allocator, | |
| 683 | .seen = event.Locked(Fmt.SeenMap).init(Fmt.SeenMap.init(allocator)), | |
| 684 | .any_error = false, | |
| 685 | .color = color, | |
| 686 | }; | |
| 687 | ||
| 688 | const check_mode = flags.present("check"); | |
| 689 | ||
| 690 | var group = event.Group(FmtError!void).init(allocator); | |
| 691 | for (flags.positionals.toSliceConst()) |file_path| { | |
| 692 | try group.call(fmtPath, &fmt, file_path, check_mode); | |
| 693 | } | |
| 694 | try group.wait(); | |
| 695 | if (fmt.any_error) { | |
| 696 | process.exit(1); | |
| 697 | } | |
| 698 | } | |
| 699 | ||
| 700 | 684 | async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void { |
| 701 | 685 | const file_path = try std.mem.dupe(fmt.allocator, u8, file_path_ref); |
| 702 | 686 | defer fmt.allocator.free(file_path); |
| ... | ... | @@ -708,33 +692,33 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro |
| 708 | 692 | if (try held.value.put(file_path, {})) |_| return; |
| 709 | 693 | } |
| 710 | 694 | |
| 711 | const source_code = ""; | |
| 712 | // const source_code = event.fs.readFile( | |
| 713 | // file_path, | |
| 714 | // max_src_size, | |
| 715 | // ) catch |err| switch (err) { | |
| 716 | // error.IsDir, error.AccessDenied => { | |
| 717 | // // TODO make event based (and dir.next()) | |
| 718 | // var dir = try fs.Dir.cwd().openDirList(file_path); | |
| 719 | // defer dir.close(); | |
| 720 | ||
| 721 | // var group = event.Group(FmtError!void).init(fmt.allocator); | |
| 722 | // while (try dir.next()) |entry| { | |
| 723 | // if (entry.kind == fs.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) { | |
| 724 | // const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name }); | |
| 725 | // try group.call(fmtPath, fmt, full_path, check_mode); | |
| 726 | // } | |
| 727 | // } | |
| 728 | // return group.wait(); | |
| 729 | // }, | |
| 730 | // else => { | |
| 731 | // // TODO lock stderr printing | |
| 732 | // try stderr.print("unable to open '{}': {}\n", file_path, err); | |
| 733 | // fmt.any_error = true; | |
| 734 | // return; | |
| 735 | // }, | |
| 736 | // }; | |
| 737 | // defer fmt.allocator.free(source_code); | |
| 695 | const source_code = event.fs.readFile( | |
| 696 | fmt.allocator, | |
| 697 | file_path, | |
| 698 | max_src_size, | |
| 699 | ) catch |err| switch (err) { | |
| 700 | error.IsDir, error.AccessDenied => { | |
| 701 | var dir = try fs.Dir.cwd().openDirList(file_path); | |
| 702 | defer dir.close(); | |
| 703 | ||
| 704 | var group = event.Group(FmtError!void).init(fmt.allocator); | |
| 705 | var it = dir.iterate(); | |
| 706 | while (try it.next()) |entry| { | |
| 707 | if (entry.kind == .Directory or mem.endsWith(u8, entry.name, ".zig")) { | |
| 708 | const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name }); | |
| 709 | try group.call(fmtPath, fmt, full_path, check_mode); | |
| 710 | } | |
| 711 | } | |
| 712 | return group.wait(); | |
| 713 | }, | |
| 714 | else => { | |
| 715 | // TODO lock stderr printing | |
| 716 | try stderr.print("unable to open '{}': {}\n", file_path, err); | |
| 717 | fmt.any_error = true; | |
| 718 | return; | |
| 719 | }, | |
| 720 | }; | |
| 721 | defer fmt.allocator.free(source_code); | |
| 738 | 722 | |
| 739 | 723 | const tree = std.zig.parse(fmt.allocator, source_code) catch |err| { |
| 740 | 724 | try stderr.print("error parsing file '{}': {}\n", file_path, err); |
src-self-hosted/test.zig+4-7| ... | ... | @@ -116,7 +116,7 @@ pub const TestContext = struct { |
| 116 | 116 | const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.incr()); |
| 117 | 117 | const file1_path = try std.fs.path.join(allocator, [_][]const u8{ tmp_dir_name, file_index, file1 }); |
| 118 | 118 | |
| 119 | const output_file = try std.fmt.allocPrint(allocator, "{}-out{}", file1_path, (Target{.Native = {}}).exeFileExt()); | |
| 119 | const output_file = try std.fmt.allocPrint(allocator, "{}-out{}", file1_path, (Target{ .Native = {} }).exeFileExt()); | |
| 120 | 120 | if (std.fs.path.dirname(file1_path)) |dirname| { |
| 121 | 121 | try std.fs.makePath(allocator, dirname); |
| 122 | 122 | } |
| ... | ... | @@ -148,15 +148,12 @@ pub const TestContext = struct { |
| 148 | 148 | exe_file: []const u8, |
| 149 | 149 | expected_output: []const u8, |
| 150 | 150 | ) anyerror!void { |
| 151 | // TODO this should not be necessary | |
| 152 | const exe_file_2 = try std.mem.dupe(allocator, u8, exe_file); | |
| 153 | ||
| 154 | 151 | defer comp.destroy(); |
| 155 | 152 | const build_event = comp.events.get(); |
| 156 | 153 | |
| 157 | 154 | switch (build_event) { |
| 158 | 155 | .Ok => { |
| 159 | const argv = [_][]const u8{exe_file_2}; | |
| 156 | const argv = [_][]const u8{exe_file}; | |
| 160 | 157 | // TODO use event loop |
| 161 | 158 | const child = try std.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024); |
| 162 | 159 | switch (child.term) { |
| ... | ... | @@ -173,8 +170,8 @@ pub const TestContext = struct { |
| 173 | 170 | return error.OutputMismatch; |
| 174 | 171 | } |
| 175 | 172 | }, |
| 176 | Compilation.Event.Error => |err| return err, | |
| 177 | Compilation.Event.Fail => |msgs| { | |
| 173 | .Error => |err| return err, | |
| 174 | .Fail => |msgs| { | |
| 178 | 175 | const stderr = std.io.getStdErr(); |
| 179 | 176 | try stderr.write("build incorrectly failed:\n"); |
| 180 | 177 | for (msgs) |msg| { |
src-self-hosted/type.zig+11-11| ... | ... | @@ -53,7 +53,7 @@ pub const Type = struct { |
| 53 | 53 | base: *Type, |
| 54 | 54 | allocator: *Allocator, |
| 55 | 55 | llvm_context: *llvm.Context, |
| 56 | ) (error{OutOfMemory}!*llvm.Type) { | |
| 56 | ) error{OutOfMemory}!*llvm.Type { | |
| 57 | 57 | switch (base.id) { |
| 58 | 58 | .Struct => return @fieldParentPtr(Struct, "base", base).getLlvmType(allocator, llvm_context), |
| 59 | 59 | .Fn => return @fieldParentPtr(Fn, "base", base).getLlvmType(allocator, llvm_context), |
| ... | ... | @@ -184,7 +184,7 @@ pub const Type = struct { |
| 184 | 184 | |
| 185 | 185 | /// If you happen to have an llvm context handy, use getAbiAlignmentInContext instead. |
| 186 | 186 | /// Otherwise, this one will grab one from the pool and then release it. |
| 187 | pub async fn getAbiAlignment(base: *Type, comp: *Compilation) !u32 { | |
| 187 | pub fn getAbiAlignment(base: *Type, comp: *Compilation) !u32 { | |
| 188 | 188 | if (base.abi_alignment.start()) |ptr| return ptr.*; |
| 189 | 189 | |
| 190 | 190 | { |
| ... | ... | @@ -200,7 +200,7 @@ pub const Type = struct { |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /// If you have an llvm conext handy, you can use it here. |
| 203 | pub async fn getAbiAlignmentInContext(base: *Type, comp: *Compilation, llvm_context: *llvm.Context) !u32 { | |
| 203 | pub fn getAbiAlignmentInContext(base: *Type, comp: *Compilation, llvm_context: *llvm.Context) !u32 { | |
| 204 | 204 | if (base.abi_alignment.start()) |ptr| return ptr.*; |
| 205 | 205 | |
| 206 | 206 | base.abi_alignment.data = base.resolveAbiAlignment(comp, llvm_context); |
| ... | ... | @@ -209,7 +209,7 @@ pub const Type = struct { |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /// Lower level function that does the work. See getAbiAlignment. |
| 212 | async fn resolveAbiAlignment(base: *Type, comp: *Compilation, llvm_context: *llvm.Context) !u32 { | |
| 212 | fn resolveAbiAlignment(base: *Type, comp: *Compilation, llvm_context: *llvm.Context) !u32 { | |
| 213 | 213 | const llvm_type = try base.getLlvmType(comp.gpa(), llvm_context); |
| 214 | 214 | return @intCast(u32, llvm.ABIAlignmentOfType(comp.target_data_ref, llvm_type)); |
| 215 | 215 | } |
| ... | ... | @@ -367,7 +367,7 @@ pub const Type = struct { |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /// takes ownership of key.Normal.params on success |
| 370 | pub async fn get(comp: *Compilation, key: Key) !*Fn { | |
| 370 | pub fn get(comp: *Compilation, key: Key) !*Fn { | |
| 371 | 371 | { |
| 372 | 372 | const held = comp.fn_type_table.acquire(); |
| 373 | 373 | defer held.release(); |
| ... | ... | @@ -564,7 +564,7 @@ pub const Type = struct { |
| 564 | 564 | return comp.u8_type; |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | pub async fn get(comp: *Compilation, key: Key) !*Int { | |
| 567 | pub fn get(comp: *Compilation, key: Key) !*Int { | |
| 568 | 568 | { |
| 569 | 569 | const held = comp.int_type_table.acquire(); |
| 570 | 570 | defer held.release(); |
| ... | ... | @@ -606,7 +606,7 @@ pub const Type = struct { |
| 606 | 606 | comp.registerGarbage(Int, &self.garbage_node); |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | pub async fn gcDestroy(self: *Int, comp: *Compilation) void { | |
| 609 | pub fn gcDestroy(self: *Int, comp: *Compilation) void { | |
| 610 | 610 | { |
| 611 | 611 | const held = comp.int_type_table.acquire(); |
| 612 | 612 | defer held.release(); |
| ... | ... | @@ -700,7 +700,7 @@ pub const Type = struct { |
| 700 | 700 | comp.registerGarbage(Pointer, &self.garbage_node); |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | pub async fn gcDestroy(self: *Pointer, comp: *Compilation) void { | |
| 703 | pub fn gcDestroy(self: *Pointer, comp: *Compilation) void { | |
| 704 | 704 | { |
| 705 | 705 | const held = comp.ptr_type_table.acquire(); |
| 706 | 706 | defer held.release(); |
| ... | ... | @@ -711,14 +711,14 @@ pub const Type = struct { |
| 711 | 711 | comp.gpa().destroy(self); |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | pub async fn getAlignAsInt(self: *Pointer, comp: *Compilation) u32 { | |
| 714 | pub fn getAlignAsInt(self: *Pointer, comp: *Compilation) u32 { | |
| 715 | 715 | switch (self.key.alignment) { |
| 716 | 716 | .Abi => return self.key.child_type.getAbiAlignment(comp), |
| 717 | 717 | .Override => |alignment| return alignment, |
| 718 | 718 | } |
| 719 | 719 | } |
| 720 | 720 | |
| 721 | pub async fn get( | |
| 721 | pub fn get( | |
| 722 | 722 | comp: *Compilation, |
| 723 | 723 | key: Key, |
| 724 | 724 | ) !*Pointer { |
| ... | ... | @@ -828,7 +828,7 @@ pub const Type = struct { |
| 828 | 828 | comp.gpa().destroy(self); |
| 829 | 829 | } |
| 830 | 830 | |
| 831 | pub async fn get(comp: *Compilation, key: Key) !*Array { | |
| 831 | pub fn get(comp: *Compilation, key: Key) !*Array { | |
| 832 | 832 | key.elem_type.base.ref(); |
| 833 | 833 | errdefer key.elem_type.base.deref(comp); |
| 834 | 834 |
src-self-hosted/util.zig+12-11| ... | ... | @@ -32,21 +32,21 @@ 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 => { | |
| 35 | pub fn getObjectFormat(target: Target) Target.ObjectFormat { | |
| 36 | switch (target) { | |
| 37 | .Native => return @import("builtin").object_format, | |
| 38 | .Cross => blk: { | |
| 39 | 39 | if (target.isWindows() or target.isUefi()) { |
| 40 | break .coff; | |
| 40 | return .coff; | |
| 41 | 41 | } else if (target.isDarwin()) { |
| 42 | break .macho; | |
| 42 | return .macho; | |
| 43 | 43 | } |
| 44 | 44 | if (target.isWasm()) { |
| 45 | break .wasm; | |
| 45 | return .wasm; | |
| 46 | 46 | } |
| 47 | break .elf; | |
| 47 | return .elf; | |
| 48 | 48 | }, |
| 49 | }; | |
| 49 | } | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | pub fn getDynamicLinkerPath(self: Target) ?[]const u8 { |
| ... | ... | @@ -156,7 +156,7 @@ pub fn getDynamicLinkerPath(self: Target) ?[]const u8 { |
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | pub fn getDarwinArchString(self: Target) []const u8 { | |
| 159 | pub fn getDarwinArchString(self: Target) [:0]const u8 { | |
| 160 | 160 | const arch = self.getArch(); |
| 161 | 161 | switch (arch) { |
| 162 | 162 | .aarch64 => return "arm64", |
| ... | ... | @@ -166,7 +166,8 @@ pub fn getDarwinArchString(self: Target) []const u8 { |
| 166 | 166 | .powerpc => return "ppc", |
| 167 | 167 | .powerpc64 => return "ppc64", |
| 168 | 168 | .powerpc64le => return "ppc64le", |
| 169 | else => return @tagName(arch), | |
| 169 | // @tagName should be able to return sentinel terminated slice | |
| 170 | else => @panic("TODO"), //return @tagName(arch), | |
| 170 | 171 | } |
| 171 | 172 | } |
| 172 | 173 |
src-self-hosted/value.zig+6-6| ... | ... | @@ -156,7 +156,7 @@ pub const Value = struct { |
| 156 | 156 | const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 157 | 157 | const llvm_fn = llvm.AddFunction( |
| 158 | 158 | ofile.module, |
| 159 | self.symbol_name.ptr(), | |
| 159 | self.symbol_name.toSliceConst(), | |
| 160 | 160 | llvm_fn_type, |
| 161 | 161 | ) orelse return error.OutOfMemory; |
| 162 | 162 | |
| ... | ... | @@ -241,7 +241,7 @@ pub const Value = struct { |
| 241 | 241 | const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 242 | 242 | const llvm_fn = llvm.AddFunction( |
| 243 | 243 | ofile.module, |
| 244 | self.symbol_name.ptr(), | |
| 244 | self.symbol_name.toSliceConst(), | |
| 245 | 245 | llvm_fn_type, |
| 246 | 246 | ) orelse return error.OutOfMemory; |
| 247 | 247 | |
| ... | ... | @@ -334,7 +334,7 @@ pub const Value = struct { |
| 334 | 334 | field_index: usize, |
| 335 | 335 | }; |
| 336 | 336 | |
| 337 | pub async fn createArrayElemPtr( | |
| 337 | pub fn createArrayElemPtr( | |
| 338 | 338 | comp: *Compilation, |
| 339 | 339 | array_val: *Array, |
| 340 | 340 | mut: Type.Pointer.Mut, |
| ... | ... | @@ -390,13 +390,13 @@ pub const Value = struct { |
| 390 | 390 | const array_llvm_value = (try base_array.val.getLlvmConst(ofile)).?; |
| 391 | 391 | const ptr_bit_count = ofile.comp.target_ptr_bits; |
| 392 | 392 | const usize_llvm_type = llvm.IntTypeInContext(ofile.context, ptr_bit_count) orelse return error.OutOfMemory; |
| 393 | const indices = [_]*llvm.Value{ | |
| 393 | var indices = [_]*llvm.Value{ | |
| 394 | 394 | llvm.ConstNull(usize_llvm_type) orelse return error.OutOfMemory, |
| 395 | 395 | llvm.ConstInt(usize_llvm_type, base_array.elem_index, 0) orelse return error.OutOfMemory, |
| 396 | 396 | }; |
| 397 | 397 | return llvm.ConstInBoundsGEP( |
| 398 | 398 | array_llvm_value, |
| 399 | &indices, | |
| 399 | @ptrCast([*]*llvm.Value, &indices), | |
| 400 | 400 | @intCast(c_uint, indices.len), |
| 401 | 401 | ) orelse return error.OutOfMemory; |
| 402 | 402 | }, |
| ... | ... | @@ -423,7 +423,7 @@ pub const Value = struct { |
| 423 | 423 | }; |
| 424 | 424 | |
| 425 | 425 | /// Takes ownership of buffer |
| 426 | pub async fn createOwnedBuffer(comp: *Compilation, buffer: []u8) !*Array { | |
| 426 | pub fn createOwnedBuffer(comp: *Compilation, buffer: []u8) !*Array { | |
| 427 | 427 | const u8_type = Type.Int.get_u8(comp); |
| 428 | 428 | defer u8_type.base.base.deref(comp); |
| 429 | 429 |