scale.backend
Class Assembler

java.lang.Object
  extended by scale.backend.Assembler
Direct Known Subclasses:
AlphaAssembler, MipsAssembler, PPCAssembler, SparcAssembler, Trips2Assembler, X86Assembler, XyzAssembler

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.50 2007-10-04 19:57:48 burrill Exp $

Copyright 2008 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.
static boolean oneItemPerLine
          Specifies whether or not individual data items should be output with their own assembly statement.
protected  boolean repsAllowedInAL
          Set true if the assembly language allows repititions to be specified by a ':' and a repitition count.
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.
protected abstract  void assembleComment(java.lang.String comment, Emit emit)
          Insert the assembler representation of the comment into the output stream.
abstract  long assembleData(Emit emit, SpaceAllocation sa, long location)
          Called for each allocation in a named area.
protected abstract  void assembleDataAreaHeader(Emit emit, int kind)
          Generate the assembly directives for each different kind of data area.
 void assembleDataBegin(Emit emit, SpaceAllocation sa, long location)
          Called when a named area is started.
 void assembleDataEnd(Emit emit, SpaceAllocation sa, long location)
          Called when a named area is ended.
protected abstract  void assembleEpilog(Emit emit)
          Called at the very end of generating assembly code.
 void assembleInstructions(Emit emit, java.lang.String name, Instruction firstInstruction)
          Generate assembly instructions for the list of instructions.
abstract  void assembleLabel(Label label, Emit emit)
          Generate a label in the assembly output.
protected 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.
protected  void genAsciiText(Emit emit, java.lang.String str)
          Generate the assembly directive required to generate an ASCII text string.
protected  void genBytes(Emit emit, int numBytes, long data, int reps)
          Output an integer data item as a string of bytes.
protected  long genData(Emit emit, int dt, AddressLiteral lit, int reps, boolean aligned)
          Generate the assembly representation of an address.
protected  long genData(Emit emit, int dt, byte[] data, int reps, boolean aligned)
          Generate the assembly representation of an array of byte values.
protected  long genData(Emit emit, int dt, Declaration decl, int reps, boolean aligned)
          Generate the assembly representation of a Declaration.
protected  long genData(Emit emit, int dt, double[] data, int reps, boolean aligned)
          Generate the assembly representation of an array of double values.
protected  long genData(Emit emit, int dt, double data, int reps, boolean aligned)
          Generate the assembly representation of double floating point value.
protected  long genData(Emit emit, int dt, Label[] labels, int reps, boolean aligned)
          Generate the assembly representation of an array of label addresses.
protected abstract  long genData(Emit emit, int dt, Label lab, int reps, boolean aligned)
          Generate the data representation for address of the label.
protected  long genData(Emit emit, int dt, long[] data, int reps, boolean aligned)
          Generate the assembly representation of an array of long values.
protected  long genData(Emit emit, int dt, long data, int reps, boolean aligned)
          Generate the assembly representation of long integer value.
protected  long genData(Emit emit, int dt, java.lang.Object value, int reps, boolean aligned)
          Generate the assembly representation of the specified data value.
protected  long genData(Emit emit, int dt, java.lang.String value, int reps, boolean aligned)
          Generate the data representation for the string.
protected abstract  void genDirective(Emit emit, int dt)
          Generate the assembly directive required for the type.
protected  void genZeroFill(Emit emit, long size)
          Generate the assembly directive required to generate a zero-filled area.
protected abstract  int getDirectiveSize(int dt)
          Return the number of addressable units required for one value of the specified type.
 java.lang.String getDisplayString(char[] v, int start, int end)
          Convert a string to a form suitable for display.
