Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anhnguyen1618/tiger-ocaml-llvm-compiler
A minimal compiler written in OCaml that compiles Tiger to LLVM IR then to assembly code
https://github.com/anhnguyen1618/tiger-ocaml-llvm-compiler
llvm-ir ocaml tiger-compiler
Last synced: about 1 month ago
JSON representation
A minimal compiler written in OCaml that compiles Tiger to LLVM IR then to assembly code
- Host: GitHub
- URL: https://github.com/anhnguyen1618/tiger-ocaml-llvm-compiler
- Owner: anhnguyen1618
- Created: 2018-12-26T18:15:28.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-08-01T07:16:54.000Z (over 2 years ago)
- Last Synced: 2023-03-06T21:21:55.587Z (almost 2 years ago)
- Topics: llvm-ir, ocaml, tiger-compiler
- Language: LLVM
- Homepage:
- Size: 21.7 MB
- Stars: 17
- Watchers: 0
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LLVM Compiler for Tiger programming language
[![Build Status](https://travis-ci.org/anhnguyen300795/Tiger-ocaml-llvm-compiler.svg?branch=master)](https://travis-ci.org/anhnguyen300795/Tiger-ocaml-llvm-compiler)
A minimal compiler written in OCaml that compiles Tiger to LLVM IR and subsequently to target-dependent assembly code
### Tiger programming language
[Link to manual](https://www.lrde.epita.fr/~tiger/tiger.html)Sample Tiger code:
```ocaml module
let
function fib (n: int): int =
if n = 0 then 0
else if n = 1 then 1
else fib(n-1) + fib(n-2)type node = {data: my_int, next: node}
type my_int = int
var a := node {data = 3, next = nil}
var b := node {data = 2, next = a}type intFun = int -> int
type intIntFun = int -> intFun
var f := (a: int): intIntFun =>
(b: int): intFun =>
(c: int): int => a + b + c
in
assert_int(fib (0), 0);
assert_int(fib (30), 832040);
assert_int(b.next.data, 3);
assert_int(f(1)(2)(3), 6)
end
```### Technologies
* [OCaml](https://www.docker.com/): OCaml programming language
* [OCamllex](https://caml.inria.fr/pub/docs/manual-ocaml/lexyacc.html): Lexer
* [Menhir](http://cristal.inria.fr/~fpottier/menhir/): LR(1) parser
* [LLVM](http://llvm.org/): LLVM compiler framework
* [Clang](https://clang.llvm.org/): C compiler
* [Travis](https://travis-ci.com/): CI-testing### Required software
* llvm-6.0-dev
* opam-1.2.2
* ocaml-4.05.0
* python-2.7
* ocamlbuild
* ocamlfind
* llvm (opam package)See ```.travis.yml``` for more details
### Usage
After cloning this repo, please create new output directory ```/llvm_byte_code/test/``` with the command:
```node module
mkdir llvm_byte_code/test
```Tiger test file ```.tig``` must be placed directly under directory ```./test```
Compile file ```test/.tig``` without executing the output binary run_prog:
```node module
make parse -f=.tig
```
This command generates the binary executable file ```run_prog``` in the current directory. This file can be executed with the command:
```node module
./run_prog
```To compile and run test on Tiger file ```test/.tig``` in one command:
```node module
python test.py -s
```Compile and run all Tiger test files in directory ```./test```:
```node module
python test.py
```
or
```node module
./compile
```The **LLVM IR** results and **assembly** code emitted by compiling file ```test/.tig``` can be found in directory ```/llvm_byte_code/test/```:
```
* .tig.ll # LLVM IR code
* .tig-opt.ll # Optimized IR codes
* .tig-opt.s # Assembly code
```