This is an attempt at producing x64 AT & T assembly from Wirth's original
PL/0. Some minor extensions might be supported. The code is unlikely to be of
proper ML nature, as this is really an OCaml exercise. The goal is to
successfully compile the attached test.pl0
which should be an original
example from Wirth's book.
The following assumes you have oasis
, ocaml
, and a suitable x86-64
compiler installed.
$ make
$ cat tests/test.pl0 | bin/opl -w -c
$ cc -static out.s -o test
$ ./test
There are a few other parameters, see bin/opl -help
for more.
Lots of unnecessary recursion is being done as all AST visitors operate on their own pass for simplicity. To get faster compilation, these should be combined into a single-pass traversal.
- parse
test.pl0
and generate the AST - do scope analysis for visible constants and variables
- search for referring to not-in-scope identifiers
- a common logging interface with verbosity for AST handlers
- extend AST types to store source line:column
- constant folding for integer arithmetic
- constant folding for constant conditionals
- common subexpression elimination
- report AST errors with line:column info
- loop-invariant hoisting
- dead store elimination
- search for calling undeclared functions
- search for assigning to constants
- dumb stack machine codegen
- register-allocating codegen