kanga.meta
Class KangaStorage

java.lang.Object
  extended by kanga.meta.KangaStorage

public final class KangaStorage
extends java.lang.Object

This wrapper represent a "union" structure of a storage unit in Kanga. A value in Kanga can be stored in either a register or on the stack. This class represents that storage information.

Author:
Santoso Wijaya
See Also:
KangaReg

Constructor Summary
KangaStorage(int offset)
          Wraps a storage unit in a stack with the given offset from the stack pointer.
KangaStorage(KangaReg reg)
          Wraps a storage unit in a register.
 
Method Summary
 KangaReg getReg()
          Returns the storage register.
 int getSpillOffset()
          Returns the spill offset where the storage is.
 boolean inRegister()
          Returns true if this storage unit is register-based.
 boolean inStack()
          Returns true if this storage unit is stack-based.
 SimpleExp lookupAsExp(KangaContext context)
          Looks up the storage unit and returns the corresponding Kanga expression that represents it (wraps a Reg AST).
 KangaReg lookupAsReg(KangaReg scratch, KangaContext context)
          Looks up the storage unit and returns the corresponding register that represents it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KangaStorage

public KangaStorage(KangaReg reg)
Wraps a storage unit in a register. Invalidates stack-based storage.

Parameters:
reg - the register where storage happens

KangaStorage

public KangaStorage(int offset)
Wraps a storage unit in a stack with the given offset from the stack pointer. Invalidates register-based storage.

Parameters:
offset - the offset from the stack pointer where storage happens
Method Detail

inStack

public boolean inStack()
Returns true if this storage unit is stack-based.

Returns:
true if this storage unit is stack-based

inRegister

public boolean inRegister()
Returns true if this storage unit is register-based.

Returns:
true if this storage unit is register-based

getReg

public KangaReg getReg()
Returns the storage register. Throws an error if this storage is stack-based.

Returns:
the storage register

getSpillOffset

public int getSpillOffset()
Returns the spill offset where the storage is. Throws an error if this storage is register-based.

Returns:
the spill offset where the storage is

lookupAsExp

public SimpleExp lookupAsExp(KangaContext context)
Looks up the storage unit and returns the corresponding Kanga expression that represents it (wraps a Reg AST). Might attach a MOVE instruction to a scratch register if the storage is in the stack.

Parameters:
context - the context where a potential MOVE statement is attached
Returns:
the Kanga expression that represents the storage lookup
See Also:
Reg, KangaReg.SCRATCH_0

lookupAsReg

public KangaReg lookupAsReg(KangaReg scratch,
                            KangaContext context)
Looks up the storage unit and returns the corresponding register that represents it. Might have to attach a ALOAD statement to a scratch register first if the storage is not register-based (in stack).

Parameters:
scratch - the scratch register to which potential loaded value is stored if need be (and also the register returned if that happens)
context - the context where a potential MOVE statement is attached
Returns:
the register that represents the storage lookup
See Also:
KangaReg.SCRATCH_0, KangaReg.SCRATCH_1