|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectdspl.backend.AssemblyfileGenerator
public class AssemblyfileGenerator
Utility used to actually write the provided assembly file and instructions
| Field Summary | |
|---|---|
private int |
nextBranchLabelNum
Used to generate unique labels for branching/control flow. |
private int |
nextStringID
Used to generate labels for string constants |
private java.util.HashMap |
stringLabelsHashMap
|
private java.io.PrintWriter |
writer
PrintWriter responsible for writing instructions directly to the asm file |
private boolean |
writeStdOut
If true, all data written to asm file will also be written to std out |
| Constructor Summary | |
|---|---|
AssemblyfileGenerator(java.lang.String outputFilename,
boolean writeStdOut)
Create an AssemblyfileGenerator to write a basic assembly program to the target file |
|
| Method Summary | |
|---|---|
void |
closeFile()
Called after the program is done writing instructions to the generator. |
java.lang.String |
getBranchLabel()
Returns a unique branch label to be used for branch instructions |
java.lang.String |
getStringLabel(Variable stringVar)
Returns the label used to refer to a particular String that should've been added to the data section of the ASM file |
private void |
outputILine(java.lang.String line)
Output tabbed (indented) line |
private void |
outputLine(java.lang.String line)
Output line |
void |
writeAsmInstr(java.lang.String op,
java.lang.String arg)
Writes one operand ASM instruction |
void |
writeAsmInstr(java.lang.String op,
java.lang.String src,
java.lang.String dest)
Writes a standard two operand ASM instruction |
private void |
writeBSSSection(java.util.ArrayList variables)
Writes the BSS section, which includes all variables that are not explicitly defined before hand. |
private void |
writeDataSection(java.util.ArrayList variables)
Generate the data section for the program based on its variables. |
void |
writeLabel(java.lang.String label)
Writes an ASM label Example: "L10:" |
void |
writeSkeletonASM(java.util.ArrayList variables)
Generates the initial Assembly file given it's variables Should be called before all other write commands are called on it |
void |
writeStdEntrySeq()
Writes standard entry sequence for a function according to Intel ABI Note: does not handle allocating additional space on the stack for local variables |
void |
writeStdOutputSeq()
Writes standard exit sequence for a function |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private int nextBranchLabelNum
private int nextStringID
private java.io.PrintWriter writer
private boolean writeStdOut
private java.util.HashMap stringLabelsHashMap
| Constructor Detail |
|---|
public AssemblyfileGenerator(java.lang.String outputFilename,
boolean writeStdOut)
throws java.io.FileNotFoundException
outputFilename: - name of ASM file to write towriteStdOut - if true, all data written to the file will also be printed to standard out
FileNotFoundException: - thrown when file cannot be opened
java.io.FileNotFoundException| Method Detail |
|---|
public void closeFile()
public java.lang.String getBranchLabel()
private void outputLine(java.lang.String line)
line: - line to write to fileprivate void outputILine(java.lang.String line)
line: - line to write to file, prepended by tabpublic java.lang.String getStringLabel(Variable stringVar)
stringVar -
public void writeSkeletonASM(java.util.ArrayList variables)
variables - private void writeDataSection(java.util.ArrayList variables)
All atomic elements and initially declared variables go in the symbol table.
The only elements that do not are arrays whose defintion is unknown ("i.e.: int_array iA[5];"), which should instead be put in the .bss section
variables - private void writeBSSSection(java.util.ArrayList variables)
BSS declared variables differ from those in the Data segment in that variables created in the BSS section to not allocate space within the actual executable, unlike in the Data section where allocating a 1000 element array would actually make the final executable 1000 * sizeof(array element) bigger
variables - public void writeStdEntrySeq()
public void writeStdOutputSeq()
public void writeAsmInstr(java.lang.String op,
java.lang.String src,
java.lang.String dest)
public void writeAsmInstr(java.lang.String op,
java.lang.String arg)
op - arg - public void writeLabel(java.lang.String label)
label -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||