- Current Progress: Optimization done...
- A language-processing system:
graph TB
S(source program)-->P[Preprocessor]
P--modified source program-->C[Compiler]
C--target assembly program-->A[Assembler]
A--relocatable machine code-->L[Linker/Loader]
li[library file <br> relocatable object files]-->L
L-->T(target machine code)
antlr4 <filename>.g4 -visitor
javac *.java
grun <filename> <rulename> -tokens
diff <file1> <file2> -qZB # regardless of space endl
compile java file:
javac <filename>.java
javac -encoding UTF-8 <filename>.java # support Chinese comment
java <filename>
enable assert
mode: in IDEA's run configuration, add -ea
in "VM option".
.c
to .ll
clang <filename>.c -S -emit-llvm -O0 -fno-discard-value-names
.ll
to .s
llc builtin.ll -o builtin.s -march=riscv32 -mattr=+m
- File structure:
graph LR
g4[Mx.g4]-->V[MxBaseVisitor]
g4-->P[MxParser, MxLexer...]
V==ASTNode==>A[ASTBuilder]
A--Scope-->S[SemanticChecker]
A--for debug-->D[ASTPrinter]
- Procedure description:
graph LR
I(Code)--Character Stream-->L[Lexer]
L--Token Stream-->P[Parser]
P--frontend.parser tree-->AB[AST build]
P--visitor mode-->AB[AST build]
AB==AST node==>S[Semantic check]
AB==Scope manager==>S
based on LLVM IR
RISCV32i
- Yx written by Antlr4
- Tiger Book (Modern Compiler Implementation)
- Dragon Book (Compilers: Principles, Techniques, and Tools 2e)
- NJU Static Analysis by Prof. Yue Li and Tian Tan
- SSA Book