Putting it all Together

Putting it all Together

Lets assume that the language we are compiling is called Z, and that a ZConstant and ZPseudoOps structure has been defined. Lets also assume that we are compiling for the Dec Alpha described in the previous section. This sections outlines the various steps required to put together a code generator for Z. The first step is to specialize MLRisc with respect to the constants and pseudo-ops using the MLTreeF.

  structure ZMLTree = MLTreeF(structure Constant=ZConstant
                              structure P = ZPseudoOps)
Next we need to specialize the alpha instruction set with the same set of constants used to define MLRisc trees.
  structure Alpha32Instr = Alpha32Instr(ZConstant)
Flowgraphs must also be specialized with respect to instructions and pseudo-ops.
  structure Alpha32FlowGraph = FlowGraphF(structure I = Alpha32Instr
                                          structure P = ZPseudoOps)
Lets assume that we do not care about trapping semantics, and that no registers are used during a trap, then the alpha instruction properties can be created using:
  structure Alpha32Props = Alpha32PropsF(val exnptrR = [])
Next we need to get register allocators for both integer and floating point registers, that are specialized to our instructions and flowgraph.
  structure Alpha32Ra = Alpha32RegAlloc(structure P = Alpha32Props
                                        structure I = Alpha32Instr
                                        structure F = Alpha32FlowGraph)
The module Alpha32Ra contains two partially applied functors which need to be applied to user specific properties.
  structure IntRa = Alpha32Ra.IntRa( ... user properties ...)
  structure FloatRa = Alpha32Ra.FloatRa( ... user properties ...)
We can now define our codegen function to be:
  val codegen = Alpha32Asm.emit o IntRa.ra o FloatRa.ra
This codegen function will first perform register allocation and finally emit assembly code using Alpha32Asm.emit. This codegen function must be passed to the flowgraph generation module.
  structure FlowGraphGen(structure Flowgraph = Alpha32FlowGraph
                         structure InsnProps = Alpha32Props
                         structure MLTree = ZMLTree
                         val codegen = codegen)
We can now finally instantiate the module to generate MLRisc
  structure MLTreeGen = 
     MLRiscGen(structure MLTreeComp=Alpha32(structure Flowgen=FlowGraphGen)
               structure Cells=Alpha32Cells
               structure R = ZRegs
               structure PseudoOp=ZPseudoOps)

  Submit a comment on this page  

[ INDEX | TOP | Parent | Root ]

Author: Lal George
Last Modified: September 4, 1996
Copyright © 1996 Bell Laboratories