spiglet.translate
Class KangaTranslator

java.lang.Object
  extended by spiglet.visitor.GJDepthFirst<KangaResult,KangaContext>
      extended by spiglet.translate.KangaTranslator
All Implemented Interfaces:
GJVisitor<KangaResult,KangaContext>

public final class KangaTranslator
extends GJDepthFirst<KangaResult,KangaContext>

Translates a Spiglet AST to a Kanga AST. The grammar for the Kanga language can be found here, and its specification here.

Author:
Santoso Wijaya

Constructor Summary
KangaTranslator()
          Creates a translator visitor.
 
Method Summary
 Goal translate(Goal p)
          Visits a Spiglet AST, constructing a Kanga AST along the way, and then returns the root of the latter tree.
 KangaResult visit(BinOp n, KangaContext argu)
           operator -> Operator() temp -> Temp() simpleExp -> SimpleExp()
 KangaResult visit(Call n, KangaContext argu)
           nodeToken -> "CALL" simpleExp -> SimpleExp() nodeToken1 -> "(" nodeListOptional -> ( Temp() )* nodeToken2 -> ")"
 KangaResult visit(CJumpStmt n, KangaContext argu)
           nodeToken -> "CJUMP" temp -> Temp() label -> Label()
 KangaResult visit(ErrorStmt n, KangaContext argu)
           nodeToken -> "ERROR"
 KangaResult visit(Exp n, KangaContext argu)
           nodeChoice -> Call() | HAllocate() | BinOp() | SimpleExp()
 KangaResult visit(HAllocate n, KangaContext argu)
           nodeToken -> "HALLOCATE" simpleExp -> SimpleExp()
 KangaResult visit(HLoadStmt n, KangaContext argu)
           nodeToken -> "HLOAD" temp -> Temp() temp1 -> Temp() integerLiteral -> IntegerLiteral()
 KangaResult visit(HStoreStmt n, KangaContext argu)
           nodeToken -> "HSTORE" temp -> Temp() integerLiteral -> IntegerLiteral() temp1 -> Temp()
 KangaResult visit(IntegerLiteral n, KangaContext argu)
           nodeToken -> <INTEGER_LITERAL>
 KangaResult visit(JumpStmt n, KangaContext argu)
           nodeToken -> "JUMP" label -> Label()
 KangaResult visit(Label n, KangaContext argu)
           nodeToken -> <IDENTIFIER>
 KangaResult visit(MoveStmt n, KangaContext argu)
           nodeToken -> "MOVE" temp -> Temp() exp -> Exp()
 KangaResult visit(NoOpStmt n, KangaContext argu)
           nodeToken -> "NOOP"
 KangaResult visit(PrintStmt n, KangaContext argu)
           nodeToken -> "PRINT" simpleExp -> SimpleExp()
 KangaResult visit(Procedure n, KangaContext argu)
           label -> Label() nodeToken -> "[" integerLiteral -> IntegerLiteral() nodeToken1 -> "]" stmtExp -> StmtExp()
 KangaResult visit(SimpleExp n, KangaContext argu)
           nodeChoice -> Temp() | IntegerLiteral() | Label()
 KangaResult visit(StmtList n, KangaContext argu)
           nodeListOptional -> ( ( Label() )? Stmt() )*
 KangaResult visit(Temp n, KangaContext argu)
           nodeToken -> "TEMP" integerLiteral -> IntegerLiteral()
 
Methods inherited from class spiglet.visitor.GJDepthFirst
visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KangaTranslator

public KangaTranslator()
Creates a translator visitor. Call translate(spiglet.syntaxtree.Goal) to produce a Kanga AST from a given Spiglet AST.

Method Detail

translate

public Goal translate(Goal p)
Visits a Spiglet AST, constructing a Kanga AST along the way, and then returns the root of the latter tree. (Implementation detail: On top of the conventional designation of s registers as callee-saved and t registers as caller-saved, the a registers are caller-saved, as well; the v0 and v1 registers are used as scratch spaces for the translator, and the v0 register is used to store return values.

Parameters:
p - the Spiglet AST's root node (Goal)
Returns:
the root of the translated Kanga AST (Goal)

visit

public KangaResult visit(StmtList n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeListOptional -> ( ( Label() )? Stmt() )*
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(Procedure n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 label -> Label()
 nodeToken -> "["
 integerLiteral -> IntegerLiteral()
 nodeToken1 -> "]"
 stmtExp -> StmtExp()
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(NoOpStmt n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "NOOP"
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(ErrorStmt n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "ERROR"
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(JumpStmt n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "JUMP"
 label -> Label()
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(PrintStmt n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "PRINT"
 simpleExp -> SimpleExp()
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(MoveStmt n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "MOVE"
 temp -> Temp()
 exp -> Exp()
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(CJumpStmt n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "CJUMP"
 temp -> Temp()
 label -> Label()
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(HLoadStmt n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "HLOAD"
 temp -> Temp()
 temp1 -> Temp()
 integerLiteral -> IntegerLiteral()
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(HStoreStmt n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "HSTORE"
 temp -> Temp()
 integerLiteral -> IntegerLiteral()
 temp1 -> Temp()
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(Exp n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeChoice -> Call()
       | HAllocate()
       | BinOp()
       | SimpleExp()
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(HAllocate n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "HALLOCATE"
 simpleExp -> SimpleExp()
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(BinOp n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 operator -> Operator()
 temp -> Temp()
 simpleExp -> SimpleExp()
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(Call n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "CALL"
 simpleExp -> SimpleExp()
 nodeToken1 -> "("
 nodeListOptional -> ( Temp() )*
 nodeToken2 -> ")"
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(SimpleExp n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeChoice -> Temp()
       | IntegerLiteral()
       | Label()
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(IntegerLiteral n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> <INTEGER_LITERAL>
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(Temp n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "TEMP"
 integerLiteral -> IntegerLiteral()
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>

visit

public KangaResult visit(Label n,
                         KangaContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> <IDENTIFIER>
 

Specified by:
visit in interface GJVisitor<KangaResult,KangaContext>
Overrides:
visit in class GJDepthFirst<KangaResult,KangaContext>