A compiler of C subset by USTB OWL Wheel Lab.
Lava can compile extended SysY languate to ARM assembly and LLVM IR.
Lava requires:
cmake3.20 or later.- C++ compiler supporting C++23 standard.
git clone https://github.com/ustb-owl/Lava
cd compiler && mkdir build && cd build
cmake .. && make -j8
./lacc -h
ninja formatUsage: lacc [OPTIONS] [input]
Positionals:
input input filename
Options:
-o, --output set output file name
--emit emit ast, ir, asm, or cfg
-T, --dump-ast dump AST
-I, --dump-ir dump LLVM IR
-S, --dump-asm dump assembly
-C, --dump-cfg dump CFG
-O, --opt-level optimization level (0-2)
--no-ra disable register allocation
--list-passes list middle-end transform passes
--print-pipeline print active middle-end pipeline
--time-passes print middle-end pass timings
--disable-pass disable one or more middle-end passes
--run-pass run only the listed middle-end passes
--start-after start the pipeline after the named pass
--stop-after stop the pipeline after the named pass
--dump-ir-before dump LLVM IR before the named pass
--dump-ir-after dump LLVM IR after the named pass
--dump-ir-dir directory for IR dumps
-h, --help show this help message
Examples:
./lacc foo.sy -O2 --emit=ir
./lacc --list-passes
./lacc --print-pipeline -O2
./lacc foo.sy -O2 --disable-pass=local-gvn --emit=ir
./lacc foo.sy -O2 --stop-after=mem2reg --dump-ir-after=mem2reg- 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:
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
}See lava-test