aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
AgeCommit message (Collapse)Author
2019-02-26fix handling when there are multiple externs andAndrew Kelley
an export in the same object closes #529
2019-02-26introduce sys_include_dir for when sys/* files are not with stdlib.hAndrew Kelley
2019-02-26fix regressions on WindowsAndrew Kelley
2019-02-26breaking changes to the way targets work in zigAndrew Kelley
* CLI: `-target [name]` instead of `--target-*` args. This matches clang's API. * `builtin.Environ` renamed to `builtin.Abi` - likewise `builtin.environ` renamed to `builtin.abi` * stop hiding the concept of sub-arch. closes #1526 * `zig targets` only shows available targets. closes #438 * include all targets in readme, even those that don't print with `zig targets` but note they are Tier 4 * refactor target.cpp and make the naming conventions more consistent * introduce the concept of a "default C ABI" for a given OS/Arch combo. As a rule of thumb, if the system compiler is clang or gcc then the default C ABI is the gnu ABI.
2019-02-26use -nostdinc and sometimes -nolibc when compiling C codeAndrew Kelley
2019-02-26use -nostdinc++ when compiling C codeAndrew Kelley
2019-02-26use -nobuiltininc when compiling c codeAndrew Kelley
2019-02-25fix not finding libgcc_s when looking for native libcAndrew Kelley
closes #2011
2019-02-25`@cImport` works with `--cache on`Andrew Kelley
We pass -MD -MF args to clang when doing `@cImport`, which gives us a complete list of files that the C code read from. Then we add these to the cache. So even when using `@cImport` Zig's caching system remains perfect. This is a proof of concept for the mechanism that the self-hosted compiler will use to watch and rebuild files.
2019-02-25building DLLs on Windows works betterAndrew Kelley
2019-02-25first class support for compiling C codeAndrew Kelley
New CLI parameter: --c-source [options] [file] It even works with `--cache on` when there are transitive dependencies. Instead of `builder.addCExecutable`, use `builder.addExecutable` and pass `null` for the root source file. Then use `builder.addCSourceFile`, which takes the path to the C code, and a list of C compiler args. Be sure to linkSystemLibrary("c") if you want libc headers to be available. Merge TestStep into LibExeObjStep. That was long overdue.
2019-02-23better libc detection (#1996)Andrew Kelley
* better libc detection This introduces a new command `zig libc` which prints the various paths of libc files. It outputs them to stdout in a simple text file format that it is capable of parsing. You can use `zig libc libc.txt` to validate a file. These arguments are gone: --libc-lib-dir [path] directory where libc crt1.o resides --libc-static-lib-dir [path] directory where libc crtbegin.o resides --msvc-lib-dir [path] (windows) directory where vcruntime.lib resides --kernel32-lib-dir [path] (windows) directory where kernel32.lib resides Instead we have this argument: --libc [file] Provide a file which specifies libc paths This is used to pass a libc text file (which can be generated with `zig libc`). So it is easier to manage multiple cross compilation environments. `--cache on` now works when linking against libc. `ZigTarget` now has a bool field `is_native` Better error messaging when you try to link against libc or use `@cImport` but the various paths cannot be found. It should also be faster. * save native_libc.txt in zig-cache This avoids having to detect libc at runtime on every invocation.
2019-02-22implement vector negationAndrew Kelley
also fix vector behavior tests, they weren't actually testing runtime vectors, but now they are. See #903
2019-02-22fix `@bitCast` when src/dest types have mismatched handle_is_ptrAndrew Kelley
* separate BitCast and BitCastGen instructions * closes #991 * closes #1934 * unrelated: fix typo in docs (thanks gamester for pointing it out)
2019-02-21better handling of arrays in packed structsAndrew Kelley
* Separate LoadPtr IR instructions into pass1 and pass2 variants. * Define `type_size_bits` for extern structs to be the same as their `@sizeOf(T) * 8` and allow them in packed structs. * More helpful error messages when trying to use types in packed structs that are not allowed. * Support arrays in packed structs even when they are not byte-aligned. * Add compile error for using arrays in packed structs when the padding bits would be problematic. This is necessary since we do not have packed arrays. closes #677
2019-02-21`@sliceToBytes` works at comptimeAndrew Kelley
closes #262
2019-02-20packed structs support comptime bitcastingAndrew Kelley
* `type_size_store` is no longer a thing. loading and storing a pointer to a value may dereference up to `@sizeOf(T)` bytes, even for integers such as `u24`. * fix `types_have_same_zig_comptime_repr` to not think that the same `ZigTypeId` means the `ConstExprValue` neccesarily has the same representation. * implement `buf_write_value_bytes` and `buf_read_value_bytes` for `ContainerLayoutPacked` closes #1120
2019-02-19valgrind client requests for undefined valuesAndrew Kelley
with this change, when you assign undefined, zig emits a few assembly instructions to tell valgrind that the memory is undefined it's on by default for debug builds, and disabled otherwise. only support for linux, darwin, solaris, mingw on x86_64 is currently implemented. --disable-valgrind turns it off even in debug mode. --enable-valgrind turns it on even in release modes. It's always disabled for compiler_rt.a and builtin.a. Adds `@import("builtin").valgrind_support` which lets code know at comptime whether valgrind client requests are enabled. See #1989
2019-02-19remove --no-rosegment workaround now that valgrind bug is fixedAndrew Kelley
See #896 Zig 0.3.0+ and Valgrind 3.14+ do not need the workaround.
2019-02-18export _mh_execute_header with weak linkageAndrew Kelley
* also fix extern variables with initialiaztion values to generate runtime code * remove the workaround in example/shared_library/mathtest.zig * introduce the ability for global variables to have Weak and LinkOnce linkage * fix `@export` to work for non-functions. this code needs to be audited though. * fix comptime ptrcast not keeping bigger alignment * fix linker warnings when targeting darwin closes #1903
2019-02-18Add align attribute for params pointersLemonBoy
2019-02-17Add NetBSD supportMaya Rashish
Mostly picking the same paths as FreeBSD. We need a little special handling for crt files, as netbsd uses its own (and not GCC's) for those, with slightly different names.
2019-02-15typecheck the panic functionAndrew Kelley
this adds the prototype of panic to @import("builtin") and then uses it to do an implicit cast of the panic function to this prototype, rather than redoing all the implicit cast logic. closes #1894 closes #1895
2019-02-15Merge pull request #1965 from ziglang/c-pointer-typeAndrew Kelley
implement C pointers
2019-02-14omit nonnull attribute for C pointersAndrew Kelley
See #1059
2019-02-14runtime safety check for casting null to pointerAndrew Kelley
see #1059
2019-02-11add C pointer type to @typeInfoAndrew Kelley
See #1059
2019-02-11C pointer comparison and arithmeticAndrew Kelley
See #1059
2019-02-10avoid needlessly creating global constantsAndrew Kelley
This deletes some legacy cruft, and produces leaner object files. Example: ``` var x: i32 = 1234; export fn entry() i32 { return x; } ``` This produces: ``` @x = internal unnamed_addr global i32 1234, align 4 @0 = internal unnamed_addr constant i32* @x, align 8 ``` and @0 is never even used. After this commit, @0 is not produced. This fixes a bug: Zig was creating invalid LLVM IR when one of these globals that shouldn't exist takes the address of a thread local variable. In LLVM 8.0.0rc2, it would produce a linker error. But probably after my bug report is solved it will be caught by the IR verifier. https://bugs.llvm.org/show_bug.cgi?id=40652
2019-02-10avoid needlessly creating global constantsAndrew Kelley
This deletes some legacy cruft, and produces leaner object files. Example: ``` var x: i32 = 1234; export fn entry() i32 { return x; } ``` This produces: ``` @x = internal unnamed_addr global i32 1234, align 4 @0 = internal unnamed_addr constant i32* @x, align 8 ``` and @0 is never even used. After this commit, @0 is not produced. This fixes a bug: Zig was creating invalid LLVM IR when one of these globals that shouldn't exist takes the address of a thread local variable. In LLVM 8.0.0rc2, it would produce a linker error. But probably after my bug report is solved it will be caught by the IR verifier. https://bugs.llvm.org/show_bug.cgi?id=40652
2019-02-09Merge remote-tracking branch 'origin/master' into llvm8Andrew Kelley
2019-02-09implement vector math safety with ext and truncAndrew Kelley
2019-02-09implement vector addition with safety checkingAndrew Kelley
this would work if @llvm.sadd.with.overflow supported vectors, which it does in trunk. but it does not support them in llvm 7 or even in llvm 8 release branch. so the next commit after this will have to do a different strategy, but when llvm 9 comes out it may be worth coming back to this one.
2019-02-07fix using the result of @intCast to u0Andrew Kelley
closes #1817
2019-02-07Merge remote-tracking branch 'origin/master' into llvm8Andrew Kelley
2019-02-07better error message when LLVM does not understand a tripleAndrew Kelley
2019-02-06Merge pull request #1924 from ziglang/tlsAndrew Kelley
Implement Thread Local Variables
2019-02-06implement Thread Local Storage on WindowsAndrew Kelley
2019-02-06require running std lib tests coherentlyAndrew Kelley
this should actually improve CI times a bit too See the description at the top of std/os/startup.zig (deleted in this commit) for a more detailed understanding of what this commit does.
2019-02-06thread local storage working for linux x86_64Andrew Kelley
2019-02-05Added support for vector wrapping mult and subJimmi Holst Christensen
* I also merged the code that generates ir for add, sub, and mult
2019-02-04Merge remote-tracking branch 'origin/master' into llvm8Andrew Kelley
2019-02-04SIMD: array to vector, vector to array, wrapping int addAndrew Kelley
also vectors and arrays now use the same ConstExprVal representation See #903
2019-02-01introduce --single-threaded build optionAndrew Kelley
closes #1764 This adds another boolean to the test matrix; hopefully it does not inflate the time too much. std.event.Loop does not work with this option yet. See #1908
2019-01-30introduce vector type for SIMDAndrew Kelley
See #903 * create with `@Vector(len, ElemType)` * only wrapping addition is implemented This feature is far from complete; this is only the beginning.
2019-01-29backport copy elision changesAndrew Kelley
This commit contains everything from the copy-elision-2 branch that does not have to do with copy elision directly, but is generally useful for master branch. * All const values know their parents, when applicable, not just structs and unions. * Null pointers in const values are represented explicitly, rather than as a HardCodedAddr value of 0. * Rename "maybe" to "optional" in various code locations. * Separate DeclVarSrc and DeclVarGen * Separate PtrCastSrc and PtrCastGen * Separate CmpxchgSrc and CmpxchgGen * Represent optional error set as an integer, using the 0 value. In a const value, it uses nullptr. * Introduce type_has_one_possible_value and use it where applicable. * Fix debug builds not setting memory to 0xaa when storing undefined. * Separate the type of a variable from the const value of a variable. * Use copy_const_val where appropriate. * Rearrange structs to pack data more efficiently. * Move test/cases/* to test/behavior/* * Use `std.debug.assertOrPanic` in behavior tests instead of `std.debug.assert`. * Fix outdated slice syntax in docs.
2019-01-09Merge remote-tracking branch 'origin/master' into llvm8Andrew Kelley
2019-01-09when rendering llvm const values, ensure the types alignAndrew Kelley
the representation of the const expr val in zig, and the type that we tell LLVM it is.
2019-01-08Merge remote-tracking branch 'origin/master' into llvm8Andrew Kelley
2019-01-08fix debug info for function pointersAndrew Kelley
found when testing against LLVM 8 see https://bugs.llvm.org/show_bug.cgi?id=40198