abstract  java.lang.String getLabelString(Label 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.
 SpaceAllocation getSpaceAllocation(int handle)
          Return the SpaceAllocation associated with the specified handle.
 boolean isFortran()
          Return true if the source language is Fortran.
 
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.


oneItemPerLine

public static boolean oneItemPerLine
Specifies whether or not individual data items should be output with their own assembly statement. Otherwise, several will share the same assembly statement. For example,
  .long 1, 2, 3
 
or
  .long 1
  .long 2
  .long 3
 


gen

protected Generator gen
The Generator used to generate the instructions.

See Also:
Generator

source

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


repsAllowedInAL

protected boolean repsAllowedInAL
Set true if the assembly language allows repititions to be specified by a ':' and a repitition count.

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 final java.lang.String getName(int handle)
Return the name associated with an area handle.


getSpaceAllocation

public final SpaceAllocation getSpaceAllocation(int handle)
Return the SpaceAllocation associated with the specified handle.


assemble

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


assembleInstructions

public 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.

isFortran

public final boolean isFortran()
Return true if the source language is Fortran.


getLabelString

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


assembleProlog

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


assembleEpilog

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


assembleLabel

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


assembleComment

protected abstract void assembleComment(java.lang.String comment,
                                        Emit emit)
Insert the assembler representation of the comment into the output stream.


assembleRegister

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


genDirective

protected abstract void genDirective(Emit emit,
                                     int dt)
Generate the assembly directive required for the type.

Parameters:
emit - specifies where to put the directive.
dt - - the data type
See Also:
SpaceAllocation

getDirectiveSize

protected abstract int getDirectiveSize(int dt)
Return the number of addressable units required for one value of the specified type.

Parameters:
dt - - the data type
See Also:
SpaceAllocation

genZeroFill

protected void genZeroFill(Emit emit,
                           long size)
Generate the assembly directive required to generate a zero-filled area.

Parameters:
emit - specifies where to put the directive.
size - is the number of bytes of zeros required
See Also:
SpaceAllocation

genAsciiText

protected void genAsciiText(Emit emit,
                            java.lang.String str)
Generate the assembly directive required to generate an ASCII text string.

Parameters:
emit - specifies where to put the directive.
str - is the string

assembleDataAreaHeader

protected 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

public void assembleDataBegin(Emit emit,
                              SpaceAllocation sa,
                              long 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 long assembleData(Emit emit,
                                  SpaceAllocation sa,
                                  long 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

public void assembleDataEnd(Emit emit,
                            SpaceAllocation sa,
                            long location)
Called when a named area is ended.

Parameters:
emit - is the output sink
sa - is the data space
location - is the current location

genData

protected long genData(Emit emit,
                       int dt,
                       java.lang.Object value,
                       int reps,
                       boolean aligned)
Generate the assembly representation of the specified data value.

Parameters:
emit - specifies where to generate the data
dt - specifies the data type
value - is the data
reps - specifies how many times to generate the representation
aligned - specifies whether the data will be aligned
Returns:
the number of bytes generated
See Also:
SpaceAllocation

genData

protected long genData(Emit emit,
                       int dt,
                       Label[] labels,
                       int reps,
                       boolean aligned)
Generate the assembly representation of an array of label addresses.

Parameters:
emit - specifies where to generate the data
dt - specifies the data type
labels - is the array of labels
reps - specifies how many times to generate the representation
aligned - specifies whether the data will be aligned
Returns:
the number of bytes generated
See Also:
SpaceAllocation

genData

protected long genData(Emit emit,
                       int dt,
                       Declaration decl,
                       int reps,
                       boolean aligned)
Generate the assembly representation of a Declaration.

Parameters:
emit - specifies where to generate the data
dt - specifies the data type
decl - is the Declaration
reps - specifies how many times to generate the representation
aligned - specifies whether the data will be aligned
Returns:
the number of bytes generated
See Also:
SpaceAllocation

genData

protected long genData(Emit emit,
                       int dt,
                       AddressLiteral lit,
                       int reps,
                       boolean aligned)
Generate the assembly representation of an address.

Parameters:
emit - specifies where to generate the data
dt - specifies the data type
lit - specifies the address
reps - specifies how many times to generate the representation
aligned - specifies whether the data will be aligned
Returns:
the number of bytes generated
See Also:
SpaceAllocation

genData

protected long genData(Emit emit,
                       int dt,
                       long data,
                       int reps,
                       boolean aligned)
Generate the assembly representation of long integer value.

Parameters:
emit - specifies where to generate the data
dt - specifies the data type
data - specifies the value
reps - specifies how many times to generate the representation
aligned - specifies whether the data will be aligned
Returns:
the number of bytes generated
See Also:
SpaceAllocation

genData

protected long genData(Emit emit,
                       int dt,
                       double data,
                       int reps,
                       boolean aligned)
Generate the assembly representation of double floating point value.

Parameters:
emit - specifies where to generate the data
dt - specifies the data type
data - specifies the value
reps - specifies how many times to generate the representation
aligned - specifies whether the data will be aligned
Returns:
the number of bytes generated
See Also:
SpaceAllocation

genData

protected long genData(Emit emit,
                       int dt,
                       byte[] data,
                       int reps,
                       boolean aligned)
Generate the assembly representation of an array of byte values.

Parameters:
emit - specifies where to generate the data
dt - specifies the data type
data - specifies the values
reps - specifies how many times to generate the representation
aligned - specifies whether the data will be aligned
Returns:
the number of bytes generated
See Also:
SpaceAllocation

genData

protected long genData(Emit emit,
                       int dt,
                       long[] data,
                       int reps,
                       boolean aligned)
Generate the assembly representation of an array of long values.

Parameters:
emit - specifies where to generate the data
dt - specifies the data type
data - specifies the values
reps - specifies how many times to generate the representation
aligned - specifies whether the data will be aligned
Returns:
the number of bytes generated
See Also:
SpaceAllocation

genData

protected long genData(Emit emit,
                       int dt,
                       double[] data,
                       int reps,
                       boolean aligned)
Generate the assembly representation of an array of double values.

Parameters:
emit - specifies where to generate the data
dt - specifies the data type
data - specifies the values
reps - specifies how many times to generate the representation
aligned - specifies whether the data will be aligned
Returns:
the number of bytes generated
See Also:
SpaceAllocation

genData

protected abstract long genData(Emit emit,
                                int dt,
                                Label lab,
                                int reps,
                                boolean aligned)
Generate the data representation for address of the label.

Parameters:
emit - specifies where to generate the data
dt - specifies the data type
lab - is the label
reps - specifies how many times to generate the representation
aligned - specifies whether the data will be aligned
Returns:
the number of bytes generated
See Also:
SpaceAllocation

genData

protected long genData(Emit emit,
                       int dt,
                       java.lang.String value,
                       int reps,
                       boolean aligned)
Generate the data representation for the string.

Parameters:
emit - specifies where to generate the data
dt - specifies the data type
value - is the string
reps - specifies how many times to generate the representation
aligned - specifies whether the data will be aligned
Returns:
the number of bytes generated
See Also:
SpaceAllocation

genBytes

protected void genBytes(Emit emit,
                        int numBytes,
                        long data,
                        int reps)
Output an integer data item as a string of bytes. This method is used when the data is not on the correct boundary for a normal assembly language directive.

Parameters:
emit - specifies where to generate the data
numBytes - is the number of bytes of data
data - is the data to be output
reps - is the number of times to repeat the data

getDisplayString

public java.lang.String getDisplayString(char[] 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 "\\000".

Parameters:
v - the original string
Returns:
the converted string