From 03a0dfbeca4b31d235097c66c9891d825cf73c15 Mon Sep 17 00:00:00 2001 From: scurest Date: Mon, 23 Oct 2017 15:40:49 -0500 Subject: Print better floats --- std/fmt/errol/index.zig | 12 ++++++------ std/fmt/index.zig | 38 +++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 17 deletions(-) (limited to 'std') diff --git a/std/fmt/errol/index.zig b/std/fmt/errol/index.zig index ac9f6b0c64..8cf13bca2e 100644 --- a/std/fmt/errol/index.zig +++ b/std/fmt/errol/index.zig @@ -38,7 +38,7 @@ fn errol3u(val: f64, buffer: []u8) -> FloatDecimal { return errolFixed(val, buffer); } - + // normalize the midpoint const e = math.frexp(val).exponent; @@ -138,7 +138,7 @@ fn tableLowerBound(k: u64) -> usize { while (j < enum3.len) { if (enum3[j] < k) { - j = 2 * k + 2; + j = 2 * j + 2; } else { i = j; j = 2 * j + 1; @@ -217,7 +217,7 @@ fn hpMul10(hp: &HP) { hp.val *= 10.0; hp.off *= 10.0; - + var off = hp.val; off -= val * 8.0; off -= val * 2.0; @@ -241,7 +241,7 @@ fn errolInt(val: f64, buffer: []u8) -> FloatDecimal { var low: u128 = mid - fpeint((fpnext(val) - val) / 2.0); var high: u128 = mid + fpeint((val - fpprev(val)) / 2.0); - if (@bitCast(u64, val) & 0x1 != 0) { + if (@bitCast(u64, val) & 0x1 != 0) { high -= 1; } else { low -= 1; @@ -347,11 +347,11 @@ fn errolFixed(val: f64, buffer: []u8) -> FloatDecimal { } fn fpnext(val: f64) -> f64 { - return @bitCast(f64, @bitCast(u64, val) + 1); + return @bitCast(f64, @bitCast(u64, val) +% 1); } fn fpprev(val: f64) -> f64 { - return @bitCast(f64, @bitCast(u64, val) - 1); + return @bitCast(f64, @bitCast(u64, val) -% 1); } pub const c_digits_lut = []u8 { diff --git a/std/fmt/index.zig b/std/fmt/index.zig index b378afa1b0..85688b361d 100644 --- a/std/fmt/index.zig +++ b/std/fmt/index.zig @@ -244,30 +244,46 @@ pub fn formatBuf(buf: []const u8, width: usize, } pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []const u8)->bool) -> bool { - var buffer: [20]u8 = undefined; - const float_decimal = errol3(f64(value), buffer[0..]); - if (float_decimal.exp != 0) { - if (!output(context, float_decimal.digits[0..1])) - return false; - } else { - if (!output(context, "0")) + var x = f64(value); + + // Errol doesn't handle these special cases. + if (math.isNan(x)) { + return output(context, "NaN"); + } + if (math.isPositiveInf(x)) { + return output(context, "Infinity"); + } + if (math.isNegativeInf(x)) { + return output(context, "-Infinity"); + } + if (x == 0.0) { + return output(context, "0.0"); + } + if (x < 0.0) { + if (!output(context, "-")) return false; + x = -x; } + + var buffer: [32]u8 = undefined; + const float_decimal = errol3(x, buffer[0..]); + if (!output(context, float_decimal.digits[0..1])) + return false; if (!output(context, ".")) return false; if (float_decimal.digits.len > 1) { - const start = if (float_decimal.exp == 0) usize(0) else usize(1); - if (!output(context, float_decimal.digits[start .. math.min(usize(7), float_decimal.digits.len)])) + const num_digits = if (@typeOf(value) == f32) { usize(8) } else { usize(17) }; + if (!output(context, float_decimal.digits[1 .. math.min(num_digits, float_decimal.digits.len)])) return false; } else { if (!output(context, "0")) return false; } - if (float_decimal.exp != 1 and float_decimal.exp != 0) { + if (float_decimal.exp != 1) { if (!output(context, "e")) return false; - if (!formatInt(float_decimal.exp, 10, false, 0, context, output)) + if (!formatInt(float_decimal.exp - 1, 10, false, 0, context, output)) return false; } return true; -- cgit v1.2.3 From 262b7428cfad88de9d328773cc4bae6151b8a030 Mon Sep 17 00:00:00 2001 From: scurest Date: Tue, 24 Oct 2017 14:18:50 -0500 Subject: More corrections to float printing Testing suggests all f32s are now printed accurately. --- std/fmt/errol/index.zig | 10 +++------- std/fmt/index.zig | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 17 deletions(-) (limited to 'std') diff --git a/std/fmt/errol/index.zig b/std/fmt/errol/index.zig index 8cf13bca2e..0a1ea7deef 100644 --- a/std/fmt/errol/index.zig +++ b/std/fmt/errol/index.zig @@ -32,7 +32,7 @@ pub fn errol3(value: f64, buffer: []u8) -> FloatDecimal { fn errol3u(val: f64, buffer: []u8) -> FloatDecimal { // check if in integer or fixed range - if (val >= 9.007199254740992e15 and val < 3.40282366920938e+38) { + if (val > 9.007199254740992e15 and val < 3.40282366920938e+38) { return errolInt(val, buffer); } else if (val >= 16.0 and val < 9.007199254740992e15) { return errolFixed(val, buffer); @@ -235,7 +235,7 @@ fn hpMul10(hp: &HP) { fn errolInt(val: f64, buffer: []u8) -> FloatDecimal { const pow19 = u128(1e19); - assert((val >= 9.007199254740992e15) and val < (3.40282366920938e38)); + assert((val > 9.007199254740992e15) and val < (3.40282366920938e38)); var mid = u128(val); var low: u128 = mid - fpeint((fpnext(val) - val) / 2.0); @@ -510,10 +510,6 @@ fn u64toa(value_param: u64, buffer: []u8) -> usize { buf_index += 1; buffer[buf_index] = c_digits_lut[d8]; buf_index += 1; - buffer[buf_index] = c_digits_lut[d8]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d8]; - buf_index += 1; buffer[buf_index] = c_digits_lut[d8 + 1]; buf_index += 1; } else { @@ -613,7 +609,7 @@ fn fpeint(from: f64) -> u128 { const bits = @bitCast(u64, from); assert((bits & ((1 << 52) - 1)) == 0); - return u64(1) << u6(((bits >> 52) - 1023)); + return u128(1) << @truncate(u7, (bits >> 52) -% 1023); } diff --git a/std/fmt/index.zig b/std/fmt/index.zig index 85688b361d..0fece54b4c 100644 --- a/std/fmt/index.zig +++ b/std/fmt/index.zig @@ -250,20 +250,17 @@ pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []cons if (math.isNan(x)) { return output(context, "NaN"); } + if (math.signbit(x)) { + if (!output(context, "-")) + return false; + x = -x; + } if (math.isPositiveInf(x)) { return output(context, "Infinity"); } - if (math.isNegativeInf(x)) { - return output(context, "-Infinity"); - } if (x == 0.0) { return output(context, "0.0"); } - if (x < 0.0) { - if (!output(context, "-")) - return false; - x = -x; - } var buffer: [32]u8 = undefined; const float_decimal = errol3(x, buffer[0..]); @@ -272,8 +269,12 @@ pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []cons if (!output(context, ".")) return false; if (float_decimal.digits.len > 1) { - const num_digits = if (@typeOf(value) == f32) { usize(8) } else { usize(17) }; - if (!output(context, float_decimal.digits[1 .. math.min(num_digits, float_decimal.digits.len)])) + const num_digits = if (@typeOf(value) == f32) { + math.min(usize(9), float_decimal.digits.len) + } else { + float_decimal.digits.len + }; + if (!output(context, float_decimal.digits[1 .. num_digits])) return false; } else { if (!output(context, "0")) -- cgit v1.2.3 From 1828f8eb8e1514578ed2da8d58536903f94b7ed0 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 24 Oct 2017 21:28:56 -0400 Subject: fix missing compiler_rt in release modes the optimizer was deleting compiler_rt symbols, so I changed the linkage type from LinkOnce to Weak also changed LinkOnce to mean linkonce_odr in llvm and Weak to mean weak_odr in llvm. See #563 --- src/codegen.cpp | 4 ++-- src/link.cpp | 1 + std/special/compiler_rt/comparetf2.zig | 2 +- std/special/compiler_rt/fixunsdfdi.zig | 2 +- std/special/compiler_rt/fixunsdfsi.zig | 2 +- std/special/compiler_rt/fixunsdfti.zig | 2 +- std/special/compiler_rt/fixunssfdi.zig | 2 +- std/special/compiler_rt/fixunssfsi.zig | 2 +- std/special/compiler_rt/fixunssfti.zig | 2 +- std/special/compiler_rt/fixunstfdi.zig | 2 +- std/special/compiler_rt/fixunstfsi.zig | 2 +- std/special/compiler_rt/fixunstfti.zig | 2 +- std/special/compiler_rt/index.zig | 6 +----- std/special/compiler_rt/udivmoddi4.zig | 2 +- std/special/compiler_rt/udivmodti4.zig | 2 +- std/special/compiler_rt/udivti3.zig | 2 +- std/special/compiler_rt/umodti3.zig | 2 +- 17 files changed, 18 insertions(+), 21 deletions(-) (limited to 'std') diff --git a/src/codegen.cpp b/src/codegen.cpp index 8c5d7622cc..6fb8d4b8ef 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -456,10 +456,10 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) { LLVMSetLinkage(fn_table_entry->llvm_value, LLVMExternalLinkage); break; case GlobalLinkageIdWeak: - LLVMSetLinkage(fn_table_entry->llvm_value, LLVMWeakAnyLinkage); + LLVMSetLinkage(fn_table_entry->llvm_value, LLVMWeakODRLinkage); break; case GlobalLinkageIdLinkOnce: - LLVMSetLinkage(fn_table_entry->llvm_value, LLVMLinkOnceAnyLinkage); + LLVMSetLinkage(fn_table_entry->llvm_value, LLVMLinkOnceODRLinkage); break; } diff --git a/src/link.cpp b/src/link.cpp index f2f21fd746..316c7bc761 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -38,6 +38,7 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) child_gen->want_h_file = false; child_gen->verbose_link = parent_gen->verbose_link; + child_gen->verbose_ir = parent_gen->verbose_ir; codegen_set_cache_dir(child_gen, parent_gen->cache_dir); diff --git a/std/special/compiler_rt/comparetf2.zig b/std/special/compiler_rt/comparetf2.zig index 45c7cb5037..f1552ca61f 100644 --- a/std/special/compiler_rt/comparetf2.zig +++ b/std/special/compiler_rt/comparetf2.zig @@ -20,7 +20,7 @@ const infRep = exponentMask; const builtin = @import("builtin"); const is_test = builtin.is_test; -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __letf2(a: f128, b: f128) -> c_int { @setDebugSafety(this, is_test); diff --git a/std/special/compiler_rt/fixunsdfdi.zig b/std/special/compiler_rt/fixunsdfdi.zig index 0290ad3975..5f730bbc85 100644 --- a/std/special/compiler_rt/fixunsdfdi.zig +++ b/std/special/compiler_rt/fixunsdfdi.zig @@ -1,6 +1,6 @@ const fixuint = @import("fixuint.zig").fixuint; const builtin = @import("builtin"); -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __fixunsdfdi(a: f64) -> u64 { @setDebugSafety(this, builtin.is_test); diff --git a/std/special/compiler_rt/fixunsdfsi.zig b/std/special/compiler_rt/fixunsdfsi.zig index 1dbc2525f2..784d5fde4f 100644 --- a/std/special/compiler_rt/fixunsdfsi.zig +++ b/std/special/compiler_rt/fixunsdfsi.zig @@ -1,6 +1,6 @@ const fixuint = @import("fixuint.zig").fixuint; const builtin = @import("builtin"); -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __fixunsdfsi(a: f64) -> u32 { @setDebugSafety(this, builtin.is_test); diff --git a/std/special/compiler_rt/fixunsdfti.zig b/std/special/compiler_rt/fixunsdfti.zig index 33b0e7c274..579455c2f9 100644 --- a/std/special/compiler_rt/fixunsdfti.zig +++ b/std/special/compiler_rt/fixunsdfti.zig @@ -1,6 +1,6 @@ const fixuint = @import("fixuint.zig").fixuint; const builtin = @import("builtin"); -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __fixunsdfti(a: f64) -> u128 { @setDebugSafety(this, builtin.is_test); diff --git a/std/special/compiler_rt/fixunssfdi.zig b/std/special/compiler_rt/fixunssfdi.zig index c183f17c62..eab553d8c9 100644 --- a/std/special/compiler_rt/fixunssfdi.zig +++ b/std/special/compiler_rt/fixunssfdi.zig @@ -1,6 +1,6 @@ const fixuint = @import("fixuint.zig").fixuint; const builtin = @import("builtin"); -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __fixunssfdi(a: f32) -> u64 { @setDebugSafety(this, builtin.is_test); diff --git a/std/special/compiler_rt/fixunssfsi.zig b/std/special/compiler_rt/fixunssfsi.zig index 51ceef65d3..18c0e66677 100644 --- a/std/special/compiler_rt/fixunssfsi.zig +++ b/std/special/compiler_rt/fixunssfsi.zig @@ -1,6 +1,6 @@ const fixuint = @import("fixuint.zig").fixuint; const builtin = @import("builtin"); -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __fixunssfsi(a: f32) -> u32 { @setDebugSafety(this, builtin.is_test); diff --git a/std/special/compiler_rt/fixunssfti.zig b/std/special/compiler_rt/fixunssfti.zig index 69e1c82a9d..f513604247 100644 --- a/std/special/compiler_rt/fixunssfti.zig +++ b/std/special/compiler_rt/fixunssfti.zig @@ -1,6 +1,6 @@ const fixuint = @import("fixuint.zig").fixuint; const builtin = @import("builtin"); -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __fixunssfti(a: f32) -> u128 { @setDebugSafety(this, builtin.is_test); diff --git a/std/special/compiler_rt/fixunstfdi.zig b/std/special/compiler_rt/fixunstfdi.zig index a5dbe0f52e..85212e2176 100644 --- a/std/special/compiler_rt/fixunstfdi.zig +++ b/std/special/compiler_rt/fixunstfdi.zig @@ -1,6 +1,6 @@ const fixuint = @import("fixuint.zig").fixuint; const builtin = @import("builtin"); -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __fixunstfdi(a: f128) -> u64 { @setDebugSafety(this, builtin.is_test); diff --git a/std/special/compiler_rt/fixunstfsi.zig b/std/special/compiler_rt/fixunstfsi.zig index d488f4c602..33c85c9224 100644 --- a/std/special/compiler_rt/fixunstfsi.zig +++ b/std/special/compiler_rt/fixunstfsi.zig @@ -1,6 +1,6 @@ const fixuint = @import("fixuint.zig").fixuint; const builtin = @import("builtin"); -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __fixunstfsi(a: f128) -> u32 { @setDebugSafety(this, builtin.is_test); diff --git a/std/special/compiler_rt/fixunstfti.zig b/std/special/compiler_rt/fixunstfti.zig index fc5c645d72..1bf7fbab4b 100644 --- a/std/special/compiler_rt/fixunstfti.zig +++ b/std/special/compiler_rt/fixunstfti.zig @@ -1,6 +1,6 @@ const fixuint = @import("fixuint.zig").fixuint; const builtin = @import("builtin"); -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __fixunstfti(a: f128) -> u128 { @setDebugSafety(this, builtin.is_test); diff --git a/std/special/compiler_rt/index.zig b/std/special/compiler_rt/index.zig index 4a4d71fde9..bea06a0b41 100644 --- a/std/special/compiler_rt/index.zig +++ b/std/special/compiler_rt/index.zig @@ -26,7 +26,7 @@ const win32 = builtin.os == builtin.Os.windows and builtin.arch == builtin.Arch. const win64 = builtin.os == builtin.Os.windows and builtin.arch == builtin.Arch.x86_64; const win32_nocrt = win32 and !builtin.link_libc; const win64_nocrt = win64 and !builtin.link_libc; -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +pub const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Weak; const strong_linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Strong; const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4; @@ -152,10 +152,6 @@ export nakedcc fn _chkstk() align(4) { @setGlobalLinkage(_chkstk, builtin.GlobalLinkage.Internal); } -// TODO The implementation from compiler-rt causes crashes and -// the implementation from disassembled ntdll seems to depend on -// thread local storage. So we have given up this safety check -// and simply have `ret`. export nakedcc fn __chkstk() align(4) { @setDebugSafety(this, false); diff --git a/std/special/compiler_rt/udivmoddi4.zig b/std/special/compiler_rt/udivmoddi4.zig index 2e167bc64a..8005538d9a 100644 --- a/std/special/compiler_rt/udivmoddi4.zig +++ b/std/special/compiler_rt/udivmoddi4.zig @@ -1,6 +1,6 @@ const udivmod = @import("udivmod.zig").udivmod; const builtin = @import("builtin"); -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?&u64) -> u64 { @setDebugSafety(this, builtin.is_test); diff --git a/std/special/compiler_rt/udivmodti4.zig b/std/special/compiler_rt/udivmodti4.zig index d7507e9521..2ee2fdb57f 100644 --- a/std/special/compiler_rt/udivmodti4.zig +++ b/std/special/compiler_rt/udivmodti4.zig @@ -1,6 +1,6 @@ const udivmod = @import("udivmod.zig").udivmod; const builtin = @import("builtin"); -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) -> u128 { @setDebugSafety(this, builtin.is_test); diff --git a/std/special/compiler_rt/udivti3.zig b/std/special/compiler_rt/udivti3.zig index 67ea15eb96..3764449758 100644 --- a/std/special/compiler_rt/udivti3.zig +++ b/std/special/compiler_rt/udivti3.zig @@ -1,6 +1,6 @@ const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4; const builtin = @import("builtin"); -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __udivti3(a: u128, b: u128) -> u128 { @setDebugSafety(this, builtin.is_test); diff --git a/std/special/compiler_rt/umodti3.zig b/std/special/compiler_rt/umodti3.zig index e4a4e7a7ee..0ad9e127b3 100644 --- a/std/special/compiler_rt/umodti3.zig +++ b/std/special/compiler_rt/umodti3.zig @@ -1,6 +1,6 @@ const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4; const builtin = @import("builtin"); -const linkage = if (builtin.is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.LinkOnce; +const linkage = @import("index.zig").linkage; export fn __umodti3(a: u128, b: u128) -> u128 { @setDebugSafety(this, builtin.is_test); -- cgit v1.2.3 From 73fe5f63c6acc1b2e6fec51da545178ffd12180e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 24 Oct 2017 21:45:00 -0400 Subject: add some sanity tests for float printing --- std/fmt/index.zig | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'std') diff --git a/std/fmt/index.zig b/std/fmt/index.zig index 0fece54b4c..56b9a2e960 100644 --- a/std/fmt/index.zig +++ b/std/fmt/index.zig @@ -531,6 +531,38 @@ test "fmt.format" { const result = bufPrint(buf1[0..], "u3: {}\n", value); assert(mem.eql(u8, result, "u3: 5\n")); } + + // TODO get these tests passing in release modes + // https://github.com/zig-lang/zig/issues/564 + if (builtin.mode == builtin.Mode.Debug) { + { + var buf1: [32]u8 = undefined; + const value: f32 = 12.34; + const result = bufPrint(buf1[0..], "f32: {}\n", value); + assert(mem.eql(u8, result, "f32: 1.23400001e1\n")); + } + { + var buf1: [32]u8 = undefined; + const value: f64 = -12.34e10; + const result = bufPrint(buf1[0..], "f64: {}\n", value); + assert(mem.eql(u8, result, "f64: -1.234e11\n")); + } + { + var buf1: [32]u8 = undefined; + const result = bufPrint(buf1[0..], "f64: {}\n", math.nan_f64); + assert(mem.eql(u8, result, "f64: NaN\n")); + } + { + var buf1: [32]u8 = undefined; + const result = bufPrint(buf1[0..], "f64: {}\n", math.inf_f64); + assert(mem.eql(u8, result, "f64: Infinity\n")); + } + { + var buf1: [32]u8 = undefined; + const result = bufPrint(buf1[0..], "f64: {}\n", -math.inf_f64); + assert(mem.eql(u8, result, "f64: -Infinity\n")); + } + } } pub fn trim(buf: []const u8) -> []const u8 { -- cgit v1.2.3 From 5f28a9d23851d94edc2b24e549b7c5abbbf23f68 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 25 Oct 2017 23:10:41 -0400 Subject: cleaner verbose flags and zig build prints failed command --- src/all_types.hpp | 5 +- src/analyze.cpp | 10 +-- src/codegen.cpp | 18 +----- src/codegen.hpp | 1 - src/ir.cpp | 6 +- src/link.cpp | 21 +++---- src/main.cpp | 142 ++++++++++++++++++++++++++----------------- src/parsec.cpp | 2 +- std/build.zig | 39 +++++++++--- std/special/build_runner.zig | 39 +++++++++--- 10 files changed, 171 insertions(+), 112 deletions(-) (limited to 'std') diff --git a/src/all_types.hpp b/src/all_types.hpp index 894deca930..b8966e764a 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1515,9 +1515,12 @@ struct CodeGen { size_t version_major; size_t version_minor; size_t version_patch; - bool verbose; + bool verbose_tokenize; + bool verbose_ast; bool verbose_link; bool verbose_ir; + bool verbose_llvm_ir; + bool verbose_cimport; ErrColor err_color; ImportTableEntry *root_import; ImportTableEntry *bootstrap_import; diff --git a/src/analyze.cpp b/src/analyze.cpp index 292943a6e6..45efa205e3 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2982,7 +2982,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ return; } - if (g->verbose) { + if (g->verbose_ir) { fprintf(stderr, "{ // (analyzed)\n"); ir_print(g, stderr, &fn_table_entry->analyzed_executable, 4); fprintf(stderr, "}\n"); @@ -3015,7 +3015,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) { fn_table_entry->anal_state = FnAnalStateInvalid; return; } - if (g->verbose) { + if (g->verbose_ir) { fprintf(stderr, "\n"); ast_render(g, stderr, fn_table_entry->body_node, 4); fprintf(stderr, "\n{ // (IR)\n"); @@ -3115,7 +3115,7 @@ void preview_use_decl(CodeGen *g, AstNode *node) { } ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code) { - if (g->verbose) { + if (g->verbose_tokenize) { fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(abs_full_path)); fprintf(stderr, "----------------\n"); fprintf(stderr, "%s\n", buf_ptr(source_code)); @@ -3135,7 +3135,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a exit(1); } - if (g->verbose) { + if (g->verbose_tokenize) { print_tokens(source_code, tokenization.tokens); fprintf(stderr, "\nAST:\n"); @@ -3150,7 +3150,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color); assert(import_entry->root); - if (g->verbose) { + if (g->verbose_ast) { ast_print(stderr, import_entry->root, 0); } diff --git a/src/codegen.cpp b/src/codegen.cpp index 6fb8d4b8ef..68fd4159bd 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -196,10 +196,6 @@ void codegen_set_is_static(CodeGen *g, bool is_static) { g->is_static = is_static; } -void codegen_set_verbose(CodeGen *g, bool verbose) { - g->verbose = verbose; -} - void codegen_set_each_lib_rpath(CodeGen *g, bool each_lib_rpath) { g->each_lib_rpath = each_lib_rpath; } @@ -4163,10 +4159,6 @@ static void validate_inline_fns(CodeGen *g) { } static void do_code_gen(CodeGen *g) { - if (g->verbose) { - fprintf(stderr, "\nCode Generation:\n"); - fprintf(stderr, "------------------\n"); - } assert(!g->errors.length); codegen_add_time_event(g, "Code Generation"); @@ -4443,7 +4435,8 @@ static void do_code_gen(CodeGen *g) { ZigLLVMDIBuilderFinalize(g->dbuilder); - if (g->verbose || g->verbose_ir) { + if (g->verbose_llvm_ir) { + fflush(stderr); LLVMDumpModule(g->module); } @@ -5273,10 +5266,6 @@ static void gen_root_source(CodeGen *g) { resolve_top_level_decl(g, panic_tld, false, nullptr); } - if (g->verbose) { - fprintf(stderr, "\nIR Generation and Semantic Analysis:\n"); - fprintf(stderr, "--------------------------------------\n"); - } if (!g->error_during_imports) { semantic_analyze(g); } @@ -5290,9 +5279,6 @@ static void gen_root_source(CodeGen *g) { } report_errors_and_maybe_exit(g); - if (g->verbose) { - fprintf(stderr, "OK\n"); - } } diff --git a/src/codegen.hpp b/src/codegen.hpp index f4c7f6a8c7..cc7721e9f8 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -25,7 +25,6 @@ void codegen_set_each_lib_rpath(CodeGen *codegen, bool each_lib_rpath); void codegen_set_is_static(CodeGen *codegen, bool is_static); void codegen_set_strip(CodeGen *codegen, bool strip); -void codegen_set_verbose(CodeGen *codegen, bool verbose); void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color); void codegen_set_out_name(CodeGen *codegen, Buf *out_name); void codegen_set_libc_lib_dir(CodeGen *codegen, Buf *libc_lib_dir); diff --git a/src/ir.cpp b/src/ir.cpp index 787d58442e..6c6ce676f6 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -7849,7 +7849,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node if (ir_executable.invalid) return codegen->invalid_instruction; - if (codegen->verbose) { + if (codegen->verbose_ir) { fprintf(stderr, "\nSource: "); ast_render(codegen, stderr, node, 4); fprintf(stderr, "\n{ // (IR)\n"); @@ -7870,7 +7870,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node if (type_is_invalid(result_type)) return codegen->invalid_instruction; - if (codegen->verbose) { + if (codegen->verbose_ir) { fprintf(stderr, "{ // (analyzed)\n"); ir_print(codegen, stderr, &analyzed_executable, 4); fprintf(stderr, "}\n"); @@ -13514,7 +13514,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc return ira->codegen->builtin_types.entry_invalid; } - if (ira->codegen->verbose) { + if (ira->codegen->verbose_cimport) { fprintf(stderr, "\nC imports:\n"); fprintf(stderr, "-----------\n"); ast_render(ira->codegen, stderr, child_import->root, 4); diff --git a/src/link.cpp b/src/link.cpp index 316c7bc761..a4e5b2dd25 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -37,8 +37,12 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) parent_gen->zig_lib_dir); child_gen->want_h_file = false; + child_gen->verbose_tokenize = parent_gen->verbose_tokenize; + child_gen->verbose_ast = parent_gen->verbose_ast; child_gen->verbose_link = parent_gen->verbose_link; child_gen->verbose_ir = parent_gen->verbose_ir; + child_gen->verbose_llvm_ir = parent_gen->verbose_llvm_ir; + child_gen->verbose_cimport = parent_gen->verbose_cimport; codegen_set_cache_dir(child_gen, parent_gen->cache_dir); @@ -47,7 +51,6 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) codegen_set_out_name(child_gen, buf_create_from_str(oname)); - codegen_set_verbose(child_gen, parent_gen->verbose); codegen_set_errmsg_color(child_gen, parent_gen->err_color); codegen_set_mmacosx_version_min(child_gen, parent_gen->mmacosx_version_min); @@ -859,15 +862,12 @@ void codegen_link(CodeGen *g, const char *out_file) { buf_resize(&lj.out_file, 0); } - if (g->verbose || g->verbose_ir) { + if (g->verbose_llvm_ir) { fprintf(stderr, "\nOptimization:\n"); fprintf(stderr, "---------------\n"); + fflush(stderr); LLVMDumpModule(g->module); } - if (g->verbose || g->verbose_link) { - fprintf(stderr, "\nLink:\n"); - fprintf(stderr, "-------\n"); - } bool override_out_file = (buf_len(&lj.out_file) != 0); if (!override_out_file) { @@ -888,9 +888,6 @@ void codegen_link(CodeGen *g, const char *out_file) { zig_panic("unable to rename object file into final output: %s", err_str(err)); } } - if (g->verbose || g->verbose_link) { - fprintf(stderr, "OK\n"); - } return; } @@ -908,7 +905,7 @@ void codegen_link(CodeGen *g, const char *out_file) { construct_linker_job(&lj); - if (g->verbose || g->verbose_link) { + if (g->verbose_link) { for (size_t i = 0; i < lj.args.length; i += 1) { const char *space = (i != 0) ? " " : ""; fprintf(stderr, "%s%s", space, lj.args.at(i)); @@ -925,8 +922,4 @@ void codegen_link(CodeGen *g, const char *out_file) { } codegen_add_time_event(g, "Done"); - - if (g->verbose || g->verbose_link) { - fprintf(stderr, "OK\n"); - } } diff --git a/src/main.cpp b/src/main.cpp index a9a1d5a8da..bee021c6a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,67 +20,70 @@ static int usage(const char *arg0) { fprintf(stderr, "Usage: %s [command] [options]\n" "Commands:\n" " build build project from build.zig\n" - " build-exe [source] create executable from source or object files\n" - " build-lib [source] create library from source or object files\n" - " build-obj [source] create object from source or assembly\n" - " parsec [source] convert c code to zig code\n" + " build-exe $source create executable from source or object files\n" + " build-lib $source create library from source or object files\n" + " build-obj $source create object from source or assembly\n" + " parsec $source convert c code to zig code\n" " targets list available compilation targets\n" - " test [source] create and run a test build\n" + " test $source create and run a test build\n" " version print version number and exit\n" " zen print zen of zig and exit\n" "Compile Options:\n" - " --assembly [source] add assembly file to build\n" - " --cache-dir [path] override the cache directory\n" - " --color [auto|off|on] enable or disable colored error messages\n" + " --assembly $source add assembly file to build\n" + " --cache-dir $path override the cache directory\n" + " --color $auto|off|on enable or disable colored error messages\n" " --enable-timing-info print timing diagnostics\n" - " --libc-include-dir [path] directory where libc stdlib.h resides\n" - " --name [name] override output name\n" - " --output [file] override destination path\n" - " --output-h [file] override generated header file path\n" - " --pkg-begin [name] [path] make package available to import and push current pkg\n" + " --libc-include-dir $path directory where libc stdlib.h resides\n" + " --name $name override output name\n" + " --output $file override destination path\n" + " --output-h $file override generated header file path\n" + " --pkg-begin $name $path make package available to import and push current pkg\n" " --pkg-end pop current pkg\n" " --release-fast build with optimizations on and safety off\n" " --release-safe build with optimizations on and safety on\n" " --static output will be statically linked\n" " --strip exclude debug symbols\n" - " --target-arch [name] specify target architecture\n" - " --target-environ [name] specify target environment\n" - " --target-os [name] specify target operating system\n" - " --verbose turn on compiler debug output\n" - " --verbose-link turn on compiler debug output for linking only\n" - " --verbose-ir turn on compiler debug output for IR only\n" - " --zig-install-prefix [path] override directory where zig thinks it is installed\n" - " -dirafter [dir] same as -isystem but do it last\n" - " -isystem [dir] add additional search path for other .h files\n" - " -mllvm [arg] additional arguments to forward to LLVM's option processing\n" + " --target-arch $name specify target architecture\n" + " --target-environ $name specify target environment\n" + " --target-os $name specify target operating system\n" + " --verbose-tokenize turn on compiler debug output for tokenization\n" + " --verbose-ast turn on compiler debug output for parsing into an AST\n" + " --verbose-link turn on compiler debug output for linking\n" + " --verbose-ir turn on compiler debug output for Zig IR\n" + " --verbose-llvm-ir turn on compiler debug output for LLVM IR\n" + " --verbose-cimport turn on compiler debug output for C imports\n" + " --zig-install-prefix $path override directory where zig thinks it is installed\n" + " -dirafter $dir same as -isystem but do it last\n" + " -isystem $dir add additional search path for other .h files\n" + " -mllvm $arg additional arguments to forward to LLVM's option processing\n" "Link Options:\n" - " --ar-path [path] set the path to ar\n" - " --dynamic-linker [path] set the path to ld.so\n" + " --ar-path $path set the path to ar\n" + " --dynamic-linker $path set the path to ld.so\n" " --each-lib-rpath add rpath for each used dynamic library\n" - " --libc-lib-dir [path] directory where libc crt1.o resides\n" - " --libc-static-lib-dir [path] directory where libc crtbegin.o resides\n" - " --msvc-lib-dir [path] (windows) directory where vcruntime.lib resides\n" - " --kernel32-lib-dir [path] (windows) directory where kernel32.lib resides\n" - " --library [lib] link against lib\n" - " --library-path [dir] add a directory to the library search path\n" - " --linker-script [path] use a custom linker script\n" - " --object [obj] add object file to build\n" - " -L[dir] alias for --library-path\n" + " --libc-lib-dir $path directory where libc crt1.o resides\n" + " --libc-static-lib-dir $path directory where libc crtbegin.o resides\n" + " --msvc-lib-dir $path (windows) directory where vcruntime.lib resides\n" + " --kernel32-lib-dir $path (windows) directory where kernel32.lib resides\n" + " --library $lib link against lib\n" + " --library-path $dir add a directory to the library search path\n" + " --linker-script $path use a custom linker script\n" + " --object $obj add object file to build\n" + " -L$dir alias for --library-path\n" " -rdynamic add all symbols to the dynamic symbol table\n" - " -rpath [path] add directory to the runtime library search path\n" + " -rpath $path add directory to the runtime library search path\n" " -mconsole (windows) --subsystem console to the linker\n" " -mwindows (windows) --subsystem windows to the linker\n" " -municode (windows) link with unicode\n" - " -framework [name] (darwin) link against framework\n" - " -mios-version-min [ver] (darwin) set iOS deployment target\n" - " -mmacosx-version-min [ver] (darwin) set Mac OS X deployment target\n" - " --ver-major [ver] dynamic library semver major version\n" - " --ver-minor [ver] dynamic library semver minor version\n" - " --ver-patch [ver] dynamic library semver patch version\n" + " -framework $name (darwin) link against framework\n" + " -mios-version-min $ver (darwin) set iOS deployment target\n" + " -mmacosx-version-min $ver (darwin) set Mac OS X deployment target\n" + " --ver-major $ver dynamic library semver major version\n" + " --ver-minor $ver dynamic library semver minor version\n" + " --ver-patch $ver dynamic library semver patch version\n" "Test Options:\n" - " --test-filter [text] skip tests that do not match filter\n" - " --test-name-prefix [text] add prefix to all tests\n" - " --test-cmd [arg] specify test execution command one arg at a time\n" + " --test-filter $text skip tests that do not match filter\n" + " --test-name-prefix $text add prefix to all tests\n" + " --test-cmd $arg specify test execution command one arg at a time\n" " --test-cmd-bin appends test binary path to test cmd args\n" , arg0); return EXIT_FAILURE; @@ -274,9 +277,12 @@ int main(int argc, char **argv) { bool is_static = false; OutType out_type = OutTypeUnknown; const char *out_name = nullptr; - bool verbose = false; + bool verbose_tokenize = false; + bool verbose_ast = false; bool verbose_link = false; bool verbose_ir = false; + bool verbose_llvm_ir = false; + bool verbose_cimport = false; ErrColor color = ErrColorAuto; const char *libc_lib_dir = nullptr; const char *libc_static_lib_dir = nullptr; @@ -328,9 +334,7 @@ int main(int argc, char **argv) { args.append(NULL); // placeholder args.append(NULL); // placeholder for (int i = 2; i < argc; i += 1) { - if (strcmp(argv[i], "--debug-build-verbose") == 0) { - verbose = true; - } else if (strcmp(argv[i], "--help") == 0) { + if (strcmp(argv[i], "--help") == 0) { asked_for_help = true; args.append(argv[i]); } else if (i + 1 < argc && strcmp(argv[i], "--build-file") == 0) { @@ -363,7 +367,6 @@ int main(int argc, char **argv) { CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf); codegen_set_out_name(g, buf_create_from_str("build")); - codegen_set_verbose(g, verbose); Buf build_file_abs = BUF_INIT; os_path_resolve(buf_create_from_str("."), buf_create_from_str(build_file), &build_file_abs); @@ -398,14 +401,30 @@ int main(int argc, char **argv) { "\n" "General Options:\n" " --help Print this help and exit\n" - " --build-file [file] Override path to build.zig\n" - " --cache-dir [path] Override path to cache directory\n" + " --build-file $file Override path to build.zig\n" + " --cache-dir $path Override path to cache directory\n" " --verbose Print commands before executing them\n" - " --debug-build-verbose Print verbose debugging information for the build system itself\n" - " --prefix [prefix] Override default install prefix\n" + " --verbose-tokenize Enable compiler debug output for tokenization\n" + " --verbose-ast Enable compiler debug output for parsing into an AST\n" + " --verbose-link Enable compiler debug output for linking\n" + " --verbose-ir Enable compiler debug output for Zig IR\n" + " --verbose-llvm-ir Enable compiler debug output for LLVM IR\n" + " --verbose-cimport Enable compiler debug output for C imports\n" + " --prefix $path Override default install prefix\n" "\n" - "More options become available when the build file is found.\n" + "Project-specific options become available when the build file is found.\n" "Run this command with no options to generate a build.zig template.\n" + "\n" + "Advanced Options:\n" + " --build-file $file Override path to build.zig\n" + " --cache-dir $path Override path to cache directory\n" + " --verbose-tokenize Enable compiler debug output for tokenization\n" + " --verbose-ast Enable compiler debug output for parsing into an AST\n" + " --verbose-link Enable compiler debug output for linking\n" + " --verbose-ir Enable compiler debug output for Zig IR\n" + " --verbose-llvm-ir Enable compiler debug output for LLVM IR\n" + " --verbose-cimport Enable compiler debug output for C imports\n" + "\n" , zig_exe_path); return 0; } @@ -452,12 +471,18 @@ int main(int argc, char **argv) { strip = true; } else if (strcmp(arg, "--static") == 0) { is_static = true; - } else if (strcmp(arg, "--verbose") == 0) { - verbose = true; + } else if (strcmp(arg, "--verbose-tokenize") == 0) { + verbose_tokenize = true; + } else if (strcmp(arg, "--verbose-ast") == 0) { + verbose_ast = true; } else if (strcmp(arg, "--verbose-link") == 0) { verbose_link = true; } else if (strcmp(arg, "--verbose-ir") == 0) { verbose_ir = true; + } else if (strcmp(arg, "--verbose-llvm-ir") == 0) { + verbose_llvm_ir = true; + } else if (strcmp(arg, "--verbose-cimport") == 0) { + verbose_cimport = true; } else if (strcmp(arg, "-mwindows") == 0) { mwindows = true; } else if (strcmp(arg, "-mconsole") == 0) { @@ -742,9 +767,12 @@ int main(int argc, char **argv) { codegen_set_kernel32_lib_dir(g, buf_create_from_str(kernel32_lib_dir)); if (dynamic_linker) codegen_set_dynamic_linker(g, buf_create_from_str(dynamic_linker)); - codegen_set_verbose(g, verbose); + g->verbose_tokenize = verbose_tokenize; + g->verbose_ast = verbose_ast; g->verbose_link = verbose_link; g->verbose_ir = verbose_ir; + g->verbose_llvm_ir = verbose_llvm_ir; + g->verbose_cimport = verbose_cimport; codegen_set_errmsg_color(g, color); for (size_t i = 0; i < lib_dirs.length; i += 1) { diff --git a/src/parsec.cpp b/src/parsec.cpp index d200c0531d..586e95bc75 100644 --- a/src/parsec.cpp +++ b/src/parsec.cpp @@ -3167,7 +3167,7 @@ int parse_h_file(ImportTableEntry *import, ZigList *errors, const ch { Context context = {0}; Context *c = &context; - c->warnings_on = codegen->verbose; + c->warnings_on = codegen->verbose_cimport; c->import = import; c->errors = errors; if (buf_ends_with_str(buf_create_from_str(target_file), ".h")) { diff --git a/std/build.zig b/std/build.zig index 84eba6d33b..7cf2ac5987 100644 --- a/std/build.zig +++ b/std/build.zig @@ -33,6 +33,12 @@ pub const Builder = struct { available_options_map: AvailableOptionsMap, available_options_list: ArrayList(AvailableOption), verbose: bool, + verbose_tokenize: bool, + verbose_ast: bool, + verbose_link: bool, + verbose_ir: bool, + verbose_llvm_ir: bool, + verbose_cimport: bool, invalid_user_input: bool, zig_exe: []const u8, default_step: &Step, @@ -88,6 +94,12 @@ pub const Builder = struct { .build_root = build_root, .cache_root = %%os.path.relative(allocator, build_root, cache_root), .verbose = false, + .verbose_tokenize = false, + .verbose_ast = false, + .verbose_link = false, + .verbose_ir = false, + .verbose_llvm_ir = false, + .verbose_cimport = false, .invalid_user_input = false, .allocator = allocator, .lib_paths = ArrayList([]const u8).init(allocator), @@ -536,15 +548,19 @@ pub const Builder = struct { return self.spawnChildEnvMap(null, &self.env_map, argv); } + fn printCmd(cwd: ?[]const u8, argv: []const []const u8) { + if (cwd) |yes_cwd| %%io.stderr.print("cd {} && ", yes_cwd); + for (argv) |arg| { + %%io.stderr.print("{} ", arg); + } + %%io.stderr.printf("\n"); + } + fn spawnChildEnvMap(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap, argv: []const []const u8) -> %void { if (self.verbose) { - if (cwd) |yes_cwd| %%io.stderr.print("cd {}; ", yes_cwd); - for (argv) |arg| { - %%io.stderr.print("{} ", arg); - } - %%io.stderr.printf("\n"); + printCmd(cwd, argv); } const child = %%os.ChildProcess.init(argv, self.allocator); @@ -561,12 +577,15 @@ pub const Builder = struct { switch (term) { Term.Exited => |code| { if (code != 0) { - %%io.stderr.printf("Process {} exited with error code {}\n", argv[0], code); + %%io.stderr.printf("The following command exited with error code {}:\n", code); + printCmd(cwd, argv); return error.UncleanExit; } }, else => { - %%io.stderr.printf("Process {} terminated unexpectedly\n", argv[0]); + %%io.stderr.printf("The following command terminated unexpectedly:\n"); + printCmd(cwd, argv); + return error.UncleanExit; }, }; @@ -1117,6 +1136,12 @@ pub const LibExeObjStep = struct { if (self.verbose) { %%zig_args.append("--verbose"); } + if (builder.verbose_tokenize) %%zig_args.append("--verbose-tokenize"); + if (builder.verbose_ast) %%zig_args.append("--verbose-ast"); + if (builder.verbose_cimport) %%zig_args.append("--verbose-cimport"); + if (builder.verbose_ir) %%zig_args.append("--verbose-ir"); + if (builder.verbose_llvm_ir) %%zig_args.append("--verbose-llvm-ir"); + if (builder.verbose_link) %%zig_args.append("--verbose-link"); if (self.strip) { %%zig_args.append("--strip"); diff --git a/std/special/build_runner.zig b/std/special/build_runner.zig index b1fbfc6c2b..089137c923 100644 --- a/std/special/build_runner.zig +++ b/std/special/build_runner.zig @@ -69,6 +69,18 @@ pub fn main() -> %void { %%io.stderr.printf("Expected argument after --prefix\n\n"); return usage(&builder, false, &io.stderr); }); + } else if (mem.eql(u8, arg, "--verbose-tokenize")) { + builder.verbose_tokenize = true; + } else if (mem.eql(u8, arg, "--verbose-ast")) { + builder.verbose_ast = true; + } else if (mem.eql(u8, arg, "--verbose-link")) { + builder.verbose_link = true; + } else if (mem.eql(u8, arg, "--verbose-ir")) { + builder.verbose_ir = true; + } else if (mem.eql(u8, arg, "--verbose-llvm-ir")) { + builder.verbose_llvm_ir = true; + } else if (mem.eql(u8, arg, "--verbose-cimport")) { + builder.verbose_cimport = true; } else { %%io.stderr.printf("Unrecognized argument: {}\n\n", arg); return usage(&builder, false, &io.stderr); @@ -116,27 +128,40 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) \\ \\General Options: \\ --help Print this help and exit - \\ --build-file [file] Override path to build.zig - \\ --cache-dir [path] Override path to cache directory \\ --verbose Print commands before executing them - \\ --debug-build-verbose Print verbose debugging information for the build system itself - \\ --prefix [prefix] Override default install prefix + \\ --prefix $path Override default install prefix \\ \\Project-Specific Options: \\ ); if (builder.available_options_list.len == 0) { - %%out_stream.printf(" (none)\n"); + %%out_stream.print(" (none)\n"); } else { for (builder.available_options_list.toSliceConst()) |option| { const name = %%fmt.allocPrint(allocator, - " -D{}=({})", option.name, Builder.typeIdName(option.type_id)); + " -D{}=${}", option.name, Builder.typeIdName(option.type_id)); defer allocator.free(name); - %%out_stream.printf("{s24} {}\n", name, option.description); + %%out_stream.print("{s24} {}\n", name, option.description); } } + %%out_stream.write( + \\ + \\Advanced Options: + \\ --build-file $file Override path to build.zig + \\ --cache-dir $path Override path to zig cache directory + \\ --verbose-tokenize Enable compiler debug output for tokenization + \\ --verbose-ast Enable compiler debug output for parsing into an AST + \\ --verbose-link Enable compiler debug output for linking + \\ --verbose-ir Enable compiler debug output for Zig IR + \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR + \\ --verbose-cimport Enable compiler debug output for C imports + \\ + ); + + %%out_stream.flush(); + if (out_stream == &io.stderr) return error.InvalidArgs; } -- cgit v1.2.3