In this course (Compilers - NTUA) we were asked to create a compiler for a given language, llama, which is a functional programming language. The doc of this language can be found in greek here.
- Basic Data Types: integer, float, character, boolean
- Reference Types and Arrays of one or more dimensions (cannot create Ref Array, or Array of Array)
- User Defined Types (can be recursive too)
- Library Functions
- Type Inference
- Function Closures
- High Order Functions
- Structural Equality
- Optimizations
To build the llama library, lib.a was used which was created using this Library. Most of the functions that the compiler supports comes from the lib.a file. Some other functions that were not implemented were created by us with the help of llvm.
- print_int : int -> unit
- print_bool : bool -> unit
- print_char : char -> unit
- print_float : float -> unit
- print_string : array of char -> unit
- read_int : unit -> int
- read_bool : unit -> bool
- read_char : unit -> char
- read_float : unit -> float
- read_string : unit -> array of char
- abs : int -> int
- fabs : float -> float
- sqrt : float -> float
- sin : float -> float
- cos : float -> float
- tan : float -> float
- atan : float -> float
- exp : float -> float
- ln : float -> float
- pi : pi -> float
- incr : int ref -> unit
- decr : int ref -> unit
- float_of_int : int -> float
- int_of_float : float -> int
- round : float -> int
- int_of_char : char -> int
- char_of_int : int -> char
- Clone the repository
- Make sure you have nasm
./libs.sh
- We changed some synonyms using the
change_syms
file
- Flex
- Bison
- LLVM
- Clang - Used to create assembly code from ir and executable from assembly code)
- C++11
- Library - Requires nasm if you want to build the library yourself
The llama compiler executable used the following versions of the above dependencies:
- Flex - Version 2.6.4
- Bison - Version 3.5.1
- LLVM - Version 10.0.0
- Clang - Version 10.0.0-4ubuntu
- Clone the repository and move to src folder
make
to create the llama compiler executable
The compiler can be used with any of the flags (in any combination) described below:
./llama [path/to/llamafile] -h (* Prints all possible flag options *)
./llama [path/to/llamafile] -O (* Optimization Flag *)
./llama [path/to/llamafile] -ast (* Prints Abstract Syntax Tree *)
./llama [path/to/llamafile] -fv (* Prints Free Variables each Function has *)
./llama [path/to/llamafile] -i (* Prints Intermediate Code - LLVM IR *)
./llama [path/to/llamafile] -f (* Prints Assembly Code *)
./llama [path/to/llamafile] -l (* Enables __LINE__ Macro - Debugging Purposes *)
./llama [path/to/llamafile] -st (* Prints complete SymbolTable (may have duplicates, because of scopes). *)