scale.backend
Class Assembler

java.lang.Object
  |
  +--scale.backend.Assembler
Direct Known Subclasses:
AlphaAssembler, MipsAssembler, PPCAssembler, SparcAssembler

public abstract class Assembler
extends java.lang.Object

This class is the base class for classes that translate instructions into assembly language.

$Id: Assembler.java,v 1.9 2002/01/03 21:41:28 burrill Exp $

Copyright 2002 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.


Field Summary
protected  Generator gen
          The Generator used to generate the instructions.
static char[] hex
          Convert an integer from 0 to 15 to a hex digit.
protected  java.lang.String source
          The source file name.
 
Constructor Summary
Assembler(Generator gen, java.lang.String source)
          Convert the Scribble CFG to instructions.
 
Method Summary
 void assemble(Emit emit, SpaceAllocation[] dataAreas)
          Generate assembly code for the data areas.
abstract  int assembleData(Emit emit, SpaceAllocation sa, int location)
          Called for each allocation in a named area.
abstract  void assembleDataAreaHeader(Emit emit, int kind)
          Generate the assembly directives for each different kind of data area.
protected  void assembleDataBegin(Emit emit, SpaceAllocation sa, int location)
          Called when a named area is started.
protected  void assembleDataEnd(Emit emit, SpaceAllocation sa, int location)
          Called when a named area is ended.
abstract  void assembleEpilog(Emit emit)
          Called at the very end of generating assembly code.
abstract  void assembleInstruction(Instruction inst, Emit emit)
          Generate an assembly instruction
protected  void assembleInstructions(Emit emit, java.lang.String name, Instruction firstInstruction)
          Generate assembly instructions for the list of instructions.
abstract  void assembleLabel(int label, Emit emit)
          Generate a label in the assembly output.
abstract  void assembleProlog(Emit emit)
          Called at the very beginning of generating assembly code.
abstract  java.lang.String assembleRegister(int reg)
          Convert a register number into its assembly language form.
 java.lang.String getDisplayString(byte[] v, int start, int end)
          Convert a string to a form suitable for display.
abstract  java.lang.String getLabelString(int label)
          Return the String representing the label.
 java.lang.String getName(int handle)
          Return the name associated with an area handle.
 SourceLanguage getSourceLanguage()
          Return the source language of the original program.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hex

public static final char[] hex
Convert an integer from 0 to 15 to a hex digit.

gen

protected Generator gen
The Generator used to generate the instructions.
See Also:
Generator

source

protected java.lang.String source
The source file name.
Constructor Detail

Assembler

public Assembler(Generator gen,
                 java.lang.String source)
Convert the Scribble CFG to instructions.
Parameters:
gen - is the generator used to generate the instructions
source - is the source file name
Method Detail

getName

public java.lang.String getName(int handle)
Return the name associated with an area handle.

assemble

public final void assemble(Emit emit,
                           SpaceAllocation[] dataAreas)
Generate assembly code for the data areas.

assembleInstructions

protected void assembleInstructions(Emit emit,
                                    java.lang.String name,
                                    Instruction firstInstruction)
Generate assembly instructions for the list of instructions.
Parameters:
name - is the associated routine name
firstInstruction - is the head of the list of instructions

getSourceLanguage

public final SourceLanguage getSourceLanguage()
Return the source language of the original program.
Returns:
the source language of the original program.

getLabelString

public abstract java.lang.String getLabelString(int label)
Return the String representing the label.

assembleProlog

public abstract void assembleProlog(Emit emit)
Called at the very beginning of generating assembly code.

assembleEpilog

public abstract void assembleEpilog(Emit emit)
Called at the very end of generating assembly code.

assembleLabel

public abstract void assembleLabel(int label,
                                   Emit emit)
Generate a label in the assembly output.

assembleRegister

public abstract java.lang.String assembleRegister(int reg)
Convert a register number into its assembly language form.

assembleInstruction

public abstract void assembleInstruction(Instruction inst,
                                         Emit emit)
Generate an assembly instruction

assembleDataAreaHeader

public abstract void assembleDataAreaHeader(Emit emit,
                                            int kind)
Generate the assembly directives for each different kind of data area. The different kindss would be data, text, read-only data, etc. All areas of the same kind are processed together.
Parameters:
emit - is the output sink
kind - specifies the area kind

assembleDataBegin

protected void assembleDataBegin(Emit emit,
                                 SpaceAllocation sa,
                                 int location)
Called when a named area is started.
Parameters:
emit - is the output sink
sa - is the data space
location - is the current location

assembleData

public abstract int assembleData(Emit emit,
                                 SpaceAllocation sa,
                                 int location)
Called for each allocation in a named area.
Parameters:
emit - is the output sink
sa - is the data space
location - is the current location

assembleDataEnd

protected void assembleDataEnd(Emit emit,
                               SpaceAllocation sa,
                               int location)
Called when a named area is ended.
Parameters:
emit - is the output sink
sa - is the data space
location - is the current location

getDisplayString

public java.lang.String getDisplayString(byte[] v,
                                         int start,
                                         int end)
Convert a string to a form suitable for display. For example, a double quote (") is converted to "\"" and "\0" is converted to "\\0".
Parameters:
v - the original string
Returns:
the converted string