Skip to content

Toy Programming language & optimizing JIT Compiler built with LLVM compiler infrastructure and C++

Notifications You must be signed in to change notification settings

OmarAzizi/Kaleidoscope

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Kaleidoscope 🔭

C++

This is a toy programming language and its compiler made with LLVM and C++. I have implemented all of the frontend components the language needs:

  • Lexing
  • Abstract Syntax Tree (AST)
  • Parsing

Along with the code the generation to generate the LLVM IR (LLVM Intermediate Representation). Also I added a JIT Driver so I can see the IR generated, and the evaluated results.

And Finally I Added additional Optimizers to the compiler such as:

Optimization Example

Before adding optimization

This screenshot shows the corresponding LLVM IR for the function I defined, the function basically computes $(x + 3)^2$, but notice in the IR that the compiler instead of calculating $(x + 3)$ once then squaring the result, what it actually does is computing it twice, the first time it stores it in addtmp and the other in addtmp1:

Screenshot from 2024-02-10 23-47-22

After adding optimization

This screenshot shows the IR for the same function definition from earlier after I added the Common Subexpression Elimination optimization:

Screenshot from 2024-02-11 00-18-45

Note

This is just something I made to teach myself more about compilers in general and the LLVM compiler infrastructure in particular, so I didn't follow software engineering best practices and its not production ready.

About

Toy Programming language & optimizing JIT Compiler built with LLVM compiler infrastructure and C++

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published