update self-hosted compiler to new format API

master
Andrew Kelley 2019-12-08 23:17:03 -05:00
parent 8b2622cdd5
commit fe4963412f
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
11 changed files with 133 additions and 142 deletions

View File

@ -45,13 +45,11 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
// Don't use ZIG_VERSION_STRING here. LLVM misparses it when it includes
// the git revision.
const producer = try std.Buffer.allocPrint(
&code.arena.allocator,
"zig {}.{}.{}",
const producer = try std.Buffer.allocPrint(&code.arena.allocator, "zig {}.{}.{}", .{
@as(u32, c.ZIG_VERSION_MAJOR),
@as(u32, c.ZIG_VERSION_MINOR),
@as(u32, c.ZIG_VERSION_PATCH),
);
});
const flags = "";
const runtime_version = 0;
const compile_unit_file = llvm.CreateFile(
@ -93,7 +91,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
llvm.DIBuilderFinalize(dibuilder);
if (comp.verbose_llvm_ir) {
std.debug.warn("raw module:\n");
std.debug.warn("raw module:\n", .{});
llvm.DumpModule(ofile.module);
}
@ -120,18 +118,18 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
is_small,
)) {
if (std.debug.runtime_safety) {
std.debug.panic("unable to write object file {}: {s}\n", output_path.toSliceConst(), err_msg);
std.debug.panic("unable to write object file {}: {s}\n", .{ output_path.toSliceConst(), err_msg });
}
return error.WritingObjectFileFailed;
}
//validate_inline_fns(g); TODO
fn_val.containing_object = output_path;
if (comp.verbose_llvm_ir) {
std.debug.warn("optimized module:\n");
std.debug.warn("optimized module:\n", .{});
llvm.DumpModule(ofile.module);
}
if (comp.verbose_link) {
std.debug.warn("created {}\n", output_path.toSliceConst());
std.debug.warn("created {}\n", .{output_path.toSliceConst()});
}
}

View File

