# stage2: add initial impl of control flow in LLVM backend · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/56c059077cdaf71220cb44f06902051a34ffd31d)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 56c059077cdaf71220cb44f06902051a34ffd31d

Requested commit: 56c059077cdaf71220cb44f06902051a34ffd31d

Commit: 56c059077cdaf71220cb44f06902051a34ffd31d

Tree: 6caa61bd74fdb294c293e025f9f76ae3580aac79

Author: Timon Kruiper

Committer: Timon Kruiper

## Message

````
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.

````

## Parents

- [3715ed7b54d4382a4495eb041ff3f9ad987bacfb](https://git.cafe/gitcafe/zig/commit/3715ed7b54d4382a4495eb041ff3f9ad987bacfb?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/56c059077cdaf71220cb44f06902051a34ffd31d?format=markdown)
