/cs265-bril

berkeley cs265

Primary LanguageRustMIT LicenseMIT

Bril: A Compiler Intermediate Representation for Learning

This Max's fork of the Bril repo for teaching Berkeley's CS 265. Links will likely still point to the published Bril docs. I will try to keep this compatible with the original Bril repo, so those docs should still be useful.

Bril (the Big Red Intermediate Language) is a compiler IR made for teaching Cornell's CS 6120, a grad compilers course. It is an extremely simple instruction-based IR that is meant to be extended. Its canonical representation is JSON, which makes it easy to build tools from scratch to manipulate it.

This repository contains the documentation, including the language reference document, and some infrastructure for Bril. There are some quick-start instructions below for some of the main tools, but check out the docs for more details about what's available.

Install the Tools

The install.sh script will install the tools for you. Read it first to see what it does, then run it:

$ ./install.sh

It installs the following tools (and their dependencies):

  • brili, the reference interpreter
  • brilck, the type checker
  • ts2bril, a TypeScript-to-Bril compiler
  • bril2json and bril2txt, the JSON-to-text and text-to-JSON converters
  • turnt, a snapshot-based testing tool (not specific to Bril, but used for the tests)
  • brench, the Bril benchmark runner.

Tests

There are some tests in the test/ directory. They use Turnt, which lets us write the expected output for individual commands. Install it with pip or the install.sh script:

$ pip install --user turnt

Then run all the tests by typing make test.

Write an optimizer!

Check out examples/remove_nops for a simple, complete example of how to write an optimization pass for Bril.