|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectat.dms.kjc.sir.lowering.ThreeAddressCode
public class ThreeAddressCode
Turn statements into three-address code optionally depending on overridable simpleExpression
and shouldConvertExpression methods.
Allowing the user to override shouldConvertExpression forces this class to be non-static.
Notes:
int -> void filter ... {
work pop 1 {
println("Got " + pop());
}
}
Would yield nonsense code:
java.lang.String tmp_1; int tmp_2; tmp_2 = pop(); tmp_1 = "Got " + tmp_2;This could be handled with some effort, but has not been deemed necessary since the source code
| Field Summary | |
|---|---|
protected Set<JExpression> |
exprsToExpand
If using ThreeAddressCode to convert just parts of the code you will want to override ThreeAddressExpressionCheck |
protected JStatement[] |
statementBeingChecked
Statement on latest call to shouldConvertStatement. |
| Constructor Summary | |
|---|---|
ThreeAddressCode()
Constructor, initializes @{link #exprsToExpand}. |
|
| Method Summary | |
|---|---|
static List<JStatement> |
destructureOptBlock(JStatement maybeBlock)
Return list of statements from a single statement by opening up a block body. |
boolean |
literalOrVariable(JExpression exp)
is an expression a literal or a variable? |
static String |
nextTemp()
nextTemp returns a fresh variable name (hopefully) |
protected boolean |
shouldConvertExpression(JExpression exp)
Determine whether to convert an expression to 3-address code. |
protected boolean |
shouldConvertStatement(JStatement stmt)
Determine whether to convert a statement to 3-address code. |
protected boolean |
shouldConvertTopExpression(JExpression expr)
Determine if should convert expression directly under statement level. |
protected boolean |
simpleExpression(JExpression exp)
Simple expression returns true if an expression should shoud not be passed to E[[]]. |
static JStatement |
structureOptBlock(List<JStatement> stmts)
Return a single statement from a list of statements by creating a block if needed. |
static JStatement |
structureOptCompound(List<JStatement> stmts)
Return a single statement from a list of statements by creating a JCompoundStatement if needed. |
SIRStream |
threeAddressCode(SIRStream str)
Turn all filters in stream into three-address code. |
SIRFilter |
threeAddressCodeFilter(SIRFilter filter)
Turn a filter into three-address code. |
JMethodDeclaration |
threeAddressCodeMethod(JMethodDeclaration method,
CType inputTapeType)
Turn a method declaration into three-address code. |
List<JStatement> |
threeAddressCodeStatement(JStatement stmt,
CType inputTapeType)
Turn a statement into three-address code. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final Set<JExpression> exprsToExpand
protected final JStatement[] statementBeingChecked
| Constructor Detail |
|---|
public ThreeAddressCode()
| Method Detail |
|---|
public SIRStream threeAddressCode(SIRStream str)
str - : stream in which all filters are processed.
public SIRFilter threeAddressCodeFilter(SIRFilter filter)
filter - : filter to process.
public JMethodDeclaration threeAddressCodeMethod(JMethodDeclaration method,
CType inputTapeType)
method - : method to process the body of.inputTapeType - : type returned by peek or pop.
public List<JStatement> threeAddressCodeStatement(JStatement stmt,
CType inputTapeType)
stmt - : statement to convert to three-address codeinputTapeType - : type returned by peek or pop.
protected boolean shouldConvertStatement(JStatement stmt)
exp - : Statement to check as to whether to convert to 3-address code.
protected boolean shouldConvertTopExpression(JExpression expr)
expr - Expression to check for expansion
protected boolean shouldConvertExpression(JExpression exp)
exp - : Expression to check as to whether to convert to 3-address code.
protected boolean simpleExpression(JExpression exp)
exp - : expression to check
public boolean literalOrVariable(JExpression exp)
exp -
public static String nextTemp()
public static List<JStatement> destructureOptBlock(JStatement maybeBlock)
maybeBlock - a block, or other single statement, or null.
public static JStatement structureOptBlock(List<JStatement> stmts)
stmts - : a list of statements
public static JStatement structureOptCompound(List<JStatement> stmts)
stmts - : a list of statements
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||