An LLVM enabled compiler written in C
The name is inspired from Euler's totient function which is also called Euler's phi function.
Watch my devlogs on YouTube here!
func get_name(): string => "phi";
// it would be cool if I could remove the : int and just infer the return type
func add_five(a: int): int => a + 5;
func main() {
string name = get_name();
int result = add_five(5);
print(name);
print(result);
}
You will need llvm installed along with coreutils on MacOS.
I forget how to install llvm correctly, it may just be brew install llvm
CoreUtils is brew install coreutils
The project uses a Makefile to build and test the compiler. Here are the available commands:
makeormake all- Builds the main compiler executable (bin/mycompiler)make bin/mycompiler- Explicitly builds the main compiler
To compile a single .phi file with the main compiler:
make # First build the compiler
./bin/mycompiler input.phimake test-all- Builds all test executables (lexer, parser, etc.)make test-lexer- Builds the lexer test executable and runs all lexer testsmake test-parser- Builds the parser test executable and runs all parser testsmake bin/test-lexer- Only builds the lexer test executable (without running tests)make bin/test-parser- Only builds the parser test executable (without running tests)
To test the lexer or parser on a specific file:
make test-lexer # Build and run all lexer tests
./bin/test-lexer input.phi # Run lexer on a single filemake clean- Removes all compiled objects, binaries, and test output filesmake clean-tests- Only removes test output files (.outand.difffiles)
The test system works by:
- Running your compiler component on
.phifiles intest-cases/ - Comparing the output with expected results in
.ansfiles - Showing differences in
.difffiles if tests fail
Test files are organized in subdirectories like test-cases/lexer/ and test-cases/parser/.