5985 Commits

Author SHA1 Message Date
Andrew Kelley
5e63baae8d CLI: remove --verbose-ast and --verbose-tokenize
closes #9034

These options were listed under the
"Debug Options (Zig Compiler Development)" heading. Anything in this
section should be considered unstable and can be modified at any time
at any developer's discretion.
2021-06-09 14:38:27 -07:00
Andrew Kelley
d128ec39df native libc detection: respect spaces in CC env var
Zig has detection for when it is accidentally being called recursively
when trying to find the native libc installation. However it was not
working, resulting in a cryptic failure, because zig tried to execute
a command which had spaces in it rather than tokenizing it.

This improves the user experience of `zig cc` for systems that Zig
does not support cross-compiling for.

Closes #8960
2021-06-09 17:26:58 -04:00
joachimschmidt557
96c60bcca5 stage2 codegen: Remove hacks for discontinued SPU II backend 2021-06-09 21:37:23 +03:00
Jakub Konka
9f8de83d93 cc,wasi: use wasi_libc.CRTFile directly instead of WasiExecModel 2021-06-09 11:11:55 +02:00
Takeshi Yoneda
bf568ec62a cc,wasi: support WASI reactors via -mexec-model flag.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-06-09 17:07:06 +09:00
Jakub Konka
2ee1f7898b cc,wasi: store CRTFile enum in wasi_emulated_libs
* then, in `link/Wasm.zig` map `CRTFile` to full emulated libs name
* move logic for removing any mention of WASI snapshot
  `wasi_snapshot_preview1` from `Compilation.zig` into `link/Wasm.zig`
2021-06-09 01:25:38 +02:00
Jakub Konka
dd84ccda5d wasi: clean up linking logic
Do not try to link WASI libc or emulated subcomponents when not
targeting WASI; e.g., when targeting `wasm32-freestanding`.
2021-06-09 01:25:38 +02:00
Jakub Konka
95745f77da wasi: skip adding wasi_snapshot_preview1 as lib dep in stage1 2021-06-09 01:25:38 +02:00
Jakub Konka
4e4722a65e cc,wasi: build referenced-only emulated components
Move parsing of system libs into `main.zig` next to where we decide
if we should link libC, and, if targeting WASI, if the specified
libname equals one of the emulated components, save it on the side
and remove it from the system libs. Then, build *only* those parts
of WASI libc that were preserved in the previous step.

This also fixes building of different crt1 bits needed to support
reactors and commands.
2021-06-09 01:25:38 +02:00
Jakub Konka
93a4403271 cc,wasi: package emulations as static archives
This replicates the expected behavior when using `clang` with
upstream `wasi-libc` sysroot: linking emulated subcomponents
such as process clocks or signals requires an explicit link flag
in the compiler invocation, for example:

```
zig cc -target wasm32-wasi -lwasi-emulated-process-clocks main.c -o main.wasm
```
2021-06-09 01:25:38 +02:00
Jakub Konka
6f6182a5f3 zig,cc,wasi: include emulated libs in WASI libc
This commit includes emulated libc sublibs that were not included
in the compilation and caching of WASI libc that ships with Zig.
The libs include (emulated): process clocks, getpid, mman, and signal.

With this change, it is now possible to successfully cross-compile
`wasm3` engine to WASI with `zig cc`.

For the future though, it might be worth considering splitting WASI
libc into libc-proper and modularised emulated libs as it is done
in upstream, and then have them included only if the user specifically
requests emulation/parts of it.
2021-06-09 01:25:38 +02:00
jacob gw
b57ac48773 stage2: compile error for ambiguous decl refrences
std: fix compile errors from this change. This is a stage1 bug.
2021-06-08 18:13:12 -04:00
Andrew Kelley
ccfa168284
Merge pull request #9030 from Vexu/stage2
Stage2: implement comptime variables
2021-06-08 14:16:57 -04:00
Matthew Borkowski
9ac6d28614 stage1: make @truncate to an integer type of different sign an error at comptime too 2021-06-08 20:58:30 +03:00
Matthew Borkowski
fc956fc110 stage1: fix render_const_value for printing const optional pointers 2021-06-08 20:41:09 +03:00
Veikka Tuominen
d41a5105cd stage2: fix repeat_inline skipping first instruction in block
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2021-06-08 10:15:34 +03:00
Andrew Kelley
38e233845e link: windows: look for more DLL import lib path names
When linking with -lfoo syntax, this indicates to Zig that the
dependency should either be provided by Zig, or it should be dynamically
provided by the system.

For windows-gnu targets, the search path was "foo.lib". Now it
additionally looks for "libfoo.dll.a".

Closes #7799
2021-06-08 01:31:10 -04:00
Veikka Tuominen
7efd7bc3b8 stage2: implement comptime variables 2021-06-07 22:15:56 +03:00
Evan Haas
fa6546ba74 translate-c: properly handle enums used as boolean expressions 2021-06-07 15:51:42 +03:00
LemonBoy
fc8791c133 stage1: Allow array-like initialization for tuple types
This small change makes working with tuple types much easier, allowing
the use of anonymous (eg. obtained with meta.ArgsTuple) tuples in more
places without the need for specifying each (quoted!) field name in the
initializer.
2021-06-06 21:21:42 -04:00
LemonBoy
849b4e3495 stage1: Apply the same set of fn attributes everywhere
Make sure to propagate the target-specific attributes to internal
functions too.

Closes #8965
2021-06-06 18:24:25 -04:00
Evan Haas
6d52daba37 translate-c: Small cleanup, remove unneeded std.math.max call 2021-06-06 11:07:00 +03:00
Min-Yih Hsu
83e0a49ba4
llvm: Add support for collecting time trace (#8546)
LLVM time profiler can collect time traces and present them in a
hierarchical view. Which breakdowns the time spent in each Pass or even
IR unit. The result is also exported into a format that can be easily
visualized by the Chrome browser.

Currently this features is controlled by the following environment
variables:
 - `ZIG_LLVM_TIME_TRACE_FILE` toggles this feature and specifies the
   output time trace file.
 - `ZIG_LLVM_TIME_TRACE_GRANULARITY` controls the time granularity in
   ms (default to 500).
2021-06-04 09:32:37 +02:00
Martin Wickham
fc9430f567 Breaking hash map changes for 0.8.0
- hash/eql functions moved into a Context object
- *Context functions pass an explicit context
- *Adapted functions pass specialized keys and contexts
- new getPtr() function returns a pointer to value
- remove functions renamed to fetchRemove
- new remove functions return bool
- removeAssertDiscard deleted, use assert(remove(...)) instead
- Keys and values are stored in separate arrays
- Entry is now {*K, *V}, the new KV is {K, V}
- BufSet/BufMap functions renamed to match other set/map types
- fixed iterating-while-modifying bug in src/link/C.zig
2021-06-03 17:02:16 -05:00
Jakub Konka
d1f60a63bd zld: fix the linker for 32bit comp targets 2021-06-03 00:23:04 +02:00
Evan Haas
a9dd8d7543 translate-c: Fix performance hazard in transPreprocessorEntities
Fixes O(N^2) behavior of `transPreprocessorEntities` due to repeated calls to
`mem.len`

Closes #8959
2021-06-02 09:12:45 +03:00
Veikka Tuominen
c6a0a4e728 translate-c: support designated initializers in macros 2021-06-01 23:40:43 -04:00
Andrew Kelley
f693247295
Merge pull request #8917 from ifreund/fix-float-tokenize2
stage1, stage2: disallow 1.e9 and 0x1.p9 as float literals
2021-06-01 14:00:54 -04:00
Isaac Freund
abd1c75c4a
stage1: disallow 1.e9 and 0x1.p9 as float literals 2021-05-31 19:51:11 +00:00
Isaac Freund
608bc1cbd5
stage2: disallow 1.e9 and 0x1.p9 as float literals
Instead require `1e9` and `0x1p9`, disallowing the trailing dot.

This change to the grammar is consistent with forbidding `1.` and `0x1.`
as float literals and ensures there is only one way to do things here.
2021-05-31 19:51:11 +00:00
protty
eb6975f088
std.sync.atomic: extended atomic helper functions (#8866)
- deprecates `std.Thread.spinLoopHint` and moves it to `std.atomic.spinLoopHint`
- added an Atomic(T) generic wrapper type which replaces atomic.Bool and atomic.Int
- in Atomic(T), selectively expose member functions depending on T and include bitwise atomic methods when T is an Integer
- added fence() and compilerFence() to std.atomic
2021-05-31 11:11:30 -05:00
Andrew Kelley
e078b4f20e zig ar: workaround for LLVM bug
In this file is copy+pasted WindowsSupport.h from LLVM 12.0.1-rc1.
This is so that we can patch it. The upstream sources are incorrectly
including "llvm/Config/config.h" which is a private header and thus not
available in the include files distributed with LLVM.
The patch here changes it to include "llvm/Config/config.h" instead.
Patch submitted upstream: https://reviews.llvm.org/D103370
2021-05-29 13:54:31 -07:00
Andrew Kelley
0afb5b2ec6 stage2: add zig ar subcommand
The same entrypoint supports the following commands:

 * ar
 * ranlib
 * dlltool
 * lib

For now, our strategy is to bundle the (renamed) `main()` function of
llvm-ar, same as our strategy for `zig clang`. However, as Zig matures,
a goal will be to replace the dependency on LLVM  with our own
implementation of this tool, so that it is available in builds of zig
that do not have LLVM extensions enabled.

This commit also categorizes the subcommands into categories in the
--help menu.
2021-05-28 20:54:11 -07:00
Andrew Kelley
e248de93a0 add llvm-ar.cpp from llvm 12.0.1-rc1 2021-05-28 20:12:28 -07:00
Andrew Kelley
c12704a339
Merge pull request #8918 from ziglang/stage1-tokenizer
stage1: rework tokenizer to match stage2
2021-05-28 21:54:01 -04:00
Andrew Kelley
3f5ca3920a AstGen: properly restore previous state after temporary changes
Before this, if a compile error occurred, it would cause the previous
value for e.g. the function scope to not get reset. If the AstGen
process continued, it would result in a violation of the data
guarantees that it relies on.

This commit takes advantage of defer to ensure the previous value is
always reset, even in the case of an error.

Closes #8920
2021-05-28 17:29:56 -07:00
LemonBoy
d3fb9f9532 stage1: Fix for atomicrmw xchg on fp types
Bitcast the pointer and operands to integer types having the same size,
working around LLVM inability to lower a LL/SC operation when the
operands have floating-point types (and are reasonably sized).

Closes #4457
2021-05-28 19:18:42 -04:00
Andrew Kelley
d888fa12a8 stage1 parser: fix the TODOs 2021-05-28 16:11:27 -07:00
Andrew Kelley
f5d4fe3e17 stage1: memoize strings in the AST
Currently, stage1 runs astgen for every comptime function call,
resulting in identifier strings being allocated multiple times,
wasting memory. As a workaround until the code is adjusted to
make astgen run only once per source node, we memoize the
result into the AST.

 * Rename `ir_gen_*` to `astgen_*`
   - Oops, meant to do this in a separate commit. My bad.
 * tokenizer: avoid using designated initializer syntax.
   MSVC does not support it.
2021-05-28 15:22:03 -07:00
Andrew Kelley
52b3daa90e stage1: get test-compile-errors passing again 2021-05-28 14:19:08 -07:00
Andrew Kelley
9de2c1b76e stage1: tokenizer: backport recent stage2 changes
This backports ec10595b65490126e1b7d231f655be6d7d198acf stage2 tokenizer
logic to stage1.
2021-05-28 13:26:16 -07:00
Andrew Kelley
01e0a4b2f0 stage1: rename IrBasicBlockSrc to Stage1ZirBasicBlock 2021-05-28 12:58:40 -07:00
Andrew Kelley
548ef78070 stage1: remove source_node field from Stage1Zir
This field is unneeded because we always have the source node available
in the context that we have a Stage1Zir object.
2021-05-28 12:58:40 -07:00
Andrew Kelley
554dd52c36 stage1: remove c_import_buf from Stage1Zir
All we need is a boolean in Stage1AstGen. This is part of an effort to
make Stage1Zir immutable.
2021-05-28 12:58:40 -07:00
Andrew Kelley
4ea421f8cb stage1: move the ZigFn from Stage1Zir to Stage1AstGen
Part of an effort to make Stage1Zir immutable.
2021-05-28 12:58:40 -07:00
Andrew Kelley
42f4ee0aeb stage1: rename IrBuilderSrc to Stage1AstGen 2021-05-28 12:58:40 -07:00
Andrew Kelley
2440c08ab0 stage1: move next_debug_id from Stage1Zir to IrBuilderSrc
Part of an effort to make Stage1Zir immutable.
2021-05-28 12:58:40 -07:00
Andrew Kelley
b11ac9c5bf stage1: move some mutable state from Stage1Zir to IrAnalyze
This is progress towards making Stage1Zir immutable, so that we can
avoid generating it for every comptime function call.

Also rename IrExecutableGen to Stage1Air.
2021-05-28 12:58:40 -07:00
Andrew Kelley
e072ace436 stage1: rename IrExecutableSrc to Stage1Zir
and make IrBuilderSrc private to astgen.cpp
2021-05-28 12:58:40 -07:00
Andrew Kelley
eb37722d79 lol that's never going to happen in stage1 2021-05-28 12:58:40 -07:00