scale.backend.x86
Class X86Assembler

java.lang.Object
  extended by scale.backend.Assembler
      extended by scale.backend.x86.X86Assembler

public final class X86Assembler
extends Assembler

This class generates X86 assembly language from a list of X86 instructions.

$Id: X86Assembler.java,v 1.1 2007-11-01 16:52:29 burrill Exp $

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

This class generates the assembly language for this architecture from the instructions for this architecture. Most of the methods below generate a "not implemented error". These must be replaced with code that generates the proper assemblylanguage sequence. The other methods may need to be modified. Use the assembler classes from the other architectures to help you understand how to make changes for your architecture.

See Also:
Assembler, AlphaAssembler, SparcAssembler, PPCAssembler

Field Summary
 
Fields inherited from class scale.backend.Assembler
gen, hex, oneItemPerLine, repsAllowedInAL, source
 
Constructor Summary
X86Assembler(Generator gen, java.lang.String source, boolean instructionScheduling)
           
 
Method Summary
 void assembleComment(java.lang.String comment, Emit emit)
          Insert the assembler representation of the comment into the output stream.
 long assembleData(Emit emit, SpaceAllocation sa, long location)
          Called for each allocation in a named area.
 void assembleDataAreaHeader(Emit emit, int kind)
          Generate the assembly directives for each different kind of data area.
 void assembleEpilog(Emit emit)
          Called at the very end of generating assembly code.
 void assembleLabel(Label label, Emit emit)
          Generate a label in the assembly output.
 void assembleProlog(Emit emit)
          Called at the very beginning of generating assembly code.
 java.lang.String assembleRegister(int reg)
          Convert a register number into its assembly language form.
 void buildAddress(Emit emit, int baseReg, int indexReg, Displacement disp, int scale)
           
 void buildAddress(java.lang.StringBuffer buf, int baseReg, int indexReg, Displacement disp, int scale)
           
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, Label lab, int reps, boolean aligned)
          Generate the data representation for address of the label.
protected  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  int getDirectiveSize(int dt)
          Return the number of addressable units required for one value of the specified type.
 java.lang.String getLabelString(Label label)
          Return the String representing the label.
 
Methods inherited from class scale.backend.Assembler
assemble, assembleDataBegin, assembleDataEnd, assembleInstructions, genData, genData, genData, genData, genData, genData, genData, genData, genData, genData, getDisplayString, getName, getSourceLanguage, getSpaceAllocation, isFortran
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

X86Assembler

public X86Assembler(Generator gen,
                    java.lang.String source,
                    boolean instructionScheduling)
Parameters:
gen - is the instruction generator used to generate the instructions.
source - specifies the source program
Method Detail

assembleProlog

public void assembleProlog(Emit emit)
Description copied from class: Assembler
Called at the very beginning of generating assembly code.

Specified by:
assembleProlog in class Assembler

assembleEpilog

public void assembleEpilog(Emit emit)
Description copied from class: Assembler
Called at the very end of generating assembly code.

Specified by:
assembleEpilog in class Assembler

getLabelString

public java.lang.String getLabelString(Label label)
Description copied from class: Assembler
Return the String representing the label.

Specified by:
getLabelString in class Assembler

assembleLabel

public void assembleLabel(Label label,
                          Emit emit)
Description copied from class: Assembler
Generate a label in the assembly output.

Specified by:
assembleLabel in class Assembler

assembleComment

public void assembleComment(java.lang.String comment,
                            Emit emit)
Description copied from class: Assembler
Insert the assembler representation of the comment into the output stream.

Specified by:
assembleComment in class Assembler

assembleRegister

public java.lang.String assembleRegister(int reg)
Description copied from class: Assembler
Convert a register number into its assembly language form.

Specified by:
assembleRegister in class Assembler

assembleDataAreaHeader

public void assembleDataAreaHeader(Emit emit,
                                   int kind)
Description copied from class: Assembler
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.

Specified by:
assembleDataAreaHeader in class Assembler
Parameters:
emit - is the output sink
kind - specifies the area kind

genDirective

protected void genDirective(Emit emit,
                            int dt)
Description copied from class: Assembler
Generate the assembly directive required for the type.

Specified by:
genDirective in class Assembler
Parameters:
emit - specifies where to put the directive.
dt - - the data type
See Also:
SpaceAllocation

getDirectiveSize

protected int getDirectiveSize(int dt)
Description copied from class: Assembler
Return the number of addressable units required for one value of the specified type.

Specified by:
getDirectiveSize in class Assembler
Parameters:
dt - - the data type
See Also:
SpaceAllocation

genZeroFill

protected void genZeroFill(Emit emit,
                           long size)
Description copied from class: Assembler
Generate the assembly directive required to generate a zero-filled area.

Overrides:
genZeroFill in class Assembler
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)
Description copied from class: Assembler
Generate the assembly directive required to generate an ASCII text string.

Overrides:
genAsciiText in class Assembler
Parameters:
emit - specifies where to put the directive.
str - is the string

genBytes

protected void genBytes(Emit emit,
                        int numBytes,
                        long data,
                        int reps)
Description copied from class: Assembler
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.

Overrides:
genBytes in class Assembler
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

genData

protected long genData(Emit emit,
                       int dt,
                       Label lab,
                       int reps,
                       boolean aligned)
Description copied from class: Assembler
Generate the data representation for address of the label.

Specified by:
genData in class Assembler
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

assembleData

public long assembleData(Emit emit,
                         SpaceAllocation sa,
                         long location)
Description copied from class: Assembler
Called for each allocation in a named area.

Specified by:
assembleData in class Assembler
Parameters:
emit - is the output sink
sa - is the data space
location - is the current location

buildAddress

public void buildAddress(Emit emit,
                         int baseReg,
                         int indexReg,
                         Displacement disp,
                         int scale)

buildAddress

public void buildAddress(java.lang.StringBuffer buf,
                         int baseReg,
                         int indexReg,
                         Displacement disp,
                         int scale)