diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-03-31 05:48:15 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-03-31 05:55:41 -0400 |
| commit | 3ca027ca8219dbdbb6467645944c4daada037f51 (patch) | |
| tree | 786a6c4ecac9f11d3a60f3c14c1b4276a3adc8d6 /std/special | |
| parent | 536c35136ab98f2f56d07937727b3c99c0e35c5c (diff) | |
| download | zig-3ca027ca8219dbdbb6467645944c4daada037f51.tar.gz zig-3ca027ca8219dbdbb6467645944c4daada037f51.zip | |
first pass at zig build system
* `zig build --export [obj|lib|exe]` changed to `zig build_obj`,
`zig build_lib` and `zig build_exe` respectively.
* `--name` parameter is optional when it can be inferred from the
root source filename. closes #207
* `zig build` now looks for `build.zig` which interacts with
`std.build.Builder` to describe the targets, and then the zig
build system prints TODO: build these targets. See #204
* add `@bitcast` which is mainly used for pointer reinterpret
casting and make explicit casting not do pointer reinterpretation.
Closes #290
* fix debug info for byval parameters
* sort command line help options
* `std.debug.panic` supports format string printing
* add `std.mem.IncrementingAllocator`
* fix const ptr to a variable with data changing at runtime.
closes #289
Diffstat (limited to 'std/special')
| -rw-r--r-- | std/special/build_runner.zig | 18 | ||||
| -rw-r--r-- | std/special/compiler_rt.zig | 24 | ||||
| -rw-r--r-- | std/special/zigrt.zig | 4 |
3 files changed, 32 insertions, 14 deletions
diff --git a/std/special/build_runner.zig b/std/special/build_runner.zig new file mode 100644 index 0000000000..73a608487a --- /dev/null +++ b/std/special/build_runner.zig @@ -0,0 +1,18 @@ +const root = @import("@build"); +const std = @import("std"); +const io = std.io; +const Builder = std.build.Builder; +const mem = std.mem; + +pub fn main(args: [][]u8) -> %void { + const zig_exe = args[1]; + const leftover_args = args[2...]; + + // TODO use a more general purpose allocator here + var inc_allocator = %%mem.IncrementingAllocator.init(10 * 1024 * 1024); + defer inc_allocator.deinit(); + + var builder = Builder.init(zig_exe, &inc_allocator.allocator); + root.build(&builder); + %return builder.make(leftover_args); +} diff --git a/std/special/compiler_rt.zig b/std/special/compiler_rt.zig index 8f61876305..f5c83becc7 100644 --- a/std/special/compiler_rt.zig +++ b/std/special/compiler_rt.zig @@ -15,7 +15,7 @@ export fn __udivdi3(a: du_int, b: du_int) -> du_int { fn du_int_to_udwords(x: du_int) -> udwords { @setDebugSafety(this, false); - return *(&udwords)(&x); + return *@bitcast(&udwords, &x); } export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { @@ -66,7 +66,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { if (var rem ?= maybe_rem) { r[high] = n[high] % d[high]; r[low] = 0; - *rem = *(&du_int)(&r[0]); + *rem = *@bitcast(&du_int, &r[0]); } return n[high] / d[high]; } @@ -78,7 +78,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { if (var rem ?= maybe_rem) { r[low] = n[low]; r[high] = n[high] & (d[high] - 1); - *rem = *(&du_int)(&r[0]); + *rem = *@bitcast(&du_int, &r[0]); } return n[high] >> @ctz(d[high]); } @@ -89,7 +89,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { // 0 <= sr <= n_uword_bits - 2 or sr large if (sr > n_uword_bits - 2) { if (var rem ?= maybe_rem) { - *rem = *(&du_int)(&n[0]); + *rem = *@bitcast(&du_int, &n[0]); } return 0; } @@ -113,12 +113,12 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { *rem = n[low] & (d[low] - 1); } if (d[low] == 1) { - return *(&du_int)(&n[0]); + return *@bitcast(&du_int, &n[0]); } sr = @ctz(d[low]); q[high] = n[high] >> sr; q[low] = (n[high] << (n_uword_bits - sr)) | (n[low] >> sr); - return *(&du_int)(&q[0]); + return *@bitcast(&du_int, &q[0]); } // K X // --- @@ -154,7 +154,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { // 0 <= sr <= n_uword_bits - 1 or sr large if (sr > n_uword_bits - 1) { if (var rem ?= maybe_rem) { - *rem = *(&du_int)(&n[0]); + *rem = *@bitcast(&du_int, &n[0]); } return 0; } @@ -191,17 +191,17 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { // r.all -= d.all; // carry = 1; // } - const s: di_int = (di_int)(*(&du_int)(&d[0]) - *(&du_int)(&r[0]) - 1) >> (n_udword_bits - 1); + const s: di_int = (di_int)(*@bitcast(&du_int, &d[0]) - *@bitcast(&du_int, &r[0]) - 1) >> (n_udword_bits - 1); carry = su_int(s & 1); - *(&du_int)(&r[0]) -= *(&du_int)(&d[0]) & u64(s); + *@bitcast(&du_int, &r[0]) -= *@bitcast(&du_int, &d[0]) & u64(s); sr -= 1; } - *(&du_int)(&q[0]) = (*(&du_int)(&q[0]) << 1) | u64(carry); + *@bitcast(&du_int, &q[0]) = (*@bitcast(&du_int, &q[0]) << 1) | u64(carry); if (var rem ?= maybe_rem) { - *rem = *(&du_int)(&r[0]); + *rem = *@bitcast(&du_int, &r[0]); } - return *(&du_int)(&q[0]); + return *@bitcast(&du_int, &q[0]); } export fn __umoddi3(a: du_int, b: du_int) -> du_int { diff --git a/std/special/zigrt.zig b/std/special/zigrt.zig index 148516eb40..6f7911917d 100644 --- a/std/special/zigrt.zig +++ b/std/special/zigrt.zig @@ -1,5 +1,5 @@ // This file contains functions that zig depends on to coordinate between -// multiple .o files. The symbols are defined LinkOnce so that multiple +// multiple .o files. The symbols are defined Weak so that multiple // instances of zig_rt.zig do not conflict with each other. export coldcc fn __zig_panic(message_ptr: &const u8, message_len: usize) -> noreturn { @@ -11,6 +11,6 @@ export coldcc fn __zig_panic(message_ptr: &const u8, message_len: usize) -> nore } else if (@compileVar("os") == Os.freestanding) { while (true) {} } else { - @import("std").debug.panic(message_ptr[0...message_len]); + @import("std").debug.panic("{}\n", message_ptr[0...message_len]); } } |
