2645 Commits

Author SHA1 Message Date
Andrew Kelley
083c0f1ceb stage2 codegen: proper abstraction for re-using dying operands
closes #6064
2020-08-18 23:11:56 -07:00
Andrew Kelley
771f40204e
Merge pull request #6086 from Vexu/stage2
Stage2: more astgen stuff
2020-08-18 22:02:55 -04:00
Isaac Freund
6242ae35f3
stage2/wasm: implement function calls
During codegen we do not yet know the indexes that will be used for
called functions. Therefore, we store the offset into the in-memory
code where the index is needed with a pointer to the Decl and use this
data to insert the proper indexes while writing the binary in the flush
function.
2020-08-19 02:05:13 +02:00
Andrew Kelley
15bcfcd368 stage2: fix use-after-free when printing ZIR 2020-08-18 15:25:01 -07:00
Veikka Tuominen
d139e44cfa
Merge pull request #5495 from xackus/fix_5314
stage1: fix non-exhaustive enums with one field
2020-08-18 23:55:44 +03:00
Vexu
2b45e23477
stage2: character literals and multiline strings 2020-08-18 20:10:18 +03:00
Andrew Kelley
bdb8c49418 stage1: update compile error tests
follow-up to 56c81c713f749f858089e5bcdf9e6fac588bcf86
2020-08-18 08:44:34 -07:00
Andrew Kelley
3cc1f8b624
Merge pull request #6056 from ifreund/wasm-backend
stage2: add a wasm backend
2020-08-18 00:28:05 -04:00
Ashish Shekar
27cb23cbc5
Handle singular param count word in error messages (#6073) 2020-08-17 22:18:29 -04:00
Isaac Freund
9f44284ad5
stage2/wasm: add basic test cases 2020-08-18 01:47:03 +02:00
Andrew Kelley
96a27557e2 stage2 test harness: at least build all compare output tests
This should have been removed with an earlier commit that improved the
test harness.
2020-08-17 15:27:41 -07:00
Vexu
2948f2d262
fix cast from invalid non-exhaustive enum to union 2020-08-17 20:48:22 +03:00
Vexu
1e835e0fcc
disallow '_' prong when switching on non-exhaustive tagged union
A tagged union cannot legally be initiated to an invalid enumeration
2020-08-17 20:47:31 +03:00
xackus
65185016f1
stage1: fix non-exhaustive enums with one field 2020-08-17 20:45:34 +03:00
Andrew Kelley
66d76cc4f9 stage2: codegen for labeled blocks 2020-08-15 17:03:05 -07:00
Andrew Kelley
2cd19c05d0 stage1: remove buggy "unable to inline function" compile error
We still want this compile error but I'm giving up on implementing it
correctly in stage1. It's been buggy and has false positives sometimes.

I left the test cases there, but commented out, so that when we go
through the stage1 compile error cases and get coverage for them in
stage2 we can reactivate the test cases.

closes #2154
2020-08-15 09:53:39 -07:00
Andrew Kelley
7a39a038db stage2: proper semantic analysis of improper returning of implicit void 2020-08-14 13:08:55 -07:00
Andrew Kelley
28a9da8bfc stage2: implement while loops (bool condition)
* introduce a dump() function on Module.Fn which helpfully prints to
   stderr the ZIR representation of a function (can be called before
   attempting to codegen it). This is a debugging tool.
 * implement x86 codegen for loops
 * liveness: fix analysis of conditional branches. The logic was buggy
   in a couple ways:
   - it never actually saved the results into the IR instruction (fixed now)
   - it incorrectly labeled operands as dying when their true death was
     after the conditional branch ended (fixed now)
 * zir rendering is enhanced to show liveness analysis results. this
   helps when debugging liveness analysis.
 * fix bug in zir rendering not numbering instructions correctly

closes #6021
2020-08-13 20:32:32 -07:00
Veikka Tuominen
f5b99abc93
Merge pull request #6045 from Vexu/block
Add error for unused/duplicate labels.
2020-08-14 01:04:05 +03:00
Vexu
13e472aa2a
translate-c: add return if one is needed 2020-08-13 18:40:14 +03:00
Vexu
6b2ce9d1e9 stage2: split unwrap_optional to safe and unsafe verions 2020-08-13 08:12:17 -07:00
Vexu
4a40282391 stage2: implement unwrap optional 2020-08-13 08:12:17 -07:00
Vexu
c5368ba20c
translate-c: ensure generated labels are unique 2020-08-13 15:27:29 +03:00
Noam Preil
5a166cead8 CBE: fix handling of IR dependencies 2020-08-12 21:58:21 -07:00
Noam Preil
dbd1e42ef2 CBE: Sorta working intcasts? 2020-08-12 21:58:21 -07:00
Noam Preil
78fe86dcd2 CBE: support unreachable on GCC 2020-08-12 21:58:21 -07:00
Noam Preil
d3eec7d46b CBE: working parameters 2020-08-12 21:58:21 -07:00
Noam Preil
dd1f1487e4 CBE: Use zig_noreturn instead of noreturn to avoid namespace conflict 2020-08-12 21:58:21 -07:00
Vexu
3734881577
add error for unused/duplicate block labels 2020-08-13 01:13:17 +03:00
Vexu
2b28cebf64
translate-c: use mangled name when macro translation fails
Closes #6009
2020-08-11 12:24:45 +03:00
Vexu
cf5932b236
translate-c: convert int to bool if bool is expected 2020-08-11 12:24:45 +03:00
Vexu
dfcac3cd76
translate-c: always add extern token for functions without body 2020-08-11 12:24:45 +03:00
Andrew Kelley
fd47839064 stage2: fix crash on empty source file 2020-08-08 18:19:48 -07:00
Andrew Kelley
c594f8dc26 stage2 tests: support the -Denable-qemu options and friends 2020-08-04 15:32:16 -07:00
pfg
ea3cc777cc stage2: riscv test case 2020-08-04 14:38:33 -07:00
pfg
52ae2b10aa stage2: starting on a riscv64 backend 2020-08-04 14:38:33 -07:00
Vexu
4ab2f947f9
translate-c: recognize other type trait expressions
Closes #5979
2020-08-04 00:48:29 +03:00
Vexu
6bba7c702b add compile error for alignCasting zero sized types 2020-08-02 17:49:16 +00:00
Andrew Kelley
606f157a6b stage2: register-aliasing-aware codegen
* unify duplicated register allocation codepath
 * support the x86_64 concept of register aliasing
 * slightly improved memset codegen, supports sizes 1, 2, 4, 8
2020-07-29 02:29:37 -07:00
Vexu
5f0bde6358 add helpful error note for when function cannot return an error
This has caused frequent confusion since it looks like you are handling
errors correctly with a try but you forgot to change your return type.
2020-07-28 04:24:52 +00:00
Andrew Kelley
b8e22d2002 stage2: implement integer return values 2020-07-27 18:59:13 -07:00
Henrik Laxhuber
442025481c Fix parsing of unsigned in translate-c.
Previously, `unsigned` was parsed as the shorthand for `unsigned int`.
This commit introduces code to parse `unsigned short`, `unsigned int`,
`unsigned long`, and `unsigned long long`.

There is a comment in the code about std.c.parse` - Im not
familiar with zig internals, but it seems like this is a separate
C parsing implementation. In the long run, it probably makes
sense to merge both implementations, so this commit should be
regarded as a quick fix that doesn't address an apparently
underlying issue.
2020-07-27 13:43:49 +03:00
Andrew Kelley
a36772ee64
Merge pull request #5693 from antlilja/switch-unreachable-else
Add error message for unreachable else prong in switch
2020-07-26 05:46:18 +00:00
Andrew Kelley
995fd7314c Revert "Support taking extern pointers at comptime"
This reverts commit d3ebd428650748e60db70dd2171cc044855814b1.

This caused a build failure on multiple targets.
2020-07-24 14:06:44 -07:00
yvt
d3ebd42865 Support taking extern pointers at comptime
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-24 13:33:17 -07:00
Luuk de Gram
ee7fbb9548
Restructured arithmetic operations 2020-07-24 17:16:48 +02:00
Luuk de Gram
198c09197b
Fixed test case 2020-07-24 17:16:48 +02:00
Luuk de Gram
9d79741fd0
Stage2: Add support for substraction 2020-07-24 17:16:48 +02:00
Andrew Kelley
aac6e8c418 self-hosted: AST flattening, astgen improvements, result locations, and more
* AST: flatten ControlFlowExpression into Continue, Break, and Return.
 * AST: unify identifiers and literals into the same AST type: OneToken
 * AST: ControlFlowExpression uses TrailerFlags to optimize storage
   space.
 * astgen: support `var` as well as `const` locals, and support
   explicitly typed locals. Corresponding Module and codegen code is not
   implemented yet.
 * astgen: support result locations.
 * ZIR: add the following instructions (see the corresponding doc
   comments for explanations of semantics):
   - alloc
   - alloc_inferred
   - bitcast_result_ptr
   - coerce_result_block_ptr
   - coerce_result_ptr
   - coerce_to_ptr_elem
   - ensure_result_used
   - ensure_result_non_error
   - ret_ptr
   - ret_type
   - store
   - param_type
 * the skeleton structure for result locations is set up. It's looking
   pretty clean so far.
 * add compile error for unused result and compile error for discarding
   errors.
 * astgen: split builtin calls up to implemented manually, and implement
   `@as`, `@bitCast` (and others) with respect to result locations.
 * add CLI support for hex and raw object formats. They are not
   supported by the self-hosted compiler yet, and emit errors.
 * rename `--c` CLI to `-ofmt=[objectformat]` which can be any of the
   object formats. Only ELF and C are supported so far. Also added missing
   help to the help text.
 * Remove hard tabs from C backend test cases. Shame on you Noam, you
   are grounded, you should know better, etc. Bad boy.
 * Delete C backend code and test case that relied on comptime_int
   incorrectly making it all the way to codegen.
2020-07-23 23:05:26 -07:00
Vexu
fd2f034e31
fix comptime comparisons of different sized floats 2020-07-21 22:29:15 +03:00