public abstract class ILOCGenerator extends DefaultASTVisitor
BuildSymbolTables
and AllocateSymbols
Constructor and Description |
---|
ILOCGenerator() |
Modifier and Type | Method and Description |
---|---|
void |
addComment(ASTNode node,
String text)
Add a comment to the most recently-emitted ILOC instruction.
|
ILOCOperand |
base(ASTNode dest,
Symbol variable)
Fills a register with the base address of a variable.
|
void |
copyCode(ASTNode dest,
ASTNode src)
Copy the ILOC code from one AST node into another.
|
void |
emit(ASTNode node,
ILOCInstruction.Form form)
Generate a new ILOC instruction and add it to the code for an AST node.
|
void |
emit(ASTNode node,
ILOCInstruction.Form form,
ILOCOperand op)
Generate a new ILOC instruction and add it to the code for an AST node.
|
void |
emit(ASTNode node,
ILOCInstruction.Form form,
ILOCOperand op1,
ILOCOperand op2)
Generate a new ILOC instruction and add it to the code for an AST node.
|
void |
emit(ASTNode node,
ILOCInstruction.Form form,
ILOCOperand op1,
ILOCOperand op2,
ILOCOperand op3)
Generate a new ILOC instruction and add it to the code for an AST node.
|
void |
emit(ASTNode node,
ILOCInstruction insn)
Generate a new ILOC instruction and add it to the code for an AST node.
|
ILOCOperand |
emitLoad(ASTLocation dest)
Emits a right-hand-side load for a given location.
|
void |
emitStore(ASTAssignment dest,
ILOCOperand srcReg)
Emits a store for a given assignment.
|
List<ILOCInstruction> |
getCode(ASTNode node)
Returns the ILOC code associated with an AST node (via the "code"
attribute).
|
ILOCProgram |
getProgram()
Returns the generated ILOC program.
|
ILOCOperand |
getTempReg(ASTNode node)
Returns the temporary ILOC virtual register associated with the result of
evaluating a node in the AST.
|
ILOCOperand |
indexedOffset(ASTNode dest,
Symbol variable,
ILOCOperand indexReg)
Calculates the offset of an indexed variable reference and returns the
adjusted offset in an
ILOCOperand . |
ILOCOperand |
offset(Symbol variable)
Calculates the offset of a scalar variable reference and returns the
adjusted offset in an
ILOCOperand . |
void |
postVisit(ASTProgram node)
Finalize ILOC program.
|
void |
setTempReg(ASTNode node,
ILOCOperand reg)
Sets the temporary ILOC virtual register associated with the result of
evaluating a node in the AST.
|
defaultInVisit, defaultPostVisit, defaultPreVisit, inVisit, postVisit, postVisit, postVisit, postVisit, postVisit, postVisit, postVisit, postVisit, postVisit, postVisit, postVisit, postVisit, postVisit, postVisit, postVisit, preVisit, preVisit, preVisit, preVisit, preVisit, preVisit, preVisit, preVisit, preVisit, preVisit, preVisit, preVisit, preVisit, preVisit, preVisit, preVisit
public ILOCProgram getProgram()
public void postVisit(ASTProgram node)
ILOCFunction
objects with info from the AST, including
the sizes of the function stack frames and the generated instructions.postVisit
in interface ASTVisitor
postVisit
in class DefaultASTVisitor
public List<ILOCInstruction> getCode(ASTNode node)
node
- AST nodepublic void emit(ASTNode node, ILOCInstruction insn)
node
- Destination AST nodeinsn
- ILOC instruction to addpublic void emit(ASTNode node, ILOCInstruction.Form form)
node
- Destination AST nodeform
- ILOC instruction form (icode) to addpublic void emit(ASTNode node, ILOCInstruction.Form form, ILOCOperand op)
node
- Destination AST nodeform
- ILOC instruction form (icode) to addop
- ILOC instruction operandpublic void emit(ASTNode node, ILOCInstruction.Form form, ILOCOperand op1, ILOCOperand op2)
node
- Destination AST nodeform
- ILOC instruction form (icode) to addop1
- First ILOC instruction operandop2
- Second ILOC instruction operandpublic void emit(ASTNode node, ILOCInstruction.Form form, ILOCOperand op1, ILOCOperand op2, ILOCOperand op3)
node
- Destination AST nodeform
- ILOC instruction form (icode) to addop1
- First ILOC instruction operandop2
- Second ILOC instruction operandop3
- Third ILOC instruction operandpublic void copyCode(ASTNode dest, ASTNode src)
dest
- Destination AST nodesrc
- Source AST nodepublic void setTempReg(ASTNode node, ILOCOperand reg)
node
- AST nodereg
- ILOC virtual temporary registerpublic ILOCOperand getTempReg(ASTNode node)
node
- AST nodepublic ILOCOperand base(ASTNode dest, Symbol variable)
dest
- Destination AST Nodevariable
- Desired variablepublic ILOCOperand offset(Symbol variable)
ILOCOperand
.variable
- Desired variablepublic ILOCOperand indexedOffset(ASTNode dest, Symbol variable, ILOCOperand indexReg)
ILOCOperand
.dest
- Destination AST Nodevariable
- Desired variableindexReg
- Register with the evaluated indexpublic ILOCOperand emitLoad(ASTLocation dest)
dest
- Destination AST nodepublic void emitStore(ASTAssignment dest, ILOCOperand srcReg)
dest
- Destination AST nodesrcReg
- Source registerCopyright © 2019. All rights reserved.