Commit Graph

8 Commits

Author SHA1 Message Date
Andrew Kelley
b109daacdd stage2: fix test cases to add pub on exported _start fn
This way the start code respects them.
2021-05-12 23:17:24 -07:00
Andrew Kelley
713f113822 stage2: improve orelse implementation
* Now it supports being an lvalue (see additional lines in the test
   case).
 * Properly handles a pointer result location (see additional lines in
   the test case that assign the result of the orelse to a variable
   rather than a const).
 * Properly sets the result location type when possible, so that type
   inference of an `orelse` operand expression knows its result type.
2021-03-02 21:59:23 -07:00
Timon Kruiper
ed6757ece6 stage2: add a test for for loops in LLVM backend 2021-03-02 19:02:55 -07:00
Timon Kruiper
d4ec0279d3 stage2: add support for optionals in the LLVM backend
We can now codegen optionals! This includes the following instructions:
- is_null
- is_null_ptr
- is_non_null
- is_non_null_ptr
- optional_payload
- optional_payload_ptr
- br_void

Also includes a test for optionals.
2021-03-02 19:02:55 -07:00
Andrew Kelley
30a824cb9e astgen: eliminate rlWrapPtr and all its callsites
The following AST avoids unnecessary derefs now:
 * error set decl
 * field access
 * array access
 * for loops: replace ensure_indexable and deref on the len_ptr with a
   special purpose ZIR instruction called indexable_ptr_len.

Added an error note when for loop operand is the wrong type.

I also accidentally implemented `@field`.
2021-01-19 00:38:53 -07:00
Timon Kruiper
e1d8073d2f stage2: add support for loops in LLVM backend
A simple `while(true) {}` loop generates the following LLVMIR:
```
define i32 @main() {
Entry:
  br label %Loop

Loop:                                 ; preds = %Loop, %Entry
  br label %Loop
}
```

Also implement TZIR printing for loops and add a corresponding test.
2021-01-10 17:47:34 -08:00
Timon Kruiper
56c059077c stage2: add initial impl of control flow in LLVM backend
The following TZIR instrutions have been implemented in the backend:
- all cmp operators (lt, lte, gt, gte, eq, neq)
- block
- br
- condbr

The following LLVMIR is generated for a simple assert function:
```
define void @assert(i1 %0) {
Entry:
  %1 = alloca i1, align 1
  store i1 %0, i1* %1, align 1
  %2 = load i1, i1* %1, align 1
  %3 = xor i1 %2, true
  br i1 %3, label %Then, label %Else

Then:                                             ; preds = %Entry
  call void @llvm.debugtrap()
  unreachable

Else:                                             ; preds = %Entry
  br label %Block

Block:                                            ; preds = %Else
  ret void
}
```

See tests for more examples.
2021-01-08 19:30:52 +01:00
Timon Kruiper
b1cfa923be stage2: rename and move files related to LLVM backend 2021-01-06 10:52:20 +01:00