A (reduced) Pascal compiler in Haskell that compiles to LLVM
Once the executable is built, it can be used to compile Pascal source files to llvm-ir, or internal IR used by the compiler:
paskell -c src compile to llvm-ir
paskell -c src dest compile to llvm-ir and save in dest
paskell -ir src produce internal IR
paskell -x src execute pascal source. Equivalent to
paskell -c src | lli
paskell -h (for help)
The compiler is complemented with the llvm utilities
$ paskell -c fib.pas fib.ll
Since the output is llvm-ir, we can leverage the many tools LLVM provide to:
$ lli fib.ll$ llvm-as fib.ll -o fib.bc$ opt -mem2reg fib.bc$ llc -march=x86-64 fib.bc -o fib.s$ make bash
to build the compiler and launch a shell session where the compiler and llvm utitlies are in $PATH and ready out-of-the-box.
$ make build
will build the same image tagged paskell
which can be used with docker run and volumes.
For example:
$ docker run -v /path/to/original_file.pas:/path/to/file.pas paskell paskell -c /path/to/file.pas
You need to have llvm installed
$ sudo apt-get install llvm-5.0
lli should be in $PATH to be able to execute Pascal programs
Then, you can use Cabal or Stack.
To build using Cabal:
$ cd Paskell/
$ cabal install -j
this will install all dependencies and produce an executable in
dist/build/Paskell/
You can also build using Stack.
$ make test
to run the test suite using docker.
This is a 4-pass compiler:
pass 1: lex/parsing
pass 2: type checking
pass 3: constructing IR: type-annotation, type resolution, (future: identifier-renaming, nested-function extraction)
pass 4: code generation
Bug reports, added features, etc are welcome
Haskell
99.3%
A (reduced) Pascal compiler in Haskell that compiles to LLVM
Once the executable is built, it can be used to compile Pascal source files to llvm-ir, or internal IR used by the compiler:
paskell -c src compile to llvm-ir
paskell -c src dest compile to llvm-ir and save in dest
paskell -ir src produce internal IR
paskell -x src execute pascal source. Equivalent to
paskell -c src | lli
paskell -h (for help)
The compiler is complemented with the llvm utilities
$ paskell -c fib.pas fib.ll
Since the output is llvm-ir, we can leverage the many tools LLVM provide to:
$ lli fib.ll$ llvm-as fib.ll -o fib.bc$ opt -mem2reg fib.bc$ llc -march=x86-64 fib.bc -o fib.s$ make bash
to build the compiler and launch a shell session where the compiler and llvm utitlies are in $PATH and ready out-of-the-box.
$ make build
will build the same image tagged paskell
which can be used with docker run and volumes.
For example:
$ docker run -v /path/to/original_file.pas:/path/to/file.pas paskell paskell -c /path/to/file.pas
You need to have llvm installed
$ sudo apt-get install llvm-5.0
lli should be in $PATH to be able to execute Pascal programs
Then, you can use Cabal or Stack.
To build using Cabal:
$ cd Paskell/
$ cabal install -j
this will install all dependencies and produce an executable in
dist/build/Paskell/
You can also build using Stack.
$ make test
to run the test suite using docker.
This is a 4-pass compiler:
pass 1: lex/parsing
pass 2: type checking
pass 3: constructing IR: type-annotation, type resolution, (future: identifier-renaming, nested-function extraction)
pass 4: code generation
Bug reports, added features, etc are welcome
Haskell
99.3%