@ -807,7 +807,7 @@ pub const Compilation = struct {
root_scope.realpath,
max_src_size,
) catch |err| {
try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", @errorName(err));
try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", .{@errorName(err)});
return;
};
errdefer self.gpa().free(source_code);
@ -878,7 +878,7 @@ pub const Compilation = struct {
try self.addCompileError(tree_scope, Span{
.first = fn_proto.fn_token,
.last = fn_proto.fn_token + 1,
}, "missing function name");
}, "missing function name", .{});
continue;
};
@ -942,7 +942,7 @@ pub const Compilation = struct {
const root_scope = blk: {
// TODO async/await std.fs.realpath
const root_src_real_path = std.fs.realpathAlloc(self.gpa(), root_src_path) catch |err| {
try self.addCompileErrorCli(root_src_path, "unable to open: {}", @errorName(err));
try self.addCompileErrorCli(root_src_path, "unable to open: {}", .{@errorName(err)});
return;
};
errdefer self.gpa().free(root_src_real_path);
@ -991,7 +991,7 @@ pub const Compilation = struct {
defer unanalyzed_code.destroy(comp.gpa());
if (comp.verbose_ir) {
std.debug.warn("unanalyzed:\n");
std.debug.warn("unanalyzed:\n", .{});
unanalyzed_code.dump();
}
@ -1003,7 +1003,7 @@ pub const Compilation = struct {
errdefer analyzed_code.destroy(comp.gpa());
if (comp.verbose_ir) {
std.debug.warn("analyzed:\n");
std.debug.warn("analyzed:\n", .{});
analyzed_code.dump();
}
@ -1048,14 +1048,14 @@ pub const Compilation = struct {
const gop = try locked_table.getOrPut(decl.name);
if (gop.found_existing) {
try self.addCompileError(decl.tree_scope, decl.getSpan(), "redefinition of '{}'", decl.name);
try self.addCompileError(decl.tree_scope, decl.getSpan(), "redefinition of '{}'", .{decl.name});
// TODO note: other definition here
} else {
gop.kv.value = decl;
}
}
fn addCompileError(self: *Compilation, tree_scope: *Scope.AstTree, span: Span, comptime fmt: []const u8, args: ...) !void {
fn addCompileError(self: *Compilation, tree_scope: *Scope.AstTree, span: Span, comptime fmt: []const u8, args: var) !void {
const text = try std.fmt.allocPrint(self.gpa(), fmt, args);
errdefer self.gpa().free(text);
@ -1065,7 +1065,7 @@ pub const Compilation = struct {
try self.prelink_group.call(addCompileErrorAsync, self, msg);
}
fn addCompileErrorCli(self: *Compilation, realpath: []const u8, comptime fmt: []const u8, args: ...) !void {
fn addCompileErrorCli(self: *Compilation, realpath: []const u8, comptime fmt: []const u8, args: var) !void {
const text = try std.fmt.allocPrint(self.gpa(), fmt, args);
errdefer self.gpa().free(text);
@ -1092,12 +1092,9 @@ pub const Compilation = struct {
defer exported_symbol_names.release();
if (try exported_symbol_names.value.put(decl.name, decl)) |other_decl| {
try self.addCompileError(
decl.tree_scope,
decl.getSpan(),
"exported symbol collision: '{}'",
try self.addCompileError(decl.tree_scope, decl.getSpan(), "exported symbol collision: '{}'", .{
decl.name,
);
});
// TODO add error note showing location of other symbol
}
}
@ -1162,7 +1159,7 @@ pub const Compilation = struct {
const tmp_dir = try self.getTmpDir();
const file_prefix = self.getRandomFileName();
const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);
const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", .{ file_prefix[0..], suffix });
defer self.gpa().free(file_name);
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 {
try comp.addCompileError(tree_scope, Span{
.first = param_decl.firstToken(),
.last = param_decl.type_node.firstToken(),
}, "missing parameter name");
}, "missing parameter name", .{});
return error.SemanticAnalysisFailed;
};
const param_name = tree_scope.tree.tokenSlice(name_token);

View File

@ -231,7 +231,7 @@ pub const Msg = struct {
pub fn printToStream(msg: *const Msg, stream: var, color_on: bool) !void {
switch (msg.data) {
.Cli => {
try stream.print("{}:-:-: error: {}\n", msg.realpath, msg.text);
try stream.print("{}:-:-: error: {}\n", .{ msg.realpath, msg.text });
return;
},
else => {},
@ -254,24 +254,22 @@ pub const Msg = struct {
const start_loc = tree.tokenLocationPtr(0, first_token);
const end_loc = tree.tokenLocationPtr(first_token.end, last_token);
if (!color_on) {
try stream.print(
"{}:{}:{}: error: {}\n",
try stream.print("{}:{}:{}: error: {}\n", .{
path,
start_loc.line + 1,
start_loc.column + 1,
msg.text,
);
});
return;
}
try stream.print(
"{}:{}:{}: error: {}\n{}\n",
try stream.print("{}:{}:{}: error: {}\n{}\n", .{
path,
start_loc.line + 1,
start_loc.column + 1,
msg.text,
tree.source[start_loc.line_start..start_loc.line_end],
);
});
try stream.writeByteNTimes(' ', start_loc.column);
try stream.writeByteNTimes('~', last_token.end - first_token.start);
try stream.write("\n");

View File

@ -48,7 +48,7 @@ pub fn resolveZigLibDir(allocator: *mem.Allocator) ![]u8 {
\\Unable to find zig lib directory: {}.
\\Reinstall Zig or use --zig-install-prefix.
\\
, @errorName(err));
, .{@errorName(err)});
return error.ZigLibDirNotFound;
};

View File

@ -32,16 +32,16 @@ pub const IrVal = union(enum) {
pub fn dump(self: IrVal) void {
switch (self) {
.Unknown => std.debug.warn("Unknown"),
.Unknown => std.debug.warn("Unknown", .{}),
.KnownType => |typ| {
std.debug.warn("KnownType(");
std.debug.warn("KnownType(", .{});
typ.dump();
std.debug.warn(")");
std.debug.warn(")", .{});
},
.KnownValue => |value| {
std.debug.warn("KnownValue(");
std.debug.warn("KnownValue(", .{});
value.dump();
std.debug.warn(")");
std.debug.warn(")", .{});
},
}
}
@ -90,9 +90,9 @@ pub const Inst = struct {
inline while (i < @memberCount(Id)) : (i += 1) {
if (base.id == @field(Id, @memberName(Id, i))) {
const T = @field(Inst, @memberName(Id, i));
std.debug.warn("#{} = {}(", base.debug_id, @tagName(base.id));
std.debug.warn("#{} = {}(", .{ base.debug_id, @tagName(base.id) });
@fieldParentPtr(T, "base", base).dump();
std.debug.warn(")");
std.debug.warn(")", .{});
return;
}
}
@ -173,7 +173,7 @@ pub const Inst = struct {
if (self.isCompTime()) {
return self.val.KnownValue;
} else {
try ira.addCompileError(self.span, "unable to evaluate constant expression");
try ira.addCompileError(self.span, "unable to evaluate constant expression", .{});
return error.SemanticAnalysisFailed;
}
}
@ -269,11 +269,11 @@ pub const Inst = struct {
const ir_val_init = IrVal.Init.Unknown;
pub fn dump(self: *const Call) void {
std.debug.warn("#{}(", self.params.fn_ref.debug_id);
std.debug.warn("#{}(", .{self.params.fn_ref.debug_id});
for (self.params.args) |arg| {
std.debug.warn("#{},", arg.debug_id);
std.debug.warn("#{},", .{arg.debug_id});
}
std.debug.warn(")");
std.debug.warn(")", .{});
}
pub fn hasSideEffects(self: *const Call) bool {
@ -284,19 +284,17 @@ pub const Inst = struct {
const fn_ref = try self.params.fn_ref.getAsParam();
const fn_ref_type = fn_ref.getKnownType();
const fn_type = fn_ref_type.cast(Type.Fn) orelse {
try ira.addCompileError(fn_ref.span, "type '{}' not a function", fn_ref_type.name);
try ira.addCompileError(fn_ref.span, "type '{}' not a function", .{fn_ref_type.name});
return error.SemanticAnalysisFailed;
};
const fn_type_param_count = fn_type.paramCount();
if (fn_type_param_count != self.params.args.len) {
try ira.addCompileError(
self.base.span,
"expected {} arguments, found {}",
try ira.addCompileError(self.base.span, "expected {} arguments, found {}", .{
fn_type_param_count,
self.params.args.len,
);
});
return error.SemanticAnalysisFailed;
}
@ -375,7 +373,7 @@ pub const Inst = struct {
const ir_val_init = IrVal.Init.NoReturn;
pub fn dump(self: *const Return) void {
std.debug.warn("#{}", self.params.return_value.debug_id);
std.debug.warn("#{}", .{self.params.return_value.debug_id});
}
pub fn hasSideEffects(self: *const Return) bool {
@ -509,7 +507,7 @@ pub const Inst = struct {
const ir_val_init = IrVal.Init.Unknown;
pub fn dump(inst: *const VarPtr) void {
std.debug.warn("{}", inst.params.var_scope.name);
std.debug.warn("{}", .{inst.params.var_scope.name});
}
pub fn hasSideEffects(inst: *const VarPtr) bool {
@ -567,7 +565,7 @@ pub const Inst = struct {
const target = try self.params.target.getAsParam();
const target_type = target.getKnownType();
if (target_type.id != .Pointer) {
try ira.addCompileError(self.base.span, "dereference of non pointer type '{}'", target_type.name);
try ira.addCompileError(self.base.span, "dereference of non pointer type '{}'", .{target_type.name});
return error.SemanticAnalysisFailed;
}
const ptr_type = @fieldParentPtr(Type.Pointer, "base", target_type);
@ -705,7 +703,7 @@ pub const Inst = struct {
const ir_val_init = IrVal.Init.Unknown;
pub fn dump(self: *const CheckVoidStmt) void {
std.debug.warn("#{}", self.params.target.debug_id);
std.debug.warn("#{}", .{self.params.target.debug_id});
}
pub fn hasSideEffects(inst: *const CheckVoidStmt) bool {
@ -715,7 +713,7 @@ pub const Inst = struct {
pub fn analyze(self: *const CheckVoidStmt, ira: *Analyze) !*Inst {
const target = try self.params.target.getAsParam();
if (target.getKnownType().id != .Void) {
try ira.addCompileError(self.base.span, "expression value is ignored");
try ira.addCompileError(self.base.span, "expression value is ignored", .{});
return error.SemanticAnalysisFailed;
}
return ira.irb.buildConstVoid(self.base.scope, self.base.span, true);
@ -801,7 +799,7 @@ pub const Inst = struct {
const ir_val_init = IrVal.Init.Unknown;
pub fn dump(inst: *const AddImplicitReturnType) void {
std.debug.warn("#{}", inst.params.target.debug_id);
std.debug.warn("#{}", .{inst.params.target.debug_id});
}
pub fn hasSideEffects(inst: *const AddImplicitReturnType) bool {
@ -826,7 +824,7 @@ pub const Inst = struct {
const ir_val_init = IrVal.Init.Unknown;
pub fn dump(inst: *const TestErr) void {
std.debug.warn("#{}", inst.params.target.debug_id);
std.debug.warn("#{}", .{inst.params.target.debug_id});
}
pub fn hasSideEffects(inst: *const TestErr) bool {
@ -888,7 +886,7 @@ pub const Inst = struct {
const ir_val_init = IrVal.Init.Unknown;
pub fn dump(inst: *const TestCompTime) void {
std.debug.warn("#{}", inst.params.target.debug_id);
std.debug.warn("#{}", .{inst.params.target.debug_id});
}
pub fn hasSideEffects(inst: *const TestCompTime) bool {
@ -971,11 +969,11 @@ pub const Code = struct {
pub fn dump(self: *Code) void {
var bb_i: usize = 0;
for (self.basic_block_list.toSliceConst()) |bb| {
std.debug.warn("{s}_{}:\n", bb.name_hint, bb.debug_id);
std.debug.warn("{s}_{}:\n", .{ bb.name_hint, bb.debug_id });
for (bb.instruction_list.toSliceConst()) |instr| {
std.debug.warn(" ");
std.debug.warn(" ", .{});
instr.dump();
std.debug.warn("\n");
std.debug.warn("\n", .{});
}
}
}
@ -993,6 +991,7 @@ pub const Code = struct {
self.tree_scope,
ret_value.span,
"unable to evaluate constant expression",
.{},
);
return error.SemanticAnalysisFailed;
} else if (inst.hasSideEffects()) {
@ -1000,6 +999,7 @@ pub const Code = struct {
self.tree_scope,
inst.span,
"unable to evaluate constant expression",
.{},
);
return error.SemanticAnalysisFailed;
}
@ -1359,7 +1359,7 @@ pub const Builder = struct {
irb.code.tree_scope,
src_span,
"invalid character in string literal: '{c}'",
str_token[bad_index],
.{str_token[bad_index]},
);
return error.SemanticAnalysisFailed;
},
@ -1523,6 +1523,7 @@ pub const Builder = struct {
irb.code.tree_scope,
src_span,
"return expression outside function definition",
.{},
);
return error.SemanticAnalysisFailed;
}
@ -1533,6 +1534,7 @@ pub const Builder = struct {
irb.code.tree_scope,
src_span,
"cannot return from defer expression",
.{},
);
scope_defer_expr.reported_err = true;
}
@ -1629,7 +1631,7 @@ pub const Builder = struct {
}
} else |err| switch (err) {
error.Overflow => {
try irb.comp.addCompileError(irb.code.tree_scope, src_span, "integer too large");
try irb.comp.addCompileError(irb.code.tree_scope, src_span, "integer too large", .{});
return error.SemanticAnalysisFailed;
},
error.OutOfMemory => return error.OutOfMemory,
@ -1663,7 +1665,7 @@ pub const Builder = struct {
// TODO put a variable of same name with invalid type in global scope
// so that future references to this same name will find a variable with an invalid type
try irb.comp.addCompileError(irb.code.tree_scope, src_span, "unknown identifier '{}'", name);
try irb.comp.addCompileError(irb.code.tree_scope, src_span, "unknown identifier '{}'", .{name});
return error.SemanticAnalysisFailed;
}
@ -2008,7 +2010,7 @@ const Analyze = struct {
const next_instruction = ira.parent_basic_block.instruction_list.at(ira.instruction_index);
if (!next_instruction.is_generated) {
try ira.addCompileError(next_instruction.span, "unreachable code");
try ira.addCompileError(next_instruction.span, "unreachable code", .{});
break;
}
ira.instruction_index += 1;
@ -2041,7 +2043,7 @@ const Analyze = struct {
}
}
fn addCompileError(self: *Analyze, span: Span, comptime fmt: []const u8, args: ...) !void {
fn addCompileError(self: *Analyze, span: Span, comptime fmt: []const u8, args: var) !void {
return self.irb.comp.addCompileError(self.irb.code.tree_scope, span, fmt, args);
}
@ -2330,12 +2332,10 @@ const Analyze = struct {
break :cast;
};
if (!fits) {
try ira.addCompileError(
source_instr.span,
"integer value '{}' cannot be stored in type '{}'",
try ira.addCompileError(source_instr.span, "integer value '{}' cannot be stored in type '{}'", .{
from_int,
dest_type.name,
);
});
return error.SemanticAnalysisFailed;
}
@ -2498,12 +2498,10 @@ const Analyze = struct {
// }
//}
try ira.addCompileError(
source_instr.span,
"expected type '{}', found '{}'",
try ira.addCompileError(source_instr.span, "expected type '{}', found '{}'", .{
dest_type.name,
from_type.name,
);
});
//ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
// buf_sprintf("expected type '%s', found '%s'",
// buf_ptr(&wanted_type->name),

View File

@ -65,7 +65,7 @@ pub const LibCInstallation = struct {
if (line.len == 0 or line[0] == '#') continue;
var line_it = std.mem.separate(line, "=");
const name = line_it.next() orelse {
try stderr.print("missing equal sign after field name\n");
try stderr.print("missing equal sign after field name\n", .{});
return error.ParseError;
};
const value = line_it.rest();
@ -83,7 +83,7 @@ pub const LibCInstallation = struct {
},
else => {
if (value.len == 0) {
try stderr.print("field cannot be empty: {}\n", key);
try stderr.print("field cannot be empty: {}\n", .{key});
return error.ParseError;
}
const dupe = try std.mem.dupe(allocator, u8, value);
@ -97,7 +97,7 @@ pub const LibCInstallation = struct {
}
for (found_keys) |found_key, i| {
if (!found_key.found) {
try stderr.print("missing field: {}\n", keys[i]);
try stderr.print("missing field: {}\n", .{keys[i]});
return error.ParseError;
}
}
@ -105,6 +105,11 @@ pub const LibCInstallation = struct {
pub fn render(self: *const LibCInstallation, out: *std.io.OutStream(fs.File.WriteError)) !void {
@setEvalBranchQuota(4000);
const lib_dir = self.lib_dir orelse "";
const static_lib_dir = self.static_lib_dir orelse "";
const msvc_lib_dir = self.msvc_lib_dir orelse "";
const kernel32_lib_dir = self.kernel32_lib_dir orelse "";
const dynamic_linker_path = self.dynamic_linker_path orelse util.getDynamicLinkerPath(Target{ .Native = {} });
try out.print(
\\# The directory that contains `stdlib.h`.
\\# On Linux, can be found with: `cc -E -Wp,-v -xc /dev/null`
@ -132,14 +137,7 @@ pub const LibCInstallation = struct {
\\# Only needed when targeting Linux.
\\dynamic_linker_path={}
\\
,
self.include_dir,
self.lib_dir orelse "",
self.static_lib_dir orelse "",
self.msvc_lib_dir orelse "",
self.kernel32_lib_dir orelse "",
self.dynamic_linker_path orelse util.getDynamicLinkerPath(Target{ .Native = {} }),
);
, .{ self.include_dir, lib_dir, static_lib_dir, msvc_lib_dir, kernel32_lib_dir, dynamic_linker_path });
}
/// Finds the default, native libc.
@ -255,7 +253,7 @@ pub const LibCInstallation = struct {
for (searches) |search| {
result_buf.shrink(0);
const stream = &std.io.BufferOutStream.init(&result_buf).stream;
try stream.print("{}\\Include\\{}\\ucrt", search.path, search.version);
try stream.print("{}\\Include\\{}\\ucrt", .{ search.path, search.version });
const stdlib_path = try fs.path.join(
allocator,
@ -282,7 +280,7 @@ pub const LibCInstallation = struct {
for (searches) |search| {
result_buf.shrink(0);
const stream = &std.io.BufferOutStream.init(&result_buf).stream;
try stream.print("{}\\Lib\\{}\\ucrt\\", search.path, search.version);
try stream.print("{}\\Lib\\{}\\ucrt\\", .{ search.path, search.version });
switch (builtin.arch) {
.i386 => try stream.write("x86"),
.x86_64 => try stream.write("x64"),
@ -360,7 +358,7 @@ pub const LibCInstallation = struct {
for (searches) |search| {
result_buf.shrink(0);
const stream = &std.io.BufferOutStream.init(&result_buf).stream;
try stream.print("{}\\Lib\\{}\\um\\", search.path, search.version);
try stream.print("{}\\Lib\\{}\\um\\", .{ search.path, search.version });
switch (builtin.arch) {
.i386 => try stream.write("x86\\"),
.x86_64 => try stream.write("x64\\"),
@ -395,7 +393,7 @@ pub const LibCInstallation = struct {
/// caller owns returned memory
fn ccPrintFileName(allocator: *Allocator, o_file: []const u8, want_dirname: bool) ![]u8 {
const cc_exe = std.os.getenv("CC") orelse "cc";
const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={}", o_file);
const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={}", .{o_file});
defer allocator.free(arg1);
const argv = [_][]const u8{ cc_exe, arg1 };

View File

@ -75,9 +75,9 @@ pub fn link(comp: *Compilation) !void {
if (comp.verbose_link) {
for (ctx.args.toSliceConst()) |arg, i| {
const space = if (i == 0) "" else " ";
std.debug.warn("{}{s}", space, arg);
std.debug.warn("{}{s}", .{ space, arg });
}
std.debug.warn("\n");
std.debug.warn("\n", .{});
}
const extern_ofmt = toExternObjectFormatType(util.getObjectFormat(comp.target));
@ -94,7 +94,7 @@ pub fn link(comp: *Compilation) !void {
// TODO capture these messages and pass them through the system, reporting them through the
// event system instead of printing them directly here.
// perhaps try to parse and understand them.
std.debug.warn("{}\n", ctx.link_msg.toSliceConst());
std.debug.warn("{}\n", .{ctx.link_msg.toSliceConst()});
}
return error.LinkFailed;
}
@ -334,13 +334,13 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
const is_library = ctx.comp.kind == .Lib;
const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", ctx.out_file_path.toSliceConst());
const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", .{ctx.out_file_path.toSliceConst()});
try ctx.args.append(@ptrCast([*:0]const u8, out_arg.ptr));
if (ctx.comp.haveLibC()) {
try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.msvc_lib_dir.?)).ptr));
try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.kernel32_lib_dir.?)).ptr));
try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.lib_dir.?)).ptr));
try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", .{ctx.libc.msvc_lib_dir.?})).ptr));
try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", .{ctx.libc.kernel32_lib_dir.?})).ptr));
try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", .{ctx.libc.lib_dir.?})).ptr));
}
if (ctx.link_in_crt) {
@ -348,17 +348,20 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
const d_str = if (ctx.comp.build_mode == .Debug) "d" else "";
if (ctx.comp.is_static) {
const cmt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "libcmt{}.lib\x00", d_str);
const cmt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "libcmt{}.lib\x00", .{d_str});
try ctx.args.append(@ptrCast([*:0]const u8, cmt_lib_name.ptr));
} else {
const msvcrt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "msvcrt{}.lib\x00", d_str);
const msvcrt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "msvcrt{}.lib\x00", .{d_str});
try ctx.args.append(@ptrCast([*:0]const u8, msvcrt_lib_name.ptr));
}
const vcruntime_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}vcruntime{}.lib\x00", lib_str, d_str);
const vcruntime_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}vcruntime{}.lib\x00", .{
lib_str,
d_str,
});
try ctx.args.append(@ptrCast([*:0]const u8, vcruntime_lib_name.ptr));
const crt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}ucrt{}.lib\x00", lib_str, d_str);
const crt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}ucrt{}.lib\x00", .{ lib_str, d_str });
try ctx.args.append(@ptrCast([*:0]const u8, crt_lib_name.ptr));
// Visual C++ 2015 Conformance Changes
@ -508,7 +511,11 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
.IPhoneOS => try ctx.args.append("-iphoneos_version_min"),
.IPhoneOSSimulator => try ctx.args.append("-ios_simulator_version_min"),
}
const ver_str = try std.fmt.allocPrint(&ctx.arena.allocator, "{}.{}.{}\x00", platform.major, platform.minor, platform.micro);
const ver_str = try std.fmt.allocPrint(&ctx.arena.allocator, "{}.{}.{}\x00", .{
platform.major,
platform.minor,
platform.micro,
});
try ctx.args.append(@ptrCast([*:0]const u8, ver_str.ptr));
if (ctx.comp.kind == .Exe) {
@ -584,7 +591,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
try ctx.args.append("-lSystem");
} else {
if (mem.indexOfScalar(u8, lib.name, '/') == null) {
const arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-l{}\x00", lib.name);
const arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-l{}\x00", .{lib.name});
try ctx.args.append(@ptrCast([*:0]const u8, arg.ptr));
} else {
const arg = try std.cstr.addNullByte(&ctx.arena.allocator, lib.name);

View File

@ -128,7 +128,7 @@ pub fn main() !void {
}
}
try stderr.print("unknown command: {}\n\n", args[1]);
try stderr.print("unknown command: {}\n\n", .{args[1]});
try stderr.write(usage);
process.argsFree(allocator, args);
process.exit(1);
@ -329,14 +329,14 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
if (cur_pkg.parent) |parent| {
cur_pkg = parent;
} else {
try stderr.print("encountered --pkg-end with no matching --pkg-begin\n");
try stderr.print("encountered --pkg-end with no matching --pkg-begin\n", .{});
process.exit(1);
}
}
}
if (cur_pkg.parent != null) {
try stderr.print("unmatched --pkg-begin\n");
try stderr.print("unmatched --pkg-begin\n", .{});
process.exit(1);
}
@ -345,7 +345,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
0 => null,
1 => flags.positionals.at(0),
else => {
try stderr.print("unexpected extra parameter: {}\n", flags.positionals.at(1));
try stderr.print("unexpected extra parameter: {}\n", .{flags.positionals.at(1)});
process.exit(1);
},
};
@ -477,13 +477,13 @@ fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {
switch (build_event) {
.Ok => {
stderr.print("Build {} succeeded\n", count) catch process.exit(1);
stderr.print("Build {} succeeded\n", .{count}) catch process.exit(1);
},
.Error => |err| {
stderr.print("Build {} failed: {}\n", count, @errorName(err)) catch process.exit(1);
stderr.print("Build {} failed: {}\n", .{ count, @errorName(err) }) catch process.exit(1);
},
.Fail => |msgs| {
stderr.print("Build {} compile errors:\n", count) catch process.exit(1);
stderr.print("Build {} compile errors:\n", .{count}) catch process.exit(1);
for (msgs) |msg| {
defer msg.destroy();
msg.printToFile(stderr_file, color) catch process.exit(1);
@ -544,12 +544,11 @@ const Fmt = struct {
fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_file: []const u8) void {
libc.parse(allocator, libc_paths_file, stderr) catch |err| {
stderr.print(
"Unable to parse libc path file '{}': {}.\n" ++
"Try running `zig libc` to see an example for the native target.\n",
stderr.print("Unable to parse libc path file '{}': {}.\n" ++
"Try running `zig libc` to see an example for the native target.\n", .{
libc_paths_file,
@errorName(err),
) catch {};
}) catch {};
process.exit(1);
};
}
@ -563,7 +562,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
return;
},
else => {
try stderr.print("unexpected extra parameter: {}\n", args[1]);
try stderr.print("unexpected extra parameter: {}\n", .{args[1]});
process.exit(1);
},
}
@ -572,7 +571,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
defer zig_compiler.deinit();
const libc = zig_compiler.getNativeLibC() catch |err| {
stderr.print("unable to find libc: {}\n", @errorName(err)) catch {};
stderr.print("unable to find libc: {}\n", .{@errorName(err)}) catch {};
process.exit(1);
};
libc.render(stdout) catch process.exit(1);
@ -614,7 +613,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
defer allocator.free(source_code);
const tree = std.zig.parse(allocator, source_code) catch |err| {
try stderr.print("error parsing stdin: {}\n", err);
try stderr.print("error parsing stdin: {}\n", .{err});
process.exit(1);
};
defer tree.deinit();
@ -718,7 +717,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
},
else => {
// TODO lock stderr printing
try stderr.print("unable to open '{}': {}\n", file_path, err);
try stderr.print("unable to open '{}': {}\n", .{ file_path, err });
fmt.any_error = true;
return;
},
@ -726,7 +725,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
defer fmt.allocator.free(source_code);
const tree = std.zig.parse(fmt.allocator, source_code) catch |err| {
try stderr.print("error parsing file '{}': {}\n", file_path, err);
try stderr.print("error parsing file '{}': {}\n", .{ file_path, err });
fmt.any_error = true;
return;
};
@ -747,7 +746,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
if (check_mode) {
const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree);
if (anything_changed) {
try stderr.print("{}\n", file_path);
try stderr.print("{}\n", .{file_path});
fmt.any_error = true;
}
} else {
@ -757,7 +756,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree);
if (anything_changed) {
try stderr.print("{}\n", file_path);
try stderr.print("{}\n", .{file_path});
try baf.finish();
}
}
@ -774,7 +773,7 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
// NOTE: Cannot use empty string, see #918.
comptime const native_str = if (comptime mem.eql(u8, arch_tag, @tagName(builtin.arch))) " (native)\n" else "\n";
try stdout.print(" {}{}", arch_tag, native_str);
try stdout.print(" {}{}", .{ arch_tag, native_str });
}
}
try stdout.write("\n");
@ -787,7 +786,7 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
// NOTE: Cannot use empty string, see #918.
comptime const native_str = if (comptime mem.eql(u8, os_tag, @tagName(builtin.os))) " (native)\n" else "\n";
try stdout.print(" {}{}", os_tag, native_str);
try stdout.print(" {}{}", .{ os_tag, native_str });
}
}
try stdout.write("\n");
@ -800,13 +799,13 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
// NOTE: Cannot use empty string, see #918.
comptime const native_str = if (comptime mem.eql(u8, abi_tag, @tagName(builtin.abi))) " (native)\n" else "\n";
try stdout.print(" {}{}", abi_tag, native_str);
try stdout.print(" {}{}", .{ abi_tag, native_str });
}
}
}
fn cmdVersion(allocator: *Allocator, args: []const []const u8) !void {
try stdout.print("{}\n", std.mem.toSliceConst(u8, c.ZIG_VERSION_STRING));
try stdout.print("{}\n", .{std.mem.toSliceConst(u8, c.ZIG_VERSION_STRING)});
}
const args_test_spec = [_]Flag{Flag.Bool("--help")};
@ -865,7 +864,7 @@ fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {
}
}
try stderr.print("unknown sub command: {}\n\n", args[0]);
try stderr.print("unknown sub command: {}\n\n", .{args[0]});
try stderr.write(usage_internal);
}
@ -878,14 +877,14 @@ fn cmdInternalBuildInfo(allocator: *Allocator, args: []const []const u8) !void {
\\ZIG_LLVM_CONFIG_EXE {}
\\ZIG_DIA_GUIDS_LIB {}
\\
,
, .{
std.mem.toSliceConst(u8, c.ZIG_CMAKE_BINARY_DIR),
std.mem.toSliceConst(u8, c.ZIG_CXX_COMPILER),
std.mem.toSliceConst(u8, c.ZIG_LLD_INCLUDE_PATH),
std.mem.toSliceConst(u8, c.ZIG_LLD_LIBRARIES),
std.mem.toSliceConst(u8, c.ZIG_LLVM_CONFIG_EXE),
std.mem.toSliceConst(u8, c.ZIG_DIA_GUIDS_LIB),
);
});
}
const CliPkg = struct {

View File

@ -399,7 +399,7 @@ pub const Type = struct {
.Generic => |generic| {
self.non_key = NonKey{ .Generic = {} };
const cc_str = ccFnTypeStr(generic.cc);
try name_stream.print("{}fn(", cc_str);
try name_stream.print("{}fn(", .{cc_str});
var param_i: usize = 0;
while (param_i < generic.param_count) : (param_i += 1) {
const arg = if (param_i == 0) "var" else ", var";
@ -407,7 +407,7 @@ pub const Type = struct {
}
try name_stream.write(")");
if (key.alignment) |alignment| {
try name_stream.print(" align({})", alignment);
try name_stream.print(" align({})", .{alignment});
}
try name_stream.write(" var");
},
@ -416,7 +416,7 @@ pub const Type = struct {
.Normal = NonKey.Normal{ .variable_list = std.ArrayList(*Scope.Var).init(comp.gpa()) },
};
const cc_str = ccFnTypeStr(normal.cc);
try name_stream.print("{}fn(", cc_str);
try name_stream.print("{}fn(", .{cc_str});
for (normal.params) |param, i| {
if (i != 0) try name_stream.write(", ");
if (param.is_noalias) try name_stream.write("noalias ");
@ -428,9 +428,9 @@ pub const Type = struct {
}
try name_stream.write(")");
if (key.alignment) |alignment| {
try name_stream.print(" align({})", alignment);
try name_stream.print(" align({})", .{alignment});
}
try name_stream.print(" {}", normal.return_type.name);
try name_stream.print(" {}", .{normal.return_type.name});
},
}
@ -584,7 +584,7 @@ pub const Type = struct {
errdefer comp.gpa().destroy(self);
const u_or_i = "ui"[@boolToInt(key.is_signed)];
const name = try std.fmt.allocPrint(comp.gpa(), "{c}{}", u_or_i, key.bit_count);
const name = try std.fmt.allocPrint(comp.gpa(), "{c}{}", .{ u_or_i, key.bit_count });
errdefer comp.gpa().free(name);
self.base.init(comp, .Int, name);
@ -767,23 +767,19 @@ pub const Type = struct {
.Non => "",
};
const name = switch (self.key.alignment) {
.Abi => try std.fmt.allocPrint(
comp.gpa(),
"{}{}{}{}",
.Abi => try std.fmt.allocPrint(comp.gpa(), "{}{}{}{}", .{
size_str,
mut_str,
vol_str,
self.key.child_type.name,
),
.Override => |alignment| try std.fmt.allocPrint(
comp.gpa(),
"{}align<{}> {}{}{}",
}),
.Override => |alignment| try std.fmt.allocPrint(comp.gpa(), "{}align<{}> {}{}{}", .{
size_str,
alignment,
mut_str,
vol_str,
self.key.child_type.name,
),
}),
};
errdefer comp.gpa().free(name);
@ -852,7 +848,7 @@ pub const Type = struct {
};
errdefer comp.gpa().destroy(self);
const name = try std.fmt.allocPrint(comp.gpa(), "[{}]{}", key.len, key.elem_type.name);
const name = try std.fmt.allocPrint(comp.gpa(), "[{}]{}", .{ key.len, key.elem_type.name });
errdefer comp.gpa().free(name);
self.base.init(comp, .Array, name);

View File

@ -175,7 +175,7 @@ pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target {
var result: *llvm.Target = undefined;
var err_msg: [*:0]u8 = undefined;
if (llvm.GetTargetFromTriple(triple.toSlice(), &result, &err_msg) != 0) {
std.debug.warn("triple: {s} error: {s}\n", triple.toSlice(), err_msg);
std.debug.warn("triple: {s} error: {s}\n", .{ triple.toSlice(), err_msg });
return error.UnsupportedTarget;
}
return result;
@ -206,7 +206,7 @@ pub fn getTriple(allocator: *std.mem.Allocator, self: std.Target) !std.Buffer {
const env_name = if (self.isWasm()) "wasm" else @tagName(self.getAbi());
var out = &std.io.BufferOutStream.init(&result).stream;
try out.print("{}-unknown-{}-{}", @tagName(self.getArch()), @tagName(self.getOs()), env_name);
try out.print("{}-unknown-{}-{}", .{ @tagName(self.getArch()), @tagName(self.getOs()), env_name });
return result;
}

View File

@ -53,7 +53,7 @@ pub const Value = struct {
}
pub fn dump(base: *const Value) void {
std.debug.warn("{}", @tagName(base.id));
std.debug.warn("{}", .{@tagName(base.id)});
}
pub fn getLlvmConst(base: *Value, ofile: *ObjectFile) (error{OutOfMemory}!?*llvm.Value) {