Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/susji/opl
Toy compiler for PL/0, emits x86-64 assembly for Linux
https://github.com/susji/opl
compilers educational ocaml
Last synced: 27 days ago
JSON representation
Toy compiler for PL/0, emits x86-64 assembly for Linux
- Host: GitHub
- URL: https://github.com/susji/opl
- Owner: susji
- License: gpl-3.0
- Created: 2021-11-20T10:34:12.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-20T11:54:42.000Z (about 3 years ago)
- Last Synced: 2023-09-09T14:20:26.657Z (over 1 year ago)
- Topics: compilers, educational, ocaml
- Language: OCaml
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
$ ./testThere 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
- [x] parse `test.pl0` and generate the AST
- [x] do scope analysis for visible constants and variables
- [x] 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
- [x] constant folding for integer arithmetic
- [x] constant folding for constant conditionals
- [x] common subexpression elimination
- [ ] report AST errors with line:column info
- [ ] loop-invariant hoisting
- [ ] dead store elimination
- [x] search for calling undeclared functions
- [x] search for assigning to constants
- [x] dumb stack machine codegen
- [ ] register-allocating codegen