Commit Graph

86 Commits

Author SHA1 Message Date
Andrew Kelley
97bfeac13f self-hosted: create tmp dir for .o files and emit .o file for fn 2018-07-16 20:52:50 -04:00
Ben Noordhuis
d464b25322 support --target-arch wasm32 (#1094)
Add wasm32 support to the build-obj, build-exe and build-lib commands
of the stage 1 compiler.  Wasm64 should work transparently once it's
supported in upstream LLVM.

To export a function:

    // lib.zig - for exposition, not necessary for this example
    pub use @import("add.zig");

    // add.zig
    export fn add(a: i32, b: i32) i32 {
        return a + b;
    }

To import a function:

    // cube.zig
    extern fn square(x: i32) i32;

    export fn cube(x: i32) i32 {
        return x * square(x);
    }
2018-06-09 22:39:22 -04:00
Andrew Kelley
f1f998e071 improve cmpxchg
* remove @cmpxchg, add @cmpxchgWeak and @cmpxchgStrong
   - See explanations in the langref.
 * add operand type as first parameter
 * return type is ?T where T is the operand type

closes #461
2018-04-18 12:16:42 -04:00
Alexandros Naskos
1c85050dad Set SizeLevel to 2 in ReleaseSmall mode 2018-04-16 03:54:40 +03:00
Alexandros Naskos
253ecd5c11 Added ReleaseSmall mode 2018-04-16 03:26:10 +03:00
Andrew Kelley
a217c764db Merge remote-tracking branch 'origin/master' into llvm6 2018-03-01 22:25:15 -05:00
Andrew Kelley
b018c64ca2 add coroutine LLVM passes 2018-02-25 18:09:39 -05:00
Andrew Kelley
9f6c5a20de codegen for coro_id instruction
See #727
2018-02-25 15:10:29 -05:00
Andrew Kelley
e7ab2bc553 Merge remote-tracking branch 'origin/master' into llvm6 2018-02-13 11:53:20 -05:00
Andrew Kelley
02f70cda8a zig_llvm.cpp uses new(std::nothrow)
This fixes a mismatched malloc/delete because
we were allocating with malloc and then llvm was
freeing with delete.
2018-02-13 10:54:46 -05:00
Andrew Kelley
ef6260b3a7 Merge remote-tracking branch 'origin/master' into llvm6 2018-02-11 23:49:20 -05:00
Andrew Kelley
5161d70620 *WIP* error sets 2018-01-31 01:51:31 -05:00
Andrew Kelley
38658a597b Merge branch 'master' into llvm6 2018-01-06 02:59:17 -05:00
Andrew Kelley
17e68c4a11 disable NewGVN
closes #673
2018-01-06 00:15:37 -05:00
Andrew Kelley
6bfaf262d5 Merge branch 'master' into llvm6 2017-12-26 21:44:08 -05:00
Andrew Kelley
6fece14cfb self-hosted: build against zig_llvm and embedded LLD
Now the self-hosted compiler re-uses the same C++ code for interfacing
with LLVM as the C++ code.
It also links against the same LLD library files.
2017-12-26 19:44:08 -05:00
Andrew Kelley
fe66046283 Merge remote-tracking branch 'origin/master' into llvm6 2017-12-23 12:00:25 -05:00
Andrew Kelley
62c25af802 add higher level arg-parsing API + misc. changes
* add @noInlineCall - see #640
   This fixes a crash in --release-safe and --release-fast modes
   where the optimizer inlines everything into _start and
   clobbers the command line argument data.
   If we were able to verify that the user's code never reads
   command line args, we could leave off this "no inline"
   attribute.
 * add i29 and u29 primitive types. u29 is the type of alignment,
   so it makes sense to be a primitive.
   probably in the future we'll make any `i` or `u` followed by
   digits into a primitive.
 * add `aligned` functions to Allocator interface
 * add `os.argsAlloc` and `os.argsFree` so that you can get
   a `[]const []u8`, do whatever arg parsing you want, and then free
   it. For now this uses the other API under the hood, but it could
   be reimplemented to do a single allocation.
 * add tests to make sure command line argument parsing works.
2017-12-06 18:12:05 -05:00
Andrew Kelley
42004f9013 Merge branch 'master' into llvm6 2017-12-04 15:28:17 -05:00
Andrew Kelley
cf96b6f87b update to LLVM 5.0.1rc2 2017-12-01 13:44:28 -05:00
Andrew Kelley
d4cd4a35d5 update fast math llvm API to latest 2017-11-29 19:11:34 -05:00
Andrew Kelley
91ef68f9b1 Merge remote-tracking branch 'origin/master' into llvm6 2017-11-29 16:34:50 -05:00
Andrew Kelley
f276fd0f37 basic union support
See #144
2017-11-15 13:04:18 -05:00
Andrew Kelley
3a600297ca Merge remote-tracking branch 'origin/master' into llvm6 2017-11-06 22:41:12 -05:00
Marc Tiehuis
795703a39c Add emit command-line option (#580)
Add emit command-line option
2017-11-03 09:09:33 -04:00
Andrew Kelley
94ec2190f8 update to llvm master 2017-11-02 21:54:24 -04:00
Andrew Kelley
d7e28f991d remove CXX ABI workaround
the actual solution is you must compile zig with the same
compiler that compiled llvm, lld, and clang.

reverts 8d60ffe314
2017-10-23 22:37:59 -04:00
Andrew Kelley
562f91e875 clean up some resources 2017-10-15 21:06:04 -04:00
Andrew Kelley
aa78827db2 add module flag to emit CodeView for COFF object files
see #516
2017-10-10 18:04:02 -04:00
Andrew Kelley
b8ee3a8143 add -mllvm support
useful for debugging crashes in llvm optimizer
2017-09-17 17:46:16 -04:00
Josh Wolfe
1449e71de8 cleanup whitespace 2017-09-01 10:27:04 -07:00
Andrew Kelley
3f5dd08ca8 codegen: all stores specify align value
See #37
2017-08-30 04:23:52 -04:00
Andrew Kelley
c5c9d98065 introduce align keyword
* remove `@setGlobalAlign`
 * add align keyword for setting alignment on functions and
   variables.
 * loads and stores use alignment from pointer
 * memcpy, memset use alignment from pointer
 * add syntax for pointer alignment
 * slices can have volatile
 * add u2, i2 primitives
 * ignore preferred align and use abi align everywhere
 * back to only having alignOf builtin.
   preferredAlignOf is too tricky to be useful.
   See #432. Partial revert of
   e726925e80.

See #37
2017-08-29 07:51:34 -04:00
Andrew Kelley
2bd6c60752 update for llvm 5.0.0rc1 2017-08-26 00:34:40 -04:00
Andrew Kelley
35d3444e27 more intuitive left shift and right shift operators
Before:
 * << is left shift, not allowed to shift 1 bits out
 * <<% is left shift, allowed to shift 1 bits out
 * >> is right shift, allowed to shift 1 bits out

After:
 * << is left shift, allowed to shift 1 bits out
 * >> is right shift, allowed to shift 1 bits out
 * @shlExact is left shift, not allowed to shift 1 bits out
 * @shrExact is right shift, not allowed to shift 1 bits out

Closes #413
2017-08-09 10:09:38 -04:00
Andrew Kelley
6a93dda3e1 progress toward windows hello world working 2017-06-14 00:04:34 -04:00
Andrew Kelley
29defd705d back to AT&T syntax for assembly
this reverts 5c04730534.

sadly the quality of the intel dialect in llvm's assembly
parser has many frustrating bugs, and generally has unfortunate
syntax.

the plan is to use AT&T for now since it at least works,
and eventually zig will have its own assembly parser for
x86 and it will be as close to NASM as possible.
2017-04-30 11:28:11 -04:00
Andrew Kelley
bf67427c67 fix crash when using zig to link
without explicit dynamic linker
2017-04-13 01:15:25 -04:00
Andrew Kelley
41144a8566 ability to inline at function callsite
closes #306
2017-04-13 00:13:54 -04:00
Andrew Kelley
7f47b0c271 run alwaysinline pass in debug mode
before this commit, the optimized IR code that is displayed in
--verbose mode is not actually what gets emitted to an object
file.

that is now corrected, and we make sure to run the alwaysinliner
pass even in debug mode, so you can rely on "inline" keyword
inlining a function, guaranteed.

See #306
2017-04-11 03:37:44 -04:00
Andrew Kelley
5c04730534 use intel dialect for inline assembly
closes #242
2017-03-23 18:59:43 -04:00
Andrew Kelley
d10bbd28e9 use lld instead of system linker 2017-03-13 11:54:56 -04:00
Andrew Kelley
cd31f875a6 update to llvm 4.0 2017-03-10 02:29:01 -05:00
Andrew Kelley
573f3f8d48 coldcc works better
* Only use Cold Calling Convention on x86
 * Add the cold attribute to functions marked with coldcc
2017-02-06 13:50:19 -05:00
Andrew Kelley
b9c943b066 tell LLVM the target sub arch type 2017-02-05 18:23:54 -05:00
Andrew Kelley
74d41ce44b infer hard float from target environments that imply it 2017-02-05 00:16:49 -05:00
Andrew Kelley
1fa4d2a5af rename LLVMZig to ZigLLVM 2016-09-10 20:53:57 -04:00
Andrew Kelley
20eb749ad6 generate debug info for global constants
See #41
2016-09-04 22:32:23 -07:00
Andrew Kelley
4e7effd3d3 port to llvm 3.9 2016-09-04 18:30:40 -07:00
Andrew Kelley
404defd99b add div_exact builtin fn
closes #149
2016-05-07 20:53:16 -07:00