authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-08 23:17:03-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-08 23:17:03-05:00
logfe4963412f939d4f72eb5f0153a253116206749b
tree1ff6242dfa3dccb082e825466202d5289f31f172
parent8b2622cdd58cec697d9d1f8f49717b6ce7ee3e2e
signature Commit is signed but in an unrecognized format.

update self-hosted compiler to new format API


11 files changed, 133 insertions(+), 142 deletions(-)

src-self-hosted/codegen.zig+6-8
...@@ -45,13 +45,11 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)...@@ -45,13 +45,11 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
4545
46 // Don't use ZIG_VERSION_STRING here. LLVM misparses it when it includes46 // Don't use ZIG_VERSION_STRING here. LLVM misparses it when it includes
47 // the git revision.47 // the git revision.
48 const producer = try std.Buffer.allocPrint(48 const producer = try std.Buffer.allocPrint(&code.arena.allocator, "zig {}.{}.{}", .{
49 &code.arena.allocator,
50 "zig {}.{}.{}",
51 @as(u32, c.ZIG_VERSION_MAJOR),49 @as(u32, c.ZIG_VERSION_MAJOR),
52 @as(u32, c.ZIG_VERSION_MINOR),50 @as(u32, c.ZIG_VERSION_MINOR),
53 @as(u32, c.ZIG_VERSION_PATCH),51 @as(u32, c.ZIG_VERSION_PATCH),
54 );52 });
55 const flags = "";53 const flags = "";
56 const runtime_version = 0;54 const runtime_version = 0;
57 const compile_unit_file = llvm.CreateFile(55 const compile_unit_file = llvm.CreateFile(
...@@ -93,7 +91,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)...@@ -93,7 +91,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
93 llvm.DIBuilderFinalize(dibuilder);91 llvm.DIBuilderFinalize(dibuilder);
9492
95 if (comp.verbose_llvm_ir) {93 if (comp.verbose_llvm_ir) {
96 std.debug.warn("raw module:\n");94 std.debug.warn("raw module:\n", .{});
97 llvm.DumpModule(ofile.module);95 llvm.DumpModule(ofile.module);
98 }96 }
9997
...@@ -120,18 +118,18 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)...@@ -120,18 +118,18 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
120 is_small,118 is_small,
121 )) {119 )) {
122 if (std.debug.runtime_safety) {120 if (std.debug.runtime_safety) {
123 std.debug.panic("unable to write object file {}: {s}\n", output_path.toSliceConst(), err_msg);121 std.debug.panic("unable to write object file {}: {s}\n", .{ output_path.toSliceConst(), err_msg });
124 }122 }
125 return error.WritingObjectFileFailed;123 return error.WritingObjectFileFailed;
126 }124 }
127 //validate_inline_fns(g); TODO125 //validate_inline_fns(g); TODO
128 fn_val.containing_object = output_path;126 fn_val.containing_object = output_path;
129 if (comp.verbose_llvm_ir) {127 if (comp.verbose_llvm_ir) {
130 std.debug.warn("optimized module:\n");128 std.debug.warn("optimized module:\n", .{});
131 llvm.DumpModule(ofile.module);129 llvm.DumpModule(ofile.module);
132 }130 }
133 if (comp.verbose_link) {131 if (comp.verbose_link) {
134 std.debug.warn("created {}\n", output_path.toSliceConst());132 std.debug.warn("created {}\n", .{output_path.toSliceConst()});
135 }133 }
136}134}
137135
src-self-hosted/compilation.zig+12-15
...@@ -807,7 +807,7 @@ pub const Compilation = struct {...@@ -807,7 +807,7 @@ pub const Compilation = struct {
807 root_scope.realpath,807 root_scope.realpath,
808 max_src_size,808 max_src_size,
809 ) catch |err| {809 ) catch |err| {
810 try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", @errorName(err));810 try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", .{@errorName(err)});
811 return;811 return;
812 };812 };
813 errdefer self.gpa().free(source_code);813 errdefer self.gpa().free(source_code);
...@@ -878,7 +878,7 @@ pub const Compilation = struct {...@@ -878,7 +878,7 @@ pub const Compilation = struct {
878 try self.addCompileError(tree_scope, Span{878 try self.addCompileError(tree_scope, Span{
879 .first = fn_proto.fn_token,879 .first = fn_proto.fn_token,
880 .last = fn_proto.fn_token + 1,880 .last = fn_proto.fn_token + 1,
881 }, "missing function name");881 }, "missing function name", .{});
882 continue;882 continue;
883 };883 };
884884
...@@ -942,7 +942,7 @@ pub const Compilation = struct {...@@ -942,7 +942,7 @@ pub const Compilation = struct {
942 const root_scope = blk: {942 const root_scope = blk: {
943 // TODO async/await std.fs.realpath943 // TODO async/await std.fs.realpath
944 const root_src_real_path = std.fs.realpathAlloc(self.gpa(), root_src_path) catch |err| {944 const root_src_real_path = std.fs.realpathAlloc(self.gpa(), root_src_path) catch |err| {
945 try self.addCompileErrorCli(root_src_path, "unable to open: {}", @errorName(err));945 try self.addCompileErrorCli(root_src_path, "unable to open: {}", .{@errorName(err)});
946 return;946 return;
947 };947 };
948 errdefer self.gpa().free(root_src_real_path);948 errdefer self.gpa().free(root_src_real_path);
...@@ -991,7 +991,7 @@ pub const Compilation = struct {...@@ -991,7 +991,7 @@ pub const Compilation = struct {
991 defer unanalyzed_code.destroy(comp.gpa());991 defer unanalyzed_code.destroy(comp.gpa());
992992
993 if (comp.verbose_ir) {993 if (comp.verbose_ir) {
994 std.debug.warn("unanalyzed:\n");994 std.debug.warn("unanalyzed:\n", .{});
995 unanalyzed_code.dump();995 unanalyzed_code.dump();
996 }996 }
997997
...@@ -1003,7 +1003,7 @@ pub const Compilation = struct {...@@ -1003,7 +1003,7 @@ pub const Compilation = struct {
1003 errdefer analyzed_code.destroy(comp.gpa());1003 errdefer analyzed_code.destroy(comp.gpa());
10041004
1005 if (comp.verbose_ir) {1005 if (comp.verbose_ir) {
1006 std.debug.warn("analyzed:\n");1006 std.debug.warn("analyzed:\n", .{});
1007 analyzed_code.dump();1007 analyzed_code.dump();
1008 }1008 }
10091009
...@@ -1048,14 +1048,14 @@ pub const Compilation = struct {...@@ -1048,14 +1048,14 @@ pub const Compilation = struct {
10481048
1049 const gop = try locked_table.getOrPut(decl.name);1049 const gop = try locked_table.getOrPut(decl.name);
1050 if (gop.found_existing) {1050 if (gop.found_existing) {
1051 try self.addCompileError(decl.tree_scope, decl.getSpan(), "redefinition of '{}'", decl.name);1051 try self.addCompileError(decl.tree_scope, decl.getSpan(), "redefinition of '{}'", .{decl.name});
1052 // TODO note: other definition here1052 // TODO note: other definition here
1053 } else {1053 } else {
1054 gop.kv.value = decl;1054 gop.kv.value = decl;
1055 }1055 }
1056 }1056 }
10571057
1058 fn addCompileError(self: *Compilation, tree_scope: *Scope.AstTree, span: Span, comptime fmt: []const u8, args: ...) !void {1058 fn addCompileError(self: *Compilation, tree_scope: *Scope.AstTree, span: Span, comptime fmt: []const u8, args: var) !void {
1059 const text = try std.fmt.allocPrint(self.gpa(), fmt, args);1059 const text = try std.fmt.allocPrint(self.gpa(), fmt, args);
1060 errdefer self.gpa().free(text);1060 errdefer self.gpa().free(text);
10611061
...@@ -1065,7 +1065,7 @@ pub const Compilation = struct {...@@ -1065,7 +1065,7 @@ pub const Compilation = struct {
1065 try self.prelink_group.call(addCompileErrorAsync, self, msg);1065 try self.prelink_group.call(addCompileErrorAsync, self, msg);
1066 }1066 }
10671067
1068 fn addCompileErrorCli(self: *Compilation, realpath: []const u8, comptime fmt: []const u8, args: ...) !void {1068 fn addCompileErrorCli(self: *Compilation, realpath: []const u8, comptime fmt: []const u8, args: var) !void {
1069 const text = try std.fmt.allocPrint(self.gpa(), fmt, args);1069 const text = try std.fmt.allocPrint(self.gpa(), fmt, args);
1070 errdefer self.gpa().free(text);1070 errdefer self.gpa().free(text);
10711071
...@@ -1092,12 +1092,9 @@ pub const Compilation = struct {...@@ -1092,12 +1092,9 @@ pub const Compilation = struct {
1092 defer exported_symbol_names.release();1092 defer exported_symbol_names.release();
10931093
1094 if (try exported_symbol_names.value.put(decl.name, decl)) |other_decl| {1094 if (try exported_symbol_names.value.put(decl.name, decl)) |other_decl| {
1095 try self.addCompileError(1095 try self.addCompileError(decl.tree_scope, decl.getSpan(), "exported symbol collision: '{}'", .{
1096 decl.tree_scope,
1097 decl.getSpan(),
1098 "exported symbol collision: '{}'",
1099 decl.name,1096 decl.name,
1100 );1097 });
1101 // TODO add error note showing location of other symbol1098 // TODO add error note showing location of other symbol
1102 }1099 }
1103 }1100 }
...@@ -1162,7 +1159,7 @@ pub const Compilation = struct {...@@ -1162,7 +1159,7 @@ pub const Compilation = struct {
1162 const tmp_dir = try self.getTmpDir();1159 const tmp_dir = try self.getTmpDir();
1163 const file_prefix = self.getRandomFileName();1160 const file_prefix = self.getRandomFileName();
11641161
1165 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);1162 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", .{ file_prefix[0..], suffix });
1166 defer self.gpa().free(file_name);1163 defer self.gpa().free(file_name);
11671164
1168 const full_path = try std.fs.path.join(self.gpa(), &[_][]const u8{ tmp_dir, file_name[0..] });1165 const full_path = try std.fs.path.join(self.gpa(), &[_][]const u8{ tmp_dir, file_name[0..] });
...@@ -1303,7 +1300,7 @@ fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void {...@@ -1303,7 +1300,7 @@ fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void {
1303 try comp.addCompileError(tree_scope, Span{1300 try comp.addCompileError(tree_scope, Span{
1304 .first = param_decl.firstToken(),1301 .first = param_decl.firstToken(),
1305 .last = param_decl.type_node.firstToken(),1302 .last = param_decl.type_node.firstToken(),
1306 }, "missing parameter name");1303 }, "missing parameter name", .{});
1307 return error.SemanticAnalysisFailed;1304 return error.SemanticAnalysisFailed;
1308 };1305 };
1309 const param_name = tree_scope.tree.tokenSlice(name_token);1306 const param_name = tree_scope.tree.tokenSlice(name_token);
src-self-hosted/errmsg.zig+5-7
...@@ -231,7 +231,7 @@ pub const Msg = struct {...@@ -231,7 +231,7 @@ pub const Msg = struct {
231 pub fn printToStream(msg: *const Msg, stream: var, color_on: bool) !void {231 pub fn printToStream(msg: *const Msg, stream: var, color_on: bool) !void {
232 switch (msg.data) {232 switch (msg.data) {
233 .Cli => {233 .Cli => {
234 try stream.print("{}:-:-: error: {}\n", msg.realpath, msg.text);234 try stream.print("{}:-:-: error: {}\n", .{ msg.realpath, msg.text });
235 return;235 return;
236 },236 },
237 else => {},237 else => {},
...@@ -254,24 +254,22 @@ pub const Msg = struct {...@@ -254,24 +254,22 @@ pub const Msg = struct {
254 const start_loc = tree.tokenLocationPtr(0, first_token);254 const start_loc = tree.tokenLocationPtr(0, first_token);
255 const end_loc = tree.tokenLocationPtr(first_token.end, last_token);255 const end_loc = tree.tokenLocationPtr(first_token.end, last_token);
256 if (!color_on) {256 if (!color_on) {
257 try stream.print(257 try stream.print("{}:{}:{}: error: {}\n", .{
258 "{}:{}:{}: error: {}\n",
259 path,258 path,
260 start_loc.line + 1,259 start_loc.line + 1,
261 start_loc.column + 1,260 start_loc.column + 1,
262 msg.text,261 msg.text,
263 );262 });
264 return;263 return;
265 }264 }
266265
267 try stream.print(266 try stream.print("{}:{}:{}: error: {}\n{}\n", .{
268 "{}:{}:{}: error: {}\n{}\n",
269 path,267 path,
270 start_loc.line + 1,268 start_loc.line + 1,
271 start_loc.column + 1,269 start_loc.column + 1,
272 msg.text,270 msg.text,
273 tree.source[start_loc.line_start..start_loc.line_end],271 tree.source[start_loc.line_start..start_loc.line_end],
274 );272 });
275 try stream.writeByteNTimes(' ', start_loc.column);273 try stream.writeByteNTimes(' ', start_loc.column);
276 try stream.writeByteNTimes('~', last_token.end - first_token.start);274 try stream.writeByteNTimes('~', last_token.end - first_token.start);
277 try stream.write("\n");275 try stream.write("\n");
src-self-hosted/introspect.zig+1-1
...@@ -48,7 +48,7 @@ pub fn resolveZigLibDir(allocator: *mem.Allocator) ![]u8 {...@@ -48,7 +48,7 @@ pub fn resolveZigLibDir(allocator: *mem.Allocator) ![]u8 {
48 \\Unable to find zig lib directory: {}.48 \\Unable to find zig lib directory: {}.
49 \\Reinstall Zig or use --zig-install-prefix.49 \\Reinstall Zig or use --zig-install-prefix.
50 \\50 \\
51 , @errorName(err));51 , .{@errorName(err)});
5252
53 return error.ZigLibDirNotFound;53 return error.ZigLibDirNotFound;
54 };54 };
src-self-hosted/ir.zig+38-40
...@@ -32,16 +32,16 @@ pub const IrVal = union(enum) {...@@ -32,16 +32,16 @@ pub const IrVal = union(enum) {
3232
33 pub fn dump(self: IrVal) void {33 pub fn dump(self: IrVal) void {
34 switch (self) {34 switch (self) {
35 .Unknown => std.debug.warn("Unknown"),35 .Unknown => std.debug.warn("Unknown", .{}),
36 .KnownType => |typ| {36 .KnownType => |typ| {
37 std.debug.warn("KnownType(");37 std.debug.warn("KnownType(", .{});
38 typ.dump();38 typ.dump();
39 std.debug.warn(")");39 std.debug.warn(")", .{});
40 },40 },
41 .KnownValue => |value| {41 .KnownValue => |value| {
42 std.debug.warn("KnownValue(");42 std.debug.warn("KnownValue(", .{});
43 value.dump();43 value.dump();
44 std.debug.warn(")");44 std.debug.warn(")", .{});
45 },45 },
46 }46 }
47 }47 }
...@@ -90,9 +90,9 @@ pub const Inst = struct {...@@ -90,9 +90,9 @@ pub const Inst = struct {
90 inline while (i < @memberCount(Id)) : (i += 1) {90 inline while (i < @memberCount(Id)) : (i += 1) {
91 if (base.id == @field(Id, @memberName(Id, i))) {91 if (base.id == @field(Id, @memberName(Id, i))) {
92 const T = @field(Inst, @memberName(Id, i));92 const T = @field(Inst, @memberName(Id, i));
93 std.debug.warn("#{} = {}(", base.debug_id, @tagName(base.id));93 std.debug.warn("#{} = {}(", .{ base.debug_id, @tagName(base.id) });
94 @fieldParentPtr(T, "base", base).dump();94 @fieldParentPtr(T, "base", base).dump();
95 std.debug.warn(")");95 std.debug.warn(")", .{});
96 return;96 return;
97 }97 }
98 }98 }
...@@ -173,7 +173,7 @@ pub const Inst = struct {...@@ -173,7 +173,7 @@ pub const Inst = struct {
173 if (self.isCompTime()) {173 if (self.isCompTime()) {
174 return self.val.KnownValue;174 return self.val.KnownValue;
175 } else {175 } else {
176 try ira.addCompileError(self.span, "unable to evaluate constant expression");176 try ira.addCompileError(self.span, "unable to evaluate constant expression", .{});
177 return error.SemanticAnalysisFailed;177 return error.SemanticAnalysisFailed;
178 }178 }
179 }179 }
...@@ -269,11 +269,11 @@ pub const Inst = struct {...@@ -269,11 +269,11 @@ pub const Inst = struct {
269 const ir_val_init = IrVal.Init.Unknown;269 const ir_val_init = IrVal.Init.Unknown;
270270
271 pub fn dump(self: *const Call) void {271 pub fn dump(self: *const Call) void {
272 std.debug.warn("#{}(", self.params.fn_ref.debug_id);272 std.debug.warn("#{}(", .{self.params.fn_ref.debug_id});
273 for (self.params.args) |arg| {273 for (self.params.args) |arg| {
274 std.debug.warn("#{},", arg.debug_id);274 std.debug.warn("#{},", .{arg.debug_id});
275 }275 }
276 std.debug.warn(")");276 std.debug.warn(")", .{});
277 }277 }
278278
279 pub fn hasSideEffects(self: *const Call) bool {279 pub fn hasSideEffects(self: *const Call) bool {
...@@ -284,19 +284,17 @@ pub const Inst = struct {...@@ -284,19 +284,17 @@ pub const Inst = struct {
284 const fn_ref = try self.params.fn_ref.getAsParam();284 const fn_ref = try self.params.fn_ref.getAsParam();
285 const fn_ref_type = fn_ref.getKnownType();285 const fn_ref_type = fn_ref.getKnownType();
286 const fn_type = fn_ref_type.cast(Type.Fn) orelse {286 const fn_type = fn_ref_type.cast(Type.Fn) orelse {
287 try ira.addCompileError(fn_ref.span, "type '{}' not a function", fn_ref_type.name);287 try ira.addCompileError(fn_ref.span, "type '{}' not a function", .{fn_ref_type.name});
288 return error.SemanticAnalysisFailed;288 return error.SemanticAnalysisFailed;
289 };289 };
290290
291 const fn_type_param_count = fn_type.paramCount();291 const fn_type_param_count = fn_type.paramCount();
292292
293 if (fn_type_param_count != self.params.args.len) {293 if (fn_type_param_count != self.params.args.len) {
294 try ira.addCompileError(294 try ira.addCompileError(self.base.span, "expected {} arguments, found {}", .{
295 self.base.span,
296 "expected {} arguments, found {}",
297 fn_type_param_count,295 fn_type_param_count,
298 self.params.args.len,296 self.params.args.len,
299 );297 });
300 return error.SemanticAnalysisFailed;298 return error.SemanticAnalysisFailed;
301 }299 }
302300
...@@ -375,7 +373,7 @@ pub const Inst = struct {...@@ -375,7 +373,7 @@ pub const Inst = struct {
375 const ir_val_init = IrVal.Init.NoReturn;373 const ir_val_init = IrVal.Init.NoReturn;
376374
377 pub fn dump(self: *const Return) void {375 pub fn dump(self: *const Return) void {
378 std.debug.warn("#{}", self.params.return_value.debug_id);376 std.debug.warn("#{}", .{self.params.return_value.debug_id});
379 }377 }
380378
381 pub fn hasSideEffects(self: *const Return) bool {379 pub fn hasSideEffects(self: *const Return) bool {
...@@ -509,7 +507,7 @@ pub const Inst = struct {...@@ -509,7 +507,7 @@ pub const Inst = struct {
509 const ir_val_init = IrVal.Init.Unknown;507 const ir_val_init = IrVal.Init.Unknown;
510508
511 pub fn dump(inst: *const VarPtr) void {509 pub fn dump(inst: *const VarPtr) void {
512 std.debug.warn("{}", inst.params.var_scope.name);510 std.debug.warn("{}", .{inst.params.var_scope.name});
513 }511 }
514512
515 pub fn hasSideEffects(inst: *const VarPtr) bool {513 pub fn hasSideEffects(inst: *const VarPtr) bool {
...@@ -567,7 +565,7 @@ pub const Inst = struct {...@@ -567,7 +565,7 @@ pub const Inst = struct {
567 const target = try self.params.target.getAsParam();565 const target = try self.params.target.getAsParam();
568 const target_type = target.getKnownType();566 const target_type = target.getKnownType();
569 if (target_type.id != .Pointer) {567 if (target_type.id != .Pointer) {
570 try ira.addCompileError(self.base.span, "dereference of non pointer type '{}'", target_type.name);568 try ira.addCompileError(self.base.span, "dereference of non pointer type '{}'", .{target_type.name});
571 return error.SemanticAnalysisFailed;569 return error.SemanticAnalysisFailed;
572 }570 }
573 const ptr_type = @fieldParentPtr(Type.Pointer, "base", target_type);571 const ptr_type = @fieldParentPtr(Type.Pointer, "base", target_type);
...@@ -705,7 +703,7 @@ pub const Inst = struct {...@@ -705,7 +703,7 @@ pub const Inst = struct {
705 const ir_val_init = IrVal.Init.Unknown;703 const ir_val_init = IrVal.Init.Unknown;
706704
707 pub fn dump(self: *const CheckVoidStmt) void {705 pub fn dump(self: *const CheckVoidStmt) void {
708 std.debug.warn("#{}", self.params.target.debug_id);706 std.debug.warn("#{}", .{self.params.target.debug_id});
709 }707 }
710708
711 pub fn hasSideEffects(inst: *const CheckVoidStmt) bool {709 pub fn hasSideEffects(inst: *const CheckVoidStmt) bool {
...@@ -715,7 +713,7 @@ pub const Inst = struct {...@@ -715,7 +713,7 @@ pub const Inst = struct {
715 pub fn analyze(self: *const CheckVoidStmt, ira: *Analyze) !*Inst {713 pub fn analyze(self: *const CheckVoidStmt, ira: *Analyze) !*Inst {
716 const target = try self.params.target.getAsParam();714 const target = try self.params.target.getAsParam();
717 if (target.getKnownType().id != .Void) {715 if (target.getKnownType().id != .Void) {
718 try ira.addCompileError(self.base.span, "expression value is ignored");716 try ira.addCompileError(self.base.span, "expression value is ignored", .{});
719 return error.SemanticAnalysisFailed;717 return error.SemanticAnalysisFailed;
720 }718 }
721 return ira.irb.buildConstVoid(self.base.scope, self.base.span, true);719 return ira.irb.buildConstVoid(self.base.scope, self.base.span, true);
...@@ -801,7 +799,7 @@ pub const Inst = struct {...@@ -801,7 +799,7 @@ pub const Inst = struct {
801 const ir_val_init = IrVal.Init.Unknown;799 const ir_val_init = IrVal.Init.Unknown;
802800
803 pub fn dump(inst: *const AddImplicitReturnType) void {801 pub fn dump(inst: *const AddImplicitReturnType) void {
804 std.debug.warn("#{}", inst.params.target.debug_id);802 std.debug.warn("#{}", .{inst.params.target.debug_id});
805 }803 }
806804
807 pub fn hasSideEffects(inst: *const AddImplicitReturnType) bool {805 pub fn hasSideEffects(inst: *const AddImplicitReturnType) bool {
...@@ -826,7 +824,7 @@ pub const Inst = struct {...@@ -826,7 +824,7 @@ pub const Inst = struct {
826 const ir_val_init = IrVal.Init.Unknown;824 const ir_val_init = IrVal.Init.Unknown;
827825
828 pub fn dump(inst: *const TestErr) void {826 pub fn dump(inst: *const TestErr) void {
829 std.debug.warn("#{}", inst.params.target.debug_id);827 std.debug.warn("#{}", .{inst.params.target.debug_id});
830 }828 }
831829
832 pub fn hasSideEffects(inst: *const TestErr) bool {830 pub fn hasSideEffects(inst: *const TestErr) bool {
...@@ -888,7 +886,7 @@ pub const Inst = struct {...@@ -888,7 +886,7 @@ pub const Inst = struct {
888 const ir_val_init = IrVal.Init.Unknown;886 const ir_val_init = IrVal.Init.Unknown;
889887
890 pub fn dump(inst: *const TestCompTime) void {888 pub fn dump(inst: *const TestCompTime) void {
891 std.debug.warn("#{}", inst.params.target.debug_id);889 std.debug.warn("#{}", .{inst.params.target.debug_id});
892 }890 }
893891
894 pub fn hasSideEffects(inst: *const TestCompTime) bool {892 pub fn hasSideEffects(inst: *const TestCompTime) bool {
...@@ -971,11 +969,11 @@ pub const Code = struct {...@@ -971,11 +969,11 @@ pub const Code = struct {
971 pub fn dump(self: *Code) void {969 pub fn dump(self: *Code) void {
972 var bb_i: usize = 0;970 var bb_i: usize = 0;
973 for (self.basic_block_list.toSliceConst()) |bb| {971 for (self.basic_block_list.toSliceConst()) |bb| {
974 std.debug.warn("{s}_{}:\n", bb.name_hint, bb.debug_id);972 std.debug.warn("{s}_{}:\n", .{ bb.name_hint, bb.debug_id });
975 for (bb.instruction_list.toSliceConst()) |instr| {973 for (bb.instruction_list.toSliceConst()) |instr| {
976 std.debug.warn(" ");974 std.debug.warn(" ", .{});
977 instr.dump();975 instr.dump();
978 std.debug.warn("\n");976 std.debug.warn("\n", .{});
979 }977 }
980 }978 }
981 }979 }
...@@ -993,6 +991,7 @@ pub const Code = struct {...@@ -993,6 +991,7 @@ pub const Code = struct {
993 self.tree_scope,991 self.tree_scope,
994 ret_value.span,992 ret_value.span,
995 "unable to evaluate constant expression",993 "unable to evaluate constant expression",
994 .{},
996 );995 );
997 return error.SemanticAnalysisFailed;996 return error.SemanticAnalysisFailed;
998 } else if (inst.hasSideEffects()) {997 } else if (inst.hasSideEffects()) {
...@@ -1000,6 +999,7 @@ pub const Code = struct {...@@ -1000,6 +999,7 @@ pub const Code = struct {
1000 self.tree_scope,999 self.tree_scope,
1001 inst.span,1000 inst.span,
1002 "unable to evaluate constant expression",1001 "unable to evaluate constant expression",
1002 .{},
1003 );1003 );
1004 return error.SemanticAnalysisFailed;1004 return error.SemanticAnalysisFailed;
1005 }1005 }
...@@ -1359,7 +1359,7 @@ pub const Builder = struct {...@@ -1359,7 +1359,7 @@ pub const Builder = struct {
1359 irb.code.tree_scope,1359 irb.code.tree_scope,
1360 src_span,1360 src_span,
1361 "invalid character in string literal: '{c}'",1361 "invalid character in string literal: '{c}'",
1362 str_token[bad_index],1362 .{str_token[bad_index]},
1363 );1363 );
1364 return error.SemanticAnalysisFailed;1364 return error.SemanticAnalysisFailed;
1365 },1365 },
...@@ -1523,6 +1523,7 @@ pub const Builder = struct {...@@ -1523,6 +1523,7 @@ pub const Builder = struct {
1523 irb.code.tree_scope,1523 irb.code.tree_scope,
1524 src_span,1524 src_span,
1525 "return expression outside function definition",1525 "return expression outside function definition",
1526 .{},
1526 );1527 );
1527 return error.SemanticAnalysisFailed;1528 return error.SemanticAnalysisFailed;
1528 }1529 }
...@@ -1533,6 +1534,7 @@ pub const Builder = struct {...@@ -1533,6 +1534,7 @@ pub const Builder = struct {
1533 irb.code.tree_scope,1534 irb.code.tree_scope,
1534 src_span,1535 src_span,
1535 "cannot return from defer expression",1536 "cannot return from defer expression",
1537 .{},
1536 );1538 );
1537 scope_defer_expr.reported_err = true;1539 scope_defer_expr.reported_err = true;
1538 }1540 }
...@@ -1629,7 +1631,7 @@ pub const Builder = struct {...@@ -1629,7 +1631,7 @@ pub const Builder = struct {
1629 }1631 }
1630 } else |err| switch (err) {1632 } else |err| switch (err) {
1631 error.Overflow => {1633 error.Overflow => {
1632 try irb.comp.addCompileError(irb.code.tree_scope, src_span, "integer too large");1634 try irb.comp.addCompileError(irb.code.tree_scope, src_span, "integer too large", .{});
1633 return error.SemanticAnalysisFailed;1635 return error.SemanticAnalysisFailed;
1634 },1636 },
1635 error.OutOfMemory => return error.OutOfMemory,1637 error.OutOfMemory => return error.OutOfMemory,
...@@ -1663,7 +1665,7 @@ pub const Builder = struct {...@@ -1663,7 +1665,7 @@ pub const Builder = struct {
1663 // TODO put a variable of same name with invalid type in global scope1665 // TODO put a variable of same name with invalid type in global scope
1664 // so that future references to this same name will find a variable with an invalid type1666 // so that future references to this same name will find a variable with an invalid type
16651667
1666 try irb.comp.addCompileError(irb.code.tree_scope, src_span, "unknown identifier '{}'", name);1668 try irb.comp.addCompileError(irb.code.tree_scope, src_span, "unknown identifier '{}'", .{name});
1667 return error.SemanticAnalysisFailed;1669 return error.SemanticAnalysisFailed;
1668 }1670 }
16691671
...@@ -2008,7 +2010,7 @@ const Analyze = struct {...@@ -2008,7 +2010,7 @@ const Analyze = struct {
2008 const next_instruction = ira.parent_basic_block.instruction_list.at(ira.instruction_index);2010 const next_instruction = ira.parent_basic_block.instruction_list.at(ira.instruction_index);
20092011
2010 if (!next_instruction.is_generated) {2012 if (!next_instruction.is_generated) {
2011 try ira.addCompileError(next_instruction.span, "unreachable code");2013 try ira.addCompileError(next_instruction.span, "unreachable code", .{});
2012 break;2014 break;
2013 }2015 }
2014 ira.instruction_index += 1;2016 ira.instruction_index += 1;
...@@ -2041,7 +2043,7 @@ const Analyze = struct {...@@ -2041,7 +2043,7 @@ const Analyze = struct {
2041 }2043 }
2042 }2044 }
20432045
2044 fn addCompileError(self: *Analyze, span: Span, comptime fmt: []const u8, args: ...) !void {2046 fn addCompileError(self: *Analyze, span: Span, comptime fmt: []const u8, args: var) !void {
2045 return self.irb.comp.addCompileError(self.irb.code.tree_scope, span, fmt, args);2047 return self.irb.comp.addCompileError(self.irb.code.tree_scope, span, fmt, args);
2046 }2048 }
20472049
...@@ -2330,12 +2332,10 @@ const Analyze = struct {...@@ -2330,12 +2332,10 @@ const Analyze = struct {
2330 break :cast;2332 break :cast;
2331 };2333 };
2332 if (!fits) {2334 if (!fits) {
2333 try ira.addCompileError(2335 try ira.addCompileError(source_instr.span, "integer value '{}' cannot be stored in type '{}'", .{
2334 source_instr.span,
2335 "integer value '{}' cannot be stored in type '{}'",
2336 from_int,2336 from_int,
2337 dest_type.name,2337 dest_type.name,
2338 );2338 });
2339 return error.SemanticAnalysisFailed;2339 return error.SemanticAnalysisFailed;
2340 }2340 }
23412341
...@@ -2498,12 +2498,10 @@ const Analyze = struct {...@@ -2498,12 +2498,10 @@ const Analyze = struct {
2498 // }2498 // }
2499 //}2499 //}
25002500
2501 try ira.addCompileError(2501 try ira.addCompileError(source_instr.span, "expected type '{}', found '{}'", .{
2502 source_instr.span,
2503 "expected type '{}', found '{}'",
2504 dest_type.name,2502 dest_type.name,
2505 from_type.name,2503 from_type.name,
2506 );2504 });
2507 //ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,2505 //ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
2508 // buf_sprintf("expected type '%s', found '%s'",2506 // buf_sprintf("expected type '%s', found '%s'",
2509 // buf_ptr(&wanted_type->name),2507 // buf_ptr(&wanted_type->name),
src-self-hosted/libc_installation.zig+13-15
...@@ -65,7 +65,7 @@ pub const LibCInstallation = struct {...@@ -65,7 +65,7 @@ pub const LibCInstallation = struct {
65 if (line.len == 0 or line[0] == '#') continue;65 if (line.len == 0 or line[0] == '#') continue;
66 var line_it = std.mem.separate(line, "=");66 var line_it = std.mem.separate(line, "=");
67 const name = line_it.next() orelse {67 const name = line_it.next() orelse {
68 try stderr.print("missing equal sign after field name\n");68 try stderr.print("missing equal sign after field name\n", .{});
69 return error.ParseError;69 return error.ParseError;
70 };70 };
71 const value = line_it.rest();71 const value = line_it.rest();
...@@ -83,7 +83,7 @@ pub const LibCInstallation = struct {...@@ -83,7 +83,7 @@ pub const LibCInstallation = struct {
83 },83 },
84 else => {84 else => {
85 if (value.len == 0) {85 if (value.len == 0) {
86 try stderr.print("field cannot be empty: {}\n", key);86 try stderr.print("field cannot be empty: {}\n", .{key});
87 return error.ParseError;87 return error.ParseError;
88 }88 }
89 const dupe = try std.mem.dupe(allocator, u8, value);89 const dupe = try std.mem.dupe(allocator, u8, value);
...@@ -97,7 +97,7 @@ pub const LibCInstallation = struct {...@@ -97,7 +97,7 @@ pub const LibCInstallation = struct {
97 }97 }
98 for (found_keys) |found_key, i| {98 for (found_keys) |found_key, i| {
99 if (!found_key.found) {99 if (!found_key.found) {
100 try stderr.print("missing field: {}\n", keys[i]);100 try stderr.print("missing field: {}\n", .{keys[i]});
101 return error.ParseError;101 return error.ParseError;
102 }102 }
103 }103 }
...@@ -105,6 +105,11 @@ pub const LibCInstallation = struct {...@@ -105,6 +105,11 @@ pub const LibCInstallation = struct {
105105
106 pub fn render(self: *const LibCInstallation, out: *std.io.OutStream(fs.File.WriteError)) !void {106 pub fn render(self: *const LibCInstallation, out: *std.io.OutStream(fs.File.WriteError)) !void {
107 @setEvalBranchQuota(4000);107 @setEvalBranchQuota(4000);
108 const lib_dir = self.lib_dir orelse "";
109 const static_lib_dir = self.static_lib_dir orelse "";
110 const msvc_lib_dir = self.msvc_lib_dir orelse "";
111 const kernel32_lib_dir = self.kernel32_lib_dir orelse "";
112 const dynamic_linker_path = self.dynamic_linker_path orelse util.getDynamicLinkerPath(Target{ .Native = {} });
108 try out.print(113 try out.print(
109 \\# The directory that contains `stdlib.h`.114 \\# The directory that contains `stdlib.h`.
110 \\# On Linux, can be found with: `cc -E -Wp,-v -xc /dev/null`115 \\# On Linux, can be found with: `cc -E -Wp,-v -xc /dev/null`
...@@ -132,14 +137,7 @@ pub const LibCInstallation = struct {...@@ -132,14 +137,7 @@ pub const LibCInstallation = struct {
132 \\# Only needed when targeting Linux.137 \\# Only needed when targeting Linux.
133 \\dynamic_linker_path={}138 \\dynamic_linker_path={}
134 \\139 \\
135 ,140 , .{ self.include_dir, lib_dir, static_lib_dir, msvc_lib_dir, kernel32_lib_dir, dynamic_linker_path });
136 self.include_dir,
137 self.lib_dir orelse "",
138 self.static_lib_dir orelse "",
139 self.msvc_lib_dir orelse "",
140 self.kernel32_lib_dir orelse "",
141 self.dynamic_linker_path orelse util.getDynamicLinkerPath(Target{ .Native = {} }),
142 );
143 }141 }
144142
145 /// Finds the default, native libc.143 /// Finds the default, native libc.
...@@ -255,7 +253,7 @@ pub const LibCInstallation = struct {...@@ -255,7 +253,7 @@ pub const LibCInstallation = struct {
255 for (searches) |search| {253 for (searches) |search| {
256 result_buf.shrink(0);254 result_buf.shrink(0);
257 const stream = &std.io.BufferOutStream.init(&result_buf).stream;255 const stream = &std.io.BufferOutStream.init(&result_buf).stream;
258 try stream.print("{}\\Include\\{}\\ucrt", search.path, search.version);256 try stream.print("{}\\Include\\{}\\ucrt", .{ search.path, search.version });
259257
260 const stdlib_path = try fs.path.join(258 const stdlib_path = try fs.path.join(
261 allocator,259 allocator,
...@@ -282,7 +280,7 @@ pub const LibCInstallation = struct {...@@ -282,7 +280,7 @@ pub const LibCInstallation = struct {
282 for (searches) |search| {280 for (searches) |search| {
283 result_buf.shrink(0);281 result_buf.shrink(0);
284 const stream = &std.io.BufferOutStream.init(&result_buf).stream;282 const stream = &std.io.BufferOutStream.init(&result_buf).stream;
285 try stream.print("{}\\Lib\\{}\\ucrt\\", search.path, search.version);283 try stream.print("{}\\Lib\\{}\\ucrt\\", .{ search.path, search.version });
286 switch (builtin.arch) {284 switch (builtin.arch) {
287 .i386 => try stream.write("x86"),285 .i386 => try stream.write("x86"),
288 .x86_64 => try stream.write("x64"),286 .x86_64 => try stream.write("x64"),
...@@ -360,7 +358,7 @@ pub const LibCInstallation = struct {...@@ -360,7 +358,7 @@ pub const LibCInstallation = struct {
360 for (searches) |search| {358 for (searches) |search| {
361 result_buf.shrink(0);359 result_buf.shrink(0);
362 const stream = &std.io.BufferOutStream.init(&result_buf).stream;360 const stream = &std.io.BufferOutStream.init(&result_buf).stream;
363 try stream.print("{}\\Lib\\{}\\um\\", search.path, search.version);361 try stream.print("{}\\Lib\\{}\\um\\", .{ search.path, search.version });
364 switch (builtin.arch) {362 switch (builtin.arch) {
365 .i386 => try stream.write("x86\\"),363 .i386 => try stream.write("x86\\"),
366 .x86_64 => try stream.write("x64\\"),364 .x86_64 => try stream.write("x64\\"),
...@@ -395,7 +393,7 @@ pub const LibCInstallation = struct {...@@ -395,7 +393,7 @@ pub const LibCInstallation = struct {
395/// caller owns returned memory393/// caller owns returned memory
396fn ccPrintFileName(allocator: *Allocator, o_file: []const u8, want_dirname: bool) ![]u8 {394fn ccPrintFileName(allocator: *Allocator, o_file: []const u8, want_dirname: bool) ![]u8 {
397 const cc_exe = std.os.getenv("CC") orelse "cc";395 const cc_exe = std.os.getenv("CC") orelse "cc";
398 const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={}", o_file);396 const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={}", .{o_file});
399 defer allocator.free(arg1);397 defer allocator.free(arg1);
400 const argv = [_][]const u8{ cc_exe, arg1 };398 const argv = [_][]const u8{ cc_exe, arg1 };
401399
src-self-hosted/link.zig+20-13
...@@ -75,9 +75,9 @@ pub fn link(comp: *Compilation) !void {...@@ -75,9 +75,9 @@ pub fn link(comp: *Compilation) !void {
75 if (comp.verbose_link) {75 if (comp.verbose_link) {
76 for (ctx.args.toSliceConst()) |arg, i| {76 for (ctx.args.toSliceConst()) |arg, i| {
77 const space = if (i == 0) "" else " ";77 const space = if (i == 0) "" else " ";
78 std.debug.warn("{}{s}", space, arg);78 std.debug.warn("{}{s}", .{ space, arg });
79 }79 }
80 std.debug.warn("\n");80 std.debug.warn("\n", .{});
81 }81 }
8282
83 const extern_ofmt = toExternObjectFormatType(util.getObjectFormat(comp.target));83 const extern_ofmt = toExternObjectFormatType(util.getObjectFormat(comp.target));
...@@ -94,7 +94,7 @@ pub fn link(comp: *Compilation) !void {...@@ -94,7 +94,7 @@ pub fn link(comp: *Compilation) !void {
94 // TODO capture these messages and pass them through the system, reporting them through the94 // TODO capture these messages and pass them through the system, reporting them through the
95 // event system instead of printing them directly here.95 // event system instead of printing them directly here.
96 // perhaps try to parse and understand them.96 // perhaps try to parse and understand them.
97 std.debug.warn("{}\n", ctx.link_msg.toSliceConst());97 std.debug.warn("{}\n", .{ctx.link_msg.toSliceConst()});
98 }98 }
99 return error.LinkFailed;99 return error.LinkFailed;
100 }100 }
...@@ -334,13 +334,13 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {...@@ -334,13 +334,13 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
334334
335 const is_library = ctx.comp.kind == .Lib;335 const is_library = ctx.comp.kind == .Lib;
336336
337 const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", ctx.out_file_path.toSliceConst());337 const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", .{ctx.out_file_path.toSliceConst()});
338 try ctx.args.append(@ptrCast([*:0]const u8, out_arg.ptr));338 try ctx.args.append(@ptrCast([*:0]const u8, out_arg.ptr));
339339
340 if (ctx.comp.haveLibC()) {340 if (ctx.comp.haveLibC()) {
341 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.msvc_lib_dir.?)).ptr));341 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", .{ctx.libc.msvc_lib_dir.?})).ptr));
342 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.kernel32_lib_dir.?)).ptr));342 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", .{ctx.libc.kernel32_lib_dir.?})).ptr));
343 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.lib_dir.?)).ptr));343 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", .{ctx.libc.lib_dir.?})).ptr));
344 }344 }
345345
346 if (ctx.link_in_crt) {346 if (ctx.link_in_crt) {
...@@ -348,17 +348,20 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {...@@ -348,17 +348,20 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
348 const d_str = if (ctx.comp.build_mode == .Debug) "d" else "";348 const d_str = if (ctx.comp.build_mode == .Debug) "d" else "";
349349
350 if (ctx.comp.is_static) {350 if (ctx.comp.is_static) {
351 const cmt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "libcmt{}.lib\x00", d_str);351 const cmt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "libcmt{}.lib\x00", .{d_str});
352 try ctx.args.append(@ptrCast([*:0]const u8, cmt_lib_name.ptr));352 try ctx.args.append(@ptrCast([*:0]const u8, cmt_lib_name.ptr));
353 } else {353 } else {
354 const msvcrt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "msvcrt{}.lib\x00", d_str);354 const msvcrt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "msvcrt{}.lib\x00", .{d_str});
355 try ctx.args.append(@ptrCast([*:0]const u8, msvcrt_lib_name.ptr));355 try ctx.args.append(@ptrCast([*:0]const u8, msvcrt_lib_name.ptr));
356 }356 }
357357
358 const vcruntime_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}vcruntime{}.lib\x00", lib_str, d_str);358 const vcruntime_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}vcruntime{}.lib\x00", .{
359 lib_str,
360 d_str,
361 });
359 try ctx.args.append(@ptrCast([*:0]const u8, vcruntime_lib_name.ptr));362 try ctx.args.append(@ptrCast([*:0]const u8, vcruntime_lib_name.ptr));
360363
361 const crt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}ucrt{}.lib\x00", lib_str, d_str);364 const crt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}ucrt{}.lib\x00", .{ lib_str, d_str });
362 try ctx.args.append(@ptrCast([*:0]const u8, crt_lib_name.ptr));365 try ctx.args.append(@ptrCast([*:0]const u8, crt_lib_name.ptr));
363366
364 // Visual C++ 2015 Conformance Changes367 // Visual C++ 2015 Conformance Changes
...@@ -508,7 +511,11 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {...@@ -508,7 +511,11 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
508 .IPhoneOS => try ctx.args.append("-iphoneos_version_min"),511 .IPhoneOS => try ctx.args.append("-iphoneos_version_min"),
509 .IPhoneOSSimulator => try ctx.args.append("-ios_simulator_version_min"),512 .IPhoneOSSimulator => try ctx.args.append("-ios_simulator_version_min"),
510 }513 }
511 const ver_str = try std.fmt.allocPrint(&ctx.arena.allocator, "{}.{}.{}\x00", platform.major, platform.minor, platform.micro);514 const ver_str = try std.fmt.allocPrint(&ctx.arena.allocator, "{}.{}.{}\x00", .{
515 platform.major,
516 platform.minor,
517 platform.micro,
518 });
512 try ctx.args.append(@ptrCast([*:0]const u8, ver_str.ptr));519 try ctx.args.append(@ptrCast([*:0]const u8, ver_str.ptr));
513520
514 if (ctx.comp.kind == .Exe) {521 if (ctx.comp.kind == .Exe) {
...@@ -584,7 +591,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {...@@ -584,7 +591,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
584 try ctx.args.append("-lSystem");591 try ctx.args.append("-lSystem");
585 } else {592 } else {
586 if (mem.indexOfScalar(u8, lib.name, '/') == null) {593 if (mem.indexOfScalar(u8, lib.name, '/') == null) {
587 const arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-l{}\x00", lib.name);594 const arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-l{}\x00", .{lib.name});
588 try ctx.args.append(@ptrCast([*:0]const u8, arg.ptr));595 try ctx.args.append(@ptrCast([*:0]const u8, arg.ptr));
589 } else {596 } else {
590 const arg = try std.cstr.addNullByte(&ctx.arena.allocator, lib.name);597 const arg = try std.cstr.addNullByte(&ctx.arena.allocator, lib.name);
src-self-hosted/main.zig+24-25
...@@ -128,7 +128,7 @@ pub fn main() !void {...@@ -128,7 +128,7 @@ pub fn main() !void {
128 }128 }
129 }129 }
130130
131 try stderr.print("unknown command: {}\n\n", args[1]);131 try stderr.print("unknown command: {}\n\n", .{args[1]});
132 try stderr.write(usage);132 try stderr.write(usage);
133 process.argsFree(allocator, args);133 process.argsFree(allocator, args);
134 process.exit(1);134 process.exit(1);
...@@ -329,14 +329,14 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co...@@ -329,14 +329,14 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
329 if (cur_pkg.parent) |parent| {329 if (cur_pkg.parent) |parent| {
330 cur_pkg = parent;330 cur_pkg = parent;
331 } else {331 } else {
332 try stderr.print("encountered --pkg-end with no matching --pkg-begin\n");332 try stderr.print("encountered --pkg-end with no matching --pkg-begin\n", .{});
333 process.exit(1);333 process.exit(1);
334 }334 }
335 }335 }
336 }336 }
337337
338 if (cur_pkg.parent != null) {338 if (cur_pkg.parent != null) {
339 try stderr.print("unmatched --pkg-begin\n");339 try stderr.print("unmatched --pkg-begin\n", .{});
340 process.exit(1);340 process.exit(1);
341 }341 }
342342
...@@ -345,7 +345,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co...@@ -345,7 +345,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
345 0 => null,345 0 => null,
346 1 => flags.positionals.at(0),346 1 => flags.positionals.at(0),
347 else => {347 else => {
348 try stderr.print("unexpected extra parameter: {}\n", flags.positionals.at(1));348 try stderr.print("unexpected extra parameter: {}\n", .{flags.positionals.at(1)});
349 process.exit(1);349 process.exit(1);
350 },350 },
351 };351 };
...@@ -477,13 +477,13 @@ fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {...@@ -477,13 +477,13 @@ fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {
477477
478 switch (build_event) {478 switch (build_event) {
479 .Ok => {479 .Ok => {
480 stderr.print("Build {} succeeded\n", count) catch process.exit(1);480 stderr.print("Build {} succeeded\n", .{count}) catch process.exit(1);
481 },481 },
482 .Error => |err| {482 .Error => |err| {
483 stderr.print("Build {} failed: {}\n", count, @errorName(err)) catch process.exit(1);483 stderr.print("Build {} failed: {}\n", .{ count, @errorName(err) }) catch process.exit(1);
484 },484 },
485 .Fail => |msgs| {485 .Fail => |msgs| {
486 stderr.print("Build {} compile errors:\n", count) catch process.exit(1);486 stderr.print("Build {} compile errors:\n", .{count}) catch process.exit(1);
487 for (msgs) |msg| {487 for (msgs) |msg| {
488 defer msg.destroy();488 defer msg.destroy();
489 msg.printToFile(stderr_file, color) catch process.exit(1);489 msg.printToFile(stderr_file, color) catch process.exit(1);
...@@ -544,12 +544,11 @@ const Fmt = struct {...@@ -544,12 +544,11 @@ const Fmt = struct {
544544
545fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_file: []const u8) void {545fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_file: []const u8) void {
546 libc.parse(allocator, libc_paths_file, stderr) catch |err| {546 libc.parse(allocator, libc_paths_file, stderr) catch |err| {
547 stderr.print(547 stderr.print("Unable to parse libc path file '{}': {}.\n" ++
548 "Unable to parse libc path file '{}': {}.\n" ++548 "Try running `zig libc` to see an example for the native target.\n", .{
549 "Try running `zig libc` to see an example for the native target.\n",
550 libc_paths_file,549 libc_paths_file,
551 @errorName(err),550 @errorName(err),
552 ) catch {};551 }) catch {};
553 process.exit(1);552 process.exit(1);
554 };553 };
555}554}
...@@ -563,7 +562,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {...@@ -563,7 +562,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
563 return;562 return;
564 },563 },
565 else => {564 else => {
566 try stderr.print("unexpected extra parameter: {}\n", args[1]);565 try stderr.print("unexpected extra parameter: {}\n", .{args[1]});
567 process.exit(1);566 process.exit(1);
568 },567 },
569 }568 }
...@@ -572,7 +571,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {...@@ -572,7 +571,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
572 defer zig_compiler.deinit();571 defer zig_compiler.deinit();
573572
574 const libc = zig_compiler.getNativeLibC() catch |err| {573 const libc = zig_compiler.getNativeLibC() catch |err| {
575 stderr.print("unable to find libc: {}\n", @errorName(err)) catch {};574 stderr.print("unable to find libc: {}\n", .{@errorName(err)}) catch {};
576 process.exit(1);575 process.exit(1);
577 };576 };
578 libc.render(stdout) catch process.exit(1);577 libc.render(stdout) catch process.exit(1);
...@@ -614,7 +613,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {...@@ -614,7 +613,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
614 defer allocator.free(source_code);613 defer allocator.free(source_code);
615614
616 const tree = std.zig.parse(allocator, source_code) catch |err| {615 const tree = std.zig.parse(allocator, source_code) catch |err| {
617 try stderr.print("error parsing stdin: {}\n", err);616 try stderr.print("error parsing stdin: {}\n", .{err});
618 process.exit(1);617 process.exit(1);
619 };618 };
620 defer tree.deinit();619 defer tree.deinit();
...@@ -718,7 +717,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -718,7 +717,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
718 },717 },
719 else => {718 else => {
720 // TODO lock stderr printing719 // TODO lock stderr printing
721 try stderr.print("unable to open '{}': {}\n", file_path, err);720 try stderr.print("unable to open '{}': {}\n", .{ file_path, err });
722 fmt.any_error = true;721 fmt.any_error = true;
723 return;722 return;
724 },723 },
...@@ -726,7 +725,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -726,7 +725,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
726 defer fmt.allocator.free(source_code);725 defer fmt.allocator.free(source_code);
727726
728 const tree = std.zig.parse(fmt.allocator, source_code) catch |err| {727 const tree = std.zig.parse(fmt.allocator, source_code) catch |err| {
729 try stderr.print("error parsing file '{}': {}\n", file_path, err);728 try stderr.print("error parsing file '{}': {}\n", .{ file_path, err });
730 fmt.any_error = true;729 fmt.any_error = true;
731 return;730 return;
732 };731 };
...@@ -747,7 +746,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -747,7 +746,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
747 if (check_mode) {746 if (check_mode) {
748 const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree);747 const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree);
749 if (anything_changed) {748 if (anything_changed) {
750 try stderr.print("{}\n", file_path);749 try stderr.print("{}\n", .{file_path});
751 fmt.any_error = true;750 fmt.any_error = true;
752 }751 }
753 } else {752 } else {
...@@ -757,7 +756,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -757,7 +756,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
757756
758 const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree);757 const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree);
759 if (anything_changed) {758 if (anything_changed) {
760 try stderr.print("{}\n", file_path);759 try stderr.print("{}\n", .{file_path});
761 try baf.finish();760 try baf.finish();
762 }761 }
763 }762 }
...@@ -774,7 +773,7 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {...@@ -774,7 +773,7 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
774 // NOTE: Cannot use empty string, see #918.773 // NOTE: Cannot use empty string, see #918.
775 comptime const native_str = if (comptime mem.eql(u8, arch_tag, @tagName(builtin.arch))) " (native)\n" else "\n";774 comptime const native_str = if (comptime mem.eql(u8, arch_tag, @tagName(builtin.arch))) " (native)\n" else "\n";
776775
777 try stdout.print(" {}{}", arch_tag, native_str);776 try stdout.print(" {}{}", .{ arch_tag, native_str });
778 }777 }
779 }778 }
780 try stdout.write("\n");779 try stdout.write("\n");
...@@ -787,7 +786,7 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {...@@ -787,7 +786,7 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
787 // NOTE: Cannot use empty string, see #918.786 // NOTE: Cannot use empty string, see #918.
788 comptime const native_str = if (comptime mem.eql(u8, os_tag, @tagName(builtin.os))) " (native)\n" else "\n";787 comptime const native_str = if (comptime mem.eql(u8, os_tag, @tagName(builtin.os))) " (native)\n" else "\n";
789788
790 try stdout.print(" {}{}", os_tag, native_str);789 try stdout.print(" {}{}", .{ os_tag, native_str });
791 }790 }
792 }791 }
793 try stdout.write("\n");792 try stdout.write("\n");
...@@ -800,13 +799,13 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {...@@ -800,13 +799,13 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
800 // NOTE: Cannot use empty string, see #918.799 // NOTE: Cannot use empty string, see #918.
801 comptime const native_str = if (comptime mem.eql(u8, abi_tag, @tagName(builtin.abi))) " (native)\n" else "\n";800 comptime const native_str = if (comptime mem.eql(u8, abi_tag, @tagName(builtin.abi))) " (native)\n" else "\n";
802801
803 try stdout.print(" {}{}", abi_tag, native_str);802 try stdout.print(" {}{}", .{ abi_tag, native_str });
804 }803 }
805 }804 }
806}805}
807806
808fn cmdVersion(allocator: *Allocator, args: []const []const u8) !void {807fn cmdVersion(allocator: *Allocator, args: []const []const u8) !void {
809 try stdout.print("{}\n", std.mem.toSliceConst(u8, c.ZIG_VERSION_STRING));808 try stdout.print("{}\n", .{std.mem.toSliceConst(u8, c.ZIG_VERSION_STRING)});
810}809}
811810
812const args_test_spec = [_]Flag{Flag.Bool("--help")};811const args_test_spec = [_]Flag{Flag.Bool("--help")};
...@@ -865,7 +864,7 @@ fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {...@@ -865,7 +864,7 @@ fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {
865 }864 }
866 }865 }
867866
868 try stderr.print("unknown sub command: {}\n\n", args[0]);867 try stderr.print("unknown sub command: {}\n\n", .{args[0]});
869 try stderr.write(usage_internal);868 try stderr.write(usage_internal);
870}869}
871870
...@@ -878,14 +877,14 @@ fn cmdInternalBuildInfo(allocator: *Allocator, args: []const []const u8) !void {...@@ -878,14 +877,14 @@ fn cmdInternalBuildInfo(allocator: *Allocator, args: []const []const u8) !void {
878 \\ZIG_LLVM_CONFIG_EXE {}877 \\ZIG_LLVM_CONFIG_EXE {}
879 \\ZIG_DIA_GUIDS_LIB {}878 \\ZIG_DIA_GUIDS_LIB {}
880 \\879 \\
881 ,880 , .{
882 std.mem.toSliceConst(u8, c.ZIG_CMAKE_BINARY_DIR),881 std.mem.toSliceConst(u8, c.ZIG_CMAKE_BINARY_DIR),
883 std.mem.toSliceConst(u8, c.ZIG_CXX_COMPILER),882 std.mem.toSliceConst(u8, c.ZIG_CXX_COMPILER),
884 std.mem.toSliceConst(u8, c.ZIG_LLD_INCLUDE_PATH),883 std.mem.toSliceConst(u8, c.ZIG_LLD_INCLUDE_PATH),
885 std.mem.toSliceConst(u8, c.ZIG_LLD_LIBRARIES),884 std.mem.toSliceConst(u8, c.ZIG_LLD_LIBRARIES),
886 std.mem.toSliceConst(u8, c.ZIG_LLVM_CONFIG_EXE),885 std.mem.toSliceConst(u8, c.ZIG_LLVM_CONFIG_EXE),
887 std.mem.toSliceConst(u8, c.ZIG_DIA_GUIDS_LIB),886 std.mem.toSliceConst(u8, c.ZIG_DIA_GUIDS_LIB),
888 );887 });
889}888}
890889
891const CliPkg = struct {890const CliPkg = struct {
src-self-hosted/type.zig+11-15
...@@ -399,7 +399,7 @@ pub const Type = struct {...@@ -399,7 +399,7 @@ pub const Type = struct {
399 .Generic => |generic| {399 .Generic => |generic| {
400 self.non_key = NonKey{ .Generic = {} };400 self.non_key = NonKey{ .Generic = {} };
401 const cc_str = ccFnTypeStr(generic.cc);401 const cc_str = ccFnTypeStr(generic.cc);
402 try name_stream.print("{}fn(", cc_str);402 try name_stream.print("{}fn(", .{cc_str});
403 var param_i: usize = 0;403 var param_i: usize = 0;
404 while (param_i < generic.param_count) : (param_i += 1) {404 while (param_i < generic.param_count) : (param_i += 1) {
405 const arg = if (param_i == 0) "var" else ", var";405 const arg = if (param_i == 0) "var" else ", var";
...@@ -407,7 +407,7 @@ pub const Type = struct {...@@ -407,7 +407,7 @@ pub const Type = struct {
407 }407 }
408 try name_stream.write(")");408 try name_stream.write(")");
409 if (key.alignment) |alignment| {409 if (key.alignment) |alignment| {
410 try name_stream.print(" align({})", alignment);410 try name_stream.print(" align({})", .{alignment});
411 }411 }
412 try name_stream.write(" var");412 try name_stream.write(" var");
413 },413 },
...@@ -416,7 +416,7 @@ pub const Type = struct {...@@ -416,7 +416,7 @@ pub const Type = struct {
416 .Normal = NonKey.Normal{ .variable_list = std.ArrayList(*Scope.Var).init(comp.gpa()) },416 .Normal = NonKey.Normal{ .variable_list = std.ArrayList(*Scope.Var).init(comp.gpa()) },
417 };417 };
418 const cc_str = ccFnTypeStr(normal.cc);418 const cc_str = ccFnTypeStr(normal.cc);
419 try name_stream.print("{}fn(", cc_str);419 try name_stream.print("{}fn(", .{cc_str});
420 for (normal.params) |param, i| {420 for (normal.params) |param, i| {
421 if (i != 0) try name_stream.write(", ");421 if (i != 0) try name_stream.write(", ");
422 if (param.is_noalias) try name_stream.write("noalias ");422 if (param.is_noalias) try name_stream.write("noalias ");
...@@ -428,9 +428,9 @@ pub const Type = struct {...@@ -428,9 +428,9 @@ pub const Type = struct {
428 }428 }
429 try name_stream.write(")");429 try name_stream.write(")");
430 if (key.alignment) |alignment| {430 if (key.alignment) |alignment| {
431 try name_stream.print(" align({})", alignment);431 try name_stream.print(" align({})", .{alignment});
432 }432 }
433 try name_stream.print(" {}", normal.return_type.name);433 try name_stream.print(" {}", .{normal.return_type.name});
434 },434 },
435 }435 }
436436
...@@ -584,7 +584,7 @@ pub const Type = struct {...@@ -584,7 +584,7 @@ pub const Type = struct {
584 errdefer comp.gpa().destroy(self);584 errdefer comp.gpa().destroy(self);
585585
586 const u_or_i = "ui"[@boolToInt(key.is_signed)];586 const u_or_i = "ui"[@boolToInt(key.is_signed)];
587 const name = try std.fmt.allocPrint(comp.gpa(), "{c}{}", u_or_i, key.bit_count);587 const name = try std.fmt.allocPrint(comp.gpa(), "{c}{}", .{ u_or_i, key.bit_count });
588 errdefer comp.gpa().free(name);588 errdefer comp.gpa().free(name);
589589
590 self.base.init(comp, .Int, name);590 self.base.init(comp, .Int, name);
...@@ -767,23 +767,19 @@ pub const Type = struct {...@@ -767,23 +767,19 @@ pub const Type = struct {
767 .Non => "",767 .Non => "",
768 };768 };
769 const name = switch (self.key.alignment) {769 const name = switch (self.key.alignment) {
770 .Abi => try std.fmt.allocPrint(770 .Abi => try std.fmt.allocPrint(comp.gpa(), "{}{}{}{}", .{
771 comp.gpa(),
772 "{}{}{}{}",
773 size_str,771 size_str,
774 mut_str,772 mut_str,
775 vol_str,773 vol_str,
776 self.key.child_type.name,774 self.key.child_type.name,
777 ),775 }),
778 .Override => |alignment| try std.fmt.allocPrint(776 .Override => |alignment| try std.fmt.allocPrint(comp.gpa(), "{}align<{}> {}{}{}", .{
779 comp.gpa(),
780 "{}align<{}> {}{}{}",
781 size_str,777 size_str,
782 alignment,778 alignment,
783 mut_str,779 mut_str,
784 vol_str,780 vol_str,
785 self.key.child_type.name,781 self.key.child_type.name,
786 ),782 }),
787 };783 };
788 errdefer comp.gpa().free(name);784 errdefer comp.gpa().free(name);
789785
...@@ -852,7 +848,7 @@ pub const Type = struct {...@@ -852,7 +848,7 @@ pub const Type = struct {
852 };848 };
853 errdefer comp.gpa().destroy(self);849 errdefer comp.gpa().destroy(self);
854850
855 const name = try std.fmt.allocPrint(comp.gpa(), "[{}]{}", key.len, key.elem_type.name);851 const name = try std.fmt.allocPrint(comp.gpa(), "[{}]{}", .{ key.len, key.elem_type.name });
856 errdefer comp.gpa().free(name);852 errdefer comp.gpa().free(name);
857853
858 self.base.init(comp, .Array, name);854 self.base.init(comp, .Array, name);
src-self-hosted/util.zig+2-2
...@@ -175,7 +175,7 @@ pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target {...@@ -175,7 +175,7 @@ pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target {
175 var result: *llvm.Target = undefined;175 var result: *llvm.Target = undefined;
176 var err_msg: [*:0]u8 = undefined;176 var err_msg: [*:0]u8 = undefined;
177 if (llvm.GetTargetFromTriple(triple.toSlice(), &result, &err_msg) != 0) {177 if (llvm.GetTargetFromTriple(triple.toSlice(), &result, &err_msg) != 0) {
178 std.debug.warn("triple: {s} error: {s}\n", triple.toSlice(), err_msg);178 std.debug.warn("triple: {s} error: {s}\n", .{ triple.toSlice(), err_msg });
179 return error.UnsupportedTarget;179 return error.UnsupportedTarget;
180 }180 }
181 return result;181 return result;
...@@ -206,7 +206,7 @@ pub fn getTriple(allocator: *std.mem.Allocator, self: std.Target) !std.Buffer {...@@ -206,7 +206,7 @@ pub fn getTriple(allocator: *std.mem.Allocator, self: std.Target) !std.Buffer {
206 const env_name = if (self.isWasm()) "wasm" else @tagName(self.getAbi());206 const env_name = if (self.isWasm()) "wasm" else @tagName(self.getAbi());
207207
208 var out = &std.io.BufferOutStream.init(&result).stream;208 var out = &std.io.BufferOutStream.init(&result).stream;
209 try out.print("{}-unknown-{}-{}", @tagName(self.getArch()), @tagName(self.getOs()), env_name);209 try out.print("{}-unknown-{}-{}", .{ @tagName(self.getArch()), @tagName(self.getOs()), env_name });
210210
211 return result;211 return result;
212}212}
src-self-hosted/value.zig+1-1
...@@ -53,7 +53,7 @@ pub const Value = struct {...@@ -53,7 +53,7 @@ pub const Value = struct {
53 }53 }
5454
55 pub fn dump(base: *const Value) void {55 pub fn dump(base: *const Value) void {
56 std.debug.warn("{}", @tagName(base.id));56 std.debug.warn("{}", .{@tagName(base.id)});
57 }57 }
5858
59 pub fn getLlvmConst(base: *Value, ofile: *ObjectFile) (error{OutOfMemory}!?*llvm.Value) {59 pub fn getLlvmConst(base: *Value, ofile: *ObjectFile) (error{OutOfMemory}!?*llvm.Value) {