Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ustb-owl/Lava

A compiler of C subset by USTB OWL Wheel Lab.
https://github.com/ustb-owl/Lava

compiler

Last synced: 2 months ago
JSON representation

A compiler of C subset by USTB OWL Wheel Lab.

Awesome Lists containing this project

README

        

# Lava
A compiler of C subset by USTB OWL Wheel Lab.

Lava can compile extended SysY languate to ARM assembly and LLVM IR.

## Building
Lava requires:
- `cmake` 3.16 or later.
- C++ compiler supporting C++17 standard.

```shell script
git clone https://github.com/ustb-owl/Lava
cd compiler && mkdir build && cd build
cmake .. && make -j8
./lacc -h
```

## Usage

```
Usage: lacc [options...] [filename]
Options:
-o, --output set output file name
-S, --dump-asm generate asm file
-I, --dump-ir generate ir file
-T, --dump-ast generate ast file
-C, --dump-cfg generate visable CFG file
filename input filename (Required)
-h, --help Shows this page
```

## Features

- Handwritten frontend.
- Strong typed IR in SSA form.
- Can emit LLVM IR
- Optimizer based on pass and pass manager.
- Flexible phase order
- Low-level IR (LLIR) for multi-architecture machine instruction abstraction.
- Visable control flow graph.

LLVM IR generated by Lava:
```llvm
define i32 @main() {
entry:
br label %while.cond0

while.cond0: ; preds: entry, loop.body0
%phi0 = phi i32 [ 0, %entry ], [ %t0, %loop.body0 ]
%phi1 = phi i32 [ 3, %entry ], [ %t1, %loop.body0 ]
%t2 = icmp slt i32 %phi0, 5
br i1 %t2, label %loop.body0, label %inline_exit0

loop.body0: ; preds: while.cond0
%t1 = mul i32 %phi1, 2
%t0 = add i32 %phi0, 1
br label %while.cond0

inline_exit0: ; preds: while.cond0
ret i32 %phi1
}
```

CFG genereated by Lava:
![cfg](https://github.com/ustb-owl/Lava/blob/master/doc/ir.svg?raw=true)

## Automated Testing Tools

See [lava-test](https://github.com/ustb-owl/lava-test)