A toy (Kaleidoscope) compiler based on llvm's guide https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/index.html, currently compiles to object files, which can be linked using clang/gcc
- cmake
- C++ 20 compiler
- conan
- Flex
- llvm
- Clone dirrectory
git clone https://github.com/jdao55/toy-compiler && cd toy-compiler
- Create build directory
mkdir build && cd build
- Run cmake
cmake ../
- Build using make
make
Usage:
toycomp <filename> [--out=filename] [--opt=level]
toycomp (-h | --help)
Options:
-h --help Show this screen.
-o filname --out=filename Specify output object file name
-O level --opt=level Specify optimization level [1,2,3])";
Kaleidoscope program test.toy
def add(x y)
x + y
def add3(x y z)
x + y + z
Compile with toycompiler
toycompiler test.toy -out=add.o
sample c++ program example.cpp
#include <iostream>
extern "C" {
double add(double, double);
double add3(double, double, double);
}
int main()
{
std::cout << add(1.2, 2.3) << std::endl;
std::cout << add3(1.0, 2.0, 3.0) << std::endl;
}
Compile and link using gcc/clang
g++ example.cpp add.o -o example
- arrays
- data types (WIP see types-ext branch)
- integers
- strings
- main function
- add optimization passes (WIP see optimzer branch)
- add compilation targets
- refactor main?