aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
AgeCommit message (Collapse)Author
2020-07-24Revert "Support taking extern pointers at comptime"Andrew Kelley
This reverts commit d3ebd428650748e60db70dd2171cc044855814b1. This caused a build failure on multiple targets.
2020-07-24Support taking extern pointers at comptimeyvt
This commit makes it possible to obtain pointers to `extern` variables at comptime. - `ir_get_var_ptr` employs several checks to determine if the given variable is eligible for obtaining its pointer at comptime. This commit alters these checks to consider `extern` variables, which have runtime values, as eligible. - After this change, it's now possible for `render_const_val` to be called for `extern` variables. This commit modifies `render_const_val` to suppress the value generation for `extern` variables. - `do_code_gen` now creates `ZigValue::llvm_global` of `extern` variables before iterating through module-level variables so that other module-level variables can refer to them. This solution is incomplete since there are several cases still failing: - `global_var.array[n..m]` - `&global_var.array[i]` - `&global_var.inner_struct.value` - `&global_array[i]` Closes #5349
2020-07-21Use function attribute "frame-pointer"Hiroki Noda
2020-07-11add 'anytype' to stage1 and langrefVexu
2020-07-05stage1: add missing runtime safety for @intCast unsigned -> signed of same ↵xackus
bit count
2020-06-22Merge remote-tracking branch 'origin/master' into zig-ast-to-zirAndrew Kelley
2020-06-21Make unary minus for unsigned types a compile error (#5654)Robin Voetter
* Make unary minus for unsigned types a compile error * Add unreachable when generating unsigned negate
2020-06-18zig cc: add missing cxxabi include pathAndrew Kelley
2020-06-18stage1: stop emitting memset to undefined when safety is offAndrew Kelley
2020-06-18self-hosted: implement Decl lookupAndrew Kelley
* Take advantage of coercing anonymous struct literals to struct types. * Reworks Module to favor Zig source as the primary use case. Breaks ZIR compilation, which will have to be restored in a future commit. * Decl uses src_index rather then src, pointing to an AST Decl node index, or ZIR Module Decl index, rather than a byte offset. * ZIR instructions have an `analyzed_inst` field instead of Module having a hash table. * Module.Fn loses the `fn_type` field since it is redundant with its `owner_decl` `TypedValue` type. * Implement Type and Value copying. A ZIR Const instruction's TypedValue is copied to the Decl arena during analysis, which allows freeing the ZIR text instructions post-analysis. * Don't flush the ELF file if there are compilation errors. * Function return types allow arbitrarily complex expressions. * AST->ZIR for function calls and return statements.
2020-06-18implement `@src`Vexu
2020-06-09Expose full llvm intrinsicJakub Konka
2020-06-09Add builtin for llvm.wasm.memory.grow.i32 intrinsicJakub Konka
This will allow the developer to request additional memory pages from the runtime to be allocated for the Wasm app. Typical usage: ```zig var wasm_pages = @wasmMemorySize(); @wasmMemoryGrow(1); @import("std").debug.assert((wasm_pages + 1) == @wasmMemorySize()); ```
2020-06-09Add builtin for llvm.wasm.memory.size.i32 instrinsicJakub Konka
This will allow the developer to poll the runtime for currently allocated memory in the number of Wasm pages. Typical usage: ```zig var wasm_pages = @wasmMemorySize(); @import("std").debug.assert(wasm_pages > 0); ```
2020-05-28C ABI: Add C support for passing structs of floats to an extern functionTimon Kruiper
Currently this does not handle returning these structs yet. Related: #1481
2020-05-26Add caller location tracking for asserts (ir_assert, src_assert, ↵foobles
ir_assert_gen) (#5393)
2020-05-16Merge remote-tracking branch 'origin/master' into ↵Andrew Kelley
self-hosted-incremental-compilation
2020-05-12clear progress indicator before printing errorsAndrew Kelley
2020-05-05Rename noasync to nosuspend in C++ compilerTadeo Kondrak
2020-04-27Add missing state to C object cacheGeorge Roman
2020-04-26add CLI option -Bsymbolic for binding global references locallyAndrew Kelley
2020-04-25Pass each target feature flag separatelyGeorge Roman
2020-04-23stage1: fix crash on accessing an array of size zero with runtime indexxackus
2020-04-23stage1: Fix bitcast of immediate to ptr type (#5131)LemonBoy
Consider a (legal according to the `@bitCast` rules) conversion from u16 to [2]u8: since the former is a scalar and the latter is a pointer (arrays are represented at pointers in the codegen phase) we have to allocate a temporary slot on the stack and then bitcast the resulting pointer to the desired destination type. Beware that this means the lifetime of the resulting value is the same of the function it's contained in and for all intents and purposes should be regarded as a local (eg. it should not escape). Closes #4395 Closes #5121
2020-04-22stage1: Another hack for the C ABI compatibilityLemonBoy
Applying the wrong ABI is slightly better than using the Zig ABI, the whole thing is so wrong it should be burned to the ground.
2020-04-20stage1: Fix wrong union accessLemonBoy
Thanks to @frett27 on irc for reporting the compiler would segfault when run on ARM.
2020-04-17stage1: Fix several bugs in constant generationLemonBoy
The codegen would sometimes change the LLVM type for some constants to an unnamed structure in order to accomodate extra padding. This is fine as long as the alignment of each field is still respected and it was not the case for structure types, leading to ill-formed constants being generated. Optional types suffer from this to a lower extent as their layout is quite lucky, the only missing piece was the tail padding. Closes #4530 Closes #4594 Closes #4295 Closes my will to live
2020-04-13stage1: More fixes for BE targetsLemonBoy
* Fix packed struct alignment * Adjust some tests
2020-04-12only use `-nostdinc++` on c++ filesMichael Dusan
This is a follow-up to d27ef1aaef8ac12801ba4e6c2ed748c7151096a7 and avoids compiler warnings: warning: argument unused during compilation: '-nostdinc++'
2020-04-12Zig treats -lstdc++ identically to -lc++Andrew Kelley
Thanks to Michael Dusan for figuring out what was happening here. closes #5012
2020-04-07Merge pull request #4857 from LemonBoy/fix-4777Andrew Kelley
Rewrite the bound checks in slice operator
2020-04-07stage1: Respect the specified name for extern varLemonBoy
Extend the logic used for function definitions to variables. Closes #4947
2020-04-06zig cc: recognize a few more linker optionsAndrew Kelley
* `--major-image-version` * `--minor-image-version` * `--stack`
2020-04-05ir: Fix error checking for vector opsLemonBoy
The extra logic that's needed was lost during a refactoring, now it should be fine.
2020-04-05ir: Remove unused and commented out codeLemonBoy
2020-04-05ir: Support shift left/right on vectorsLemonBoy
2020-04-05ir: Support div/mod/rem on vector typesLemonBoy
Closes #4050
2020-04-05Do not parse native_libc.txt anymore when linking on native target, always ↵Michaël Larouche
run detection of libc. Fixes #4772
2020-04-03change the default ABI of riscv64-linux-muslAndrew Kelley
Before, this would cause a link failure when mixing Zig and C code for RISC-V targets. Now, the ABIs match and Zig and C code can be mixed successfully. I will file a follow-up issue for the ability to deal more explicitly with ABIs. closes #4863
2020-04-03ir: Rewrite the bound checks in slice operatorLemonBoy
Closes #4777
2020-04-02zig cc: support more linker argsAndrew Kelley
2020-04-02zig cc: respect -MF -MV -MD optionsAndrew Kelley
Zig disables its caching and forwards these args when any are provided. see #4784
2020-04-01zig cc properly handles -S flag and .ll, .bc extensionsAndrew Kelley
2020-04-01stage1: make C++ switch fallthrough an errorMichael Dusan
Make fallthrough an error when compiler supports it. This requires a new macro that is defined with such compilers to be used as a statement, at all fallthrough sites: switch (...) { case 0: ... ZIG_FALLTHROUGH; case 1: ... break; default: ... break; } If we ever move to C++17 as minimal requirement, then the macro can be replaced with `[[fallthrough]];` at statement sites.
2020-04-01Merge pull request #4896 from FireFox317/fix-arm32-stuffAndrew Kelley
fix some nullptr dereferences on arm-linux-musleabhif
2020-04-01Make sure that ZigTypeVector and ZigTypeArray have the same memory layoutTimon Kruiper
Throughout the stage1 code it is assumed that these have the same layout, but that was not the case. This caused an issue on 32-bit hardware.
2020-04-01fixups and revert a few thingsAndrew Kelley
2020-04-01Use length field as passed in stage2 libc_installation instead of relying on ↵daurnimator
zero termination
2020-03-30revert detection of rtti and exceptionsAndrew Kelley
This caused link errors in c++ code because it was not correct to pass these flags to child codegens. And that was the only reason to detect these flags. Otherwise we can safely rely on non-explicitly-detected flag forwarding.
2020-03-27zig c++: get it working with musl and mingw-w64Andrew Kelley