toy compiler implemented using c++ and llvm
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
git clone https://github.com/jdao55/toy-compiler && cd toy-compiler
mkdir build && cd build
cmake ../
make
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])”;
# Example
Kaleidoscope program test.toy
```python
def add(x y)
x + y
def add3(x y z)
x + y + z
Compile with toycompilertoycompiler 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/clangg++ example.cpp add.o -o example