kanga.translate
Class MIPSTranslator

java.lang.Object
  extended by kanga.visitor.GJDepthFirst<MResult,MContext>
      extended by kanga.translate.MIPSTranslator
All Implemented Interfaces:
GJVisitor<MResult,MContext>

public final class MIPSTranslator
extends GJDepthFirst<MResult,MContext>

Translates a Kanga AST into MIPS by printing the resulting code to the a PrintStream.

Author:
Santoso Wijaya

Constructor Summary
MIPSTranslator(java.io.PrintStream out)
          Creates a MIPS translator that prints its result to the given output stream.
 
Method Summary
 void translate(Goal p)
          Visits a Kanga AST, writing a MIPS code translation to the PrintStream output given in the constructor method.
 MResult visit(ALoadStmt n, MContext argu)
           nodeToken -> "ALOAD" reg -> Reg() spilledArg -> SpilledArg()
 MResult visit(AStoreStmt n, MContext argu)
           nodeToken -> "ASTORE" spilledArg -> SpilledArg() reg -> Reg()
 MResult visit(BinOp n, MContext argu)
           operator -> Operator() reg -> Reg() simpleExp -> SimpleExp()
 MResult visit(CallStmt n, MContext argu)
           nodeToken -> "CALL" simpleExp -> SimpleExp()
 MResult visit(CJumpStmt n, MContext argu)
           nodeToken -> "CJUMP" reg -> Reg() label -> Label()
 MResult visit(ErrorStmt n, MContext argu)
           nodeToken -> "ERROR"
 MResult visit(Exp n, MContext argu)
           nodeChoice -> HAllocate() | BinOp() | SimpleExp()
 MResult visit(HAllocate n, MContext argu)
           nodeToken -> "HALLOCATE" simpleExp -> SimpleExp()
 MResult visit(HLoadStmt n, MContext argu)
           nodeToken -> "HLOAD" reg -> Reg() reg1 -> Reg() integerLiteral -> IntegerLiteral()
 MResult visit(HStoreStmt n, MContext argu)
           nodeToken -> "HSTORE" reg -> Reg() integerLiteral -> IntegerLiteral() reg1 -> Reg()
 MResult visit(IntegerLiteral n, MContext argu)
           nodeToken -> <INTEGER_LITERAL>
 MResult visit(JumpStmt n, MContext argu)
           nodeToken -> "JUMP" label -> Label()
 MResult visit(Label n, MContext argu)
           nodeToken -> <IDENTIFIER>
 MResult visit(MoveStmt n, MContext argu)
           nodeToken -> "MOVE" reg -> Reg() exp -> Exp()
 MResult visit(NodeListOptional n, MContext argu)
           
 MResult visit(NoOpStmt n, MContext argu)
           nodeToken -> "NOOP"
 MResult visit(PassArgStmt n, MContext argu)
           nodeToken -> "PASSARG" integerLiteral -> IntegerLiteral() reg -> Reg()
 MResult visit(PrintStmt n, MContext argu)
           nodeToken -> "PRINT" simpleExp -> SimpleExp()
 MResult visit(Procedure n, MContext argu)
           label -> Label() nodeToken -> "[" integerLiteral -> IntegerLiteral() nodeToken1 -> "]" nodeToken2 -> "[" integerLiteral1 -> IntegerLiteral() nodeToken3 -> "]" nodeToken4 -> "[" integerLiteral2 -> IntegerLiteral() nodeToken5 -> "]" stmtList -> StmtList() nodeToken6 -> "END"
 MResult visit(Reg n, MContext argu)
           nodeChoice -> "a0" | "a1" | "a2" | "a3" | "t0" | "t1" | "t2" | "t3" | "t4" | "t5" | "t6" | "t7" | "s0" | "s1" | "s2" | "s3" | "s4" | "s5" | "s6" | "s7" | "t8" | "t9" | "v0" | "v1"
 MResult visit(SimpleExp n, MContext argu)
           nodeChoice -> Reg() | IntegerLiteral() | Label()
 MResult visit(SpilledArg n, MContext argu)
           nodeToken -> "SPILLEDARG" integerLiteral -> IntegerLiteral()
 
Methods inherited from class kanga.visitor.GJDepthFirst
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

MIPSTranslator

public MIPSTranslator(java.io.PrintStream out)
Creates a MIPS translator that prints its result to the given output stream.

Parameters:
out - the output stream
Method Detail

translate

public void translate(Goal p)
Visits a Kanga AST, writing a MIPS code translation to the PrintStream output given in the constructor method.

Parameters:
p - the Kanga AST's root node (Goal)

visit

public MResult visit(Procedure n,
                     MContext argu)
Description copied from class: GJDepthFirst
 label -> Label()
 nodeToken -> "["
 integerLiteral -> IntegerLiteral()
 nodeToken1 -> "]"
 nodeToken2 -> "["
 integerLiteral1 -> IntegerLiteral()
 nodeToken3 -> "]"
 nodeToken4 -> "["
 integerLiteral2 -> IntegerLiteral()
 nodeToken5 -> "]"
 stmtList -> StmtList()
 nodeToken6 -> "END"
 

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

public MResult visit(NodeListOptional n,
                     MContext argu)
Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

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

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

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

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

public MResult visit(CJumpStmt n,
                     MContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "CJUMP"
 reg -> Reg()
 label -> Label()
 

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

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

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

public MResult visit(HStoreStmt n,
                     MContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "HSTORE"
 reg -> Reg()
 integerLiteral -> IntegerLiteral()
 reg1 -> Reg()
 

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

public MResult visit(HLoadStmt n,
                     MContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "HLOAD"
 reg -> Reg()
 reg1 -> Reg()
 integerLiteral -> IntegerLiteral()
 

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

public MResult visit(MoveStmt n,
                     MContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "MOVE"
 reg -> Reg()
 exp -> Exp()
 

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

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

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

public MResult visit(ALoadStmt n,
                     MContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "ALOAD"
 reg -> Reg()
 spilledArg -> SpilledArg()
 

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

public MResult visit(AStoreStmt n,
                     MContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "ASTORE"
 spilledArg -> SpilledArg()
 reg -> Reg()
 

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

public MResult visit(PassArgStmt n,
                     MContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "PASSARG"
 integerLiteral -> IntegerLiteral()
 reg -> Reg()
 

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

public MResult visit(CallStmt n,
                     MContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "CALL"
 simpleExp -> SimpleExp()
 

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

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

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

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

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

public MResult visit(BinOp n,
                     MContext argu)
Description copied from class: GJDepthFirst
 operator -> Operator()
 reg -> Reg()
 simpleExp -> SimpleExp()
 

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

public MResult visit(SpilledArg n,
                     MContext argu)
Description copied from class: GJDepthFirst
 nodeToken -> "SPILLEDARG"
 integerLiteral -> IntegerLiteral()
 

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

public MResult visit(SimpleExp n,
                     MContext argu)
Description copied from class: GJDepthFirst
 nodeChoice -> Reg()
       | IntegerLiteral()
       | Label()
 

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

public MResult visit(Reg n,
                     MContext argu)
Description copied from class: GJDepthFirst
 nodeChoice -> "a0"
       | "a1"
       | "a2"
       | "a3"
       | "t0"
       | "t1"
       | "t2"
       | "t3"
       | "t4"
       | "t5"
       | "t6"
       | "t7"
       | "s0"
       | "s1"
       | "s2"
       | "s3"
       | "s4"
       | "s5"
       | "s6"
       | "s7"
       | "t8"
       | "t9"
       | "v0"
       | "v1"
 

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

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

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>

visit

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

Specified by:
visit in interface GJVisitor<MResult,MContext>
Overrides:
visit in class GJDepthFirst<MResult,MContext>