spiglet.translate
Class KangaResult

java.lang.Object
  extended by spiglet.translate.KangaResult

public final class KangaResult
extends java.lang.Object

The result of visiting an expression subtree in a translation step to Kanga. A result wraps a simple expression.

Author:
Santoso Wijaya

Constructor Summary
KangaResult(SimpleExp exp)
          Wraps an expression as a result.
 
Method Summary
 SimpleExp getExp()
          Returns the wrapped result as an expression.
 KangaReg processAsReg(KangaReg scratch, KangaContext context)
          Processes this result's simple exp, if it is a Reg, return a Reg object that corresponds to it, otherwise inject a MOVE statement to a scratch register (as defined in KangaTranslator), then returns the Reg object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KangaResult

public KangaResult(SimpleExp exp)
Wraps an expression as a result.

Parameters:
exp - the expression result
Method Detail

getExp

public SimpleExp getExp()
Returns the wrapped result as an expression.

Returns:
the wrapped result as an expression

processAsReg

public KangaReg processAsReg(KangaReg scratch,
                             KangaContext context)
Processes this result's simple exp, if it is a Reg, return a Reg object that corresponds to it, otherwise inject a MOVE statement to a scratch register (as defined in KangaTranslator), then returns the Reg object.

Parameters:
scratch - the scratch register to where evaluation of the expression is moved, if need be; this is also the register returned if such evaluation happens.
context - the context to which a potential MOVE statement is attached
Returns:
the register whose value equals this expression's evaluation
See Also:
KangaReg.SCRATCH_0, KangaReg.SCRATCH_1