The initial idea was to make "tree-walking code generation"; so source code goes through lexer and parser and finally ends up in AST.
That AST will be walked and LLVM IR would be generated during walk. Look in middleware/llvm-gen
for these files.
.ks file --> AST --> LLVM IR --> assembly
^ ^ ^
parser lowering backend (llc)
While working on that I found about something called MLIR.
The framework built for language hackers which can be used for sequential lowering.
It will help us when writing language specific optimizations.
- https://github.com/j2kun/mlir-tutorial
- https://mlir.llvm.org/docs/Tutorials/Toy/Ch-1/
- https://medium.com/sniper-ai/mlir-tutorial-create-your-custom-dialect-lowering-to-llvm-ir-dialect-system-1-1f125a6a3008
- https://www.youtube.com/watch?v=Ij4LswX1tZU&list=PLlONLmJCfHTo9WYfsoQvwjsa5ZB6hjOG5&index=1
- https://llvm.org/docs/TableGen/ProgRef.html
- https://mlir.llvm.org/docs/DefiningDialects/Operations/
- https://mlir.llvm.org/docs/PassManagement/#operation-pass-static-filtering-by-op-type
- Interesting Passes and Dialects:
- from
test.ll
(IR code) totest.bc
(Machine-level bitcode) usellvm-as
.llvm-dis
can be used for dissasembling.
- Compile LLVM IR to bitcode:
llvm-as yourfile.ll -o yourfile.bc
- Compile bitcode to native assembly:
llc yourfile.bc -o yourfile.s
- Link the assembly to an executable:
clang yourfile.s -o yourfile