susji / opl

Toy compiler for PL/0, emits x86-64 assembly for Linux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

opl

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.

usage

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.

Bits and pieces

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.

TODO

  • 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

About

Toy compiler for PL/0, emits x86-64 assembly for Linux

License:GNU General Public License v3.0


Languages

Language:OCaml 99.2%Language:Makefile 0.8%