Version 9 (modified by kjs, 12 years ago)

add link to register allocator paper that i based the reg alloc on

PIRC Introduction

PIRC is a fresh implementation of the PIR language. It is being developed as a replacement for the current PIR compiler, IMCC. Somewhere in the future, we all hope to be able to finish it. However, some help is needed. Most of the tricky parts have been done for you, such as implement all sorts of weird features of the PIR language.

The basic workflow of PIRC is as follows. The lexer and parser are implemented with Flex and Bison specifications. During the parsing phase, a data structure is built that represents the input. To stick with compiler jargon, let's call this the Abstract Syntax Tree (AST). After the parse, this AST is traversed and for each instruction the appropriate bytecode is emitted. Registers are allocated by the built-in vanilla register allocator. This means that for the following code:

.sub main
  $S12 = "Hi there"
  print $S12
  $I44 = 42
  print $I44
.end

$S12 and $I44 will be mapped to the registers S0 and I0 respectively (yes, you guessed it, it starts allocating from 0). As you would expect, the vanilla register allocator is pretty stupid, but the generated bytecode is not too bad, really. If you want to optimize the register usage (which saves runtime memory), you can activate the register optimizer. The register optimizer is based on a Linear Scan Register allocator. The original algorithm, as described in  this paper, assumes a fixed number of available registers. Since Parrot has a variable number of registers available per subroutine, the algorithm has been changed here and there.

Building and running PIRC

PIRC is located in compilers/pirc. In order to compile, do the following:

cd compilers/pirc
make
make test

At this point (August 5, 2009) some tests are failing, so don't be alarmed if you see them failing.

In order to run PIRC:

./pirc -h
./pirc -b test.pir # will generate a file a.pbc

Enjoy!

PIRC Status

PIRC is not complete yet. All stages are implemented (lexer, parser, bytecode generator), but all of them need some additional work to complete them. See the section below for the specific items that need to be fixed. Once these are fixed, PIRC will be done about 98%.

PIRC Development Tasks

Shouldn't-be-too-hard tasks

  • ticket #43: autoheaderize all PIRC sources.
  • ticekt #55: decorate all function arguments with ARGIN macros etc.
  • write tests for the generated output.

Hardcore hacking tasks

  • Fix parser to accept syntax such as:
    $P0 = new ['Integer']
    
  • Convert all C strings in PIRC into STRINGs. All identifiers and strings that are scanned should be stored as STRING objects, not C strings.
  • Fix ticket #198. It seems that when there is a sequence of more than one instruction dealing with STRINGs or NUMs, the resulting bytecode segfaults. Apparently, PIRC is emitting the wrong bytecode. Bug #186 is related to this issue.
  • Fix ticket #173. Lexicals are not stored correctly in the generated bytecode. The code for storing the lexicals is taken from IMCC, and therefore it doesn't come as a complete surprise it's not working. However, I don't see what's wrong.
  • Fix ticket #14. Braced arguments to macros are not handled correctly. Nested macro expansion isn't correctly handled yet.
  • Fix ticket #163. Keyed multi types must be implemented