coins.casttohir
Class ToHir

java.lang.Object
  extended bycoins.casttohir.ToHir

public class ToHir
extends java.lang.Object

ToHir Offer cooperation with other packages to all classes included in this package, for example, I/O files, compile option information, etc.


Field Summary
(package private)  Debug debug
          debug Used to access debugging fields.
protected  java.util.HashSet fAssignsForInitiation
           
 int fDbgLevel
           
protected  java.util.Map fHirOptMap
           
(package private)  HIR hir
          hir HIR instance (used to create HIR objects).
(package private)  HirRoot hirRoot
          hirRoot Used to access HIR root fields.
(package private)  IoRoot ioRoot
          ioRoot Used to access I/O root fields.
(package private)  MachineParam machineParam
          Define target machine parameters.
(package private)  java.lang.String nowFile
          nowFile Now procesing file name.
(package private)  int nowLine
          nowLine Now procesing line number.
(package private)  boolean optHirFromC
          optHirFromC Optimize HIR-C (temporary switch for development).
(package private)  boolean safeArrayAll
           
(package private)  Sym sym
          sym Sym instance (used to create Sym objects).
(package private)  SymRoot symRoot
          symRoot Used to access symbol root fields.
(package private)  Type typeVoidPtr
          typeVoidPtr Type of void pointer.
(package private)  boolean useArrayParameterSize
          useArrayParameterSize Use array parameter size (decided by compiler option).
(package private)  boolean useOldLir
          useOldLir Use old LIR generator (temporary switch for development).
(package private)  boolean useSubsForPtr
          useSubsForPtr Use subscripted expression for pointer (decided by compiler option).
 
Constructor Summary
ToHir(HirRoot pHirRoot, boolean oldlir, boolean fromc)
          ToHirUtil Constructor to record hirRoot, ioRoot, symRoot to make them available in methods of this class and subclasses.
 
Method Summary
(package private)  Exp addrExp(Exp e)
          addrExp Create OP_ADDR (= &e) expression node.
(package private)  Type compositeType(Type t1, Type t2, boolean checkqualifier)
          compositeType: Create the composite type that is the resultant type of an expression with t1 and t2 as its operand types.
(package private)  Sym createBlockSym()
          createBlockSym Create block symbol which has unique name.
(package private)  Label createLabel()
          createLabel Create label with name which does not overlap.
(package private)  Label createLabel(java.lang.String name)
          createLabel Create label.
(package private)  Type daPromotedType(Type t)
          Return the default argument promoted type.
(package private)  Exp decayExp(Exp e)
          decayExp Create OP_DECAY (convert array to pointer) expression node.
(package private)  void error(java.lang.String mes)
          error Output error message.
(package private)  void error(Sym s, java.lang.String mes)
           
(package private)  void fatal(java.lang.String mes)
          fatal Throws fatal error.
(package private)  java.lang.String getOp(HIR h)
          getOp Get operation name of HIR.
(package private)  SymTable getSubpTable()
          getSubpTable Get symbol table which current subprogram has.
(package private)  Type iPromotedType(Type t)
          Get the resultant type of integral promotion.
(package private)  boolean isArithmetic(Type t)
          isArithmetic Is arithmetic type ?
(package private)  boolean isCompatible(Type t1, Type t2, boolean checkqualifier)
          isCompatible Is compatible types ?
(package private)  boolean isIntegral(Type t)
          isIntegral Is integral type ?
(package private)  boolean isModifierIncluded(Type t1, Type t2)
          isModifierIncluded Is type modifier included ?
(package private)  boolean isScalar(Type t)
          isScalar Is scalar type ?
(package private)  void message(int level, java.lang.String mes)
          message Output debug message.
(package private)  ConstNode new0Node()
          new0Node Create constant 0 node.
(package private)  ConstNode new1Node()
          new1Node Create constant 1 node.
(package private)  AssignStmt newAssignStmt(Exp e1, Exp e2)
          newAssignStmt create assign statement.
(package private)  BlockStmt newBlockStmt(Stmt stmt)
          newBlockStmt Create block statement with statement stmt.
(package private)  ExpStmt newExpStmt(Exp exp)
          newExpStmt Create expression statement, and set position.
(package private)  Exp newFalseNode()
          newFalseNode Create false node.
(package private)  IfStmt newIfStmt(Exp condexp, Stmt thenstmt, Stmt elsestmt)
          newIfStmt Create if statement, and set position.
(package private)  LabeledStmt newLabeledStmt(Stmt stmt)
          newLabeledStmt create labeled statement which has statement stmt.
(package private)  VarNode newTempVarNode(Type t)
          newTempVarNode Create temporary variable node, with new variable bymbol.
(package private)  Exp newTrueNode()
          newTrueNode Create true node.
(package private)  Sym searchGlobalOrdinaryId(java.lang.String name)
          searchGlobalOrdinaryId Search ordinary identifier (=KIND_VAR,KIND_PARAM,KIND_SUBP,KIND_TYPE) from symTableRoot.
(package private)  Sym searchLocalOrdinaryId(java.lang.String name)
          searchLocalOrdinaryId Search ordinary identifier (=KIND_VAR,KIND_PARAM,KIND_SUBP,KIND_TYPE) from symTableCurrent.
(package private)  Sym searchOrdinaryId(java.lang.String name)
          searchOrdinaryId Search ordinary identifier (=KIND_VAR,KIND_PARAM,KIND_SUBP,KIND_TYPE) from symTableCurrent and it's parents.
(package private)  void setFlagAddressTaken(Exp e)
          setFlagAddressTaken Set FLAG_ADDRESS_TAKEN flag.
(package private)  void setFlagPointerOperation(Exp e)
          setFlagPointerOperation Set FLAG_POINTER_OPERATION flag.
(package private)  void setFlagValueIsAssigned(Exp e)
          setFlagValueIsAssigned Set FLAG_VALUE_IS_ASSIGNED flag.
(package private)  Exp subsExp(Exp e1, Exp e2)
          subsExp Create OP_SUBS (= e1[e2]) expression node.
(package private)  VectorType vectorType(Type t, long n)
          vectorType Create vector type.
(package private)  void warning(java.lang.String mes)
          warning Output warning message.
(package private)  void warning(Sym s, java.lang.String mes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hirRoot

final HirRoot hirRoot
hirRoot Used to access HIR root fields.


symRoot

final SymRoot symRoot
symRoot Used to access symbol root fields.


ioRoot

final IoRoot ioRoot
ioRoot Used to access I/O root fields.


debug

final Debug debug
debug Used to access debugging fields.


hir

final HIR hir
hir HIR instance (used to create HIR objects).


sym

final Sym sym
sym Sym instance (used to create Sym objects).


typeVoidPtr

final Type typeVoidPtr
typeVoidPtr Type of void pointer.


machineParam

final MachineParam machineParam
Define target machine parameters.


nowFile

java.lang.String nowFile
nowFile Now procesing file name.


nowLine

int nowLine
nowLine Now procesing line number.


useSubsForPtr

final boolean useSubsForPtr
useSubsForPtr Use subscripted expression for pointer (decided by compiler option).


useArrayParameterSize

final boolean useArrayParameterSize
useArrayParameterSize Use array parameter size (decided by compiler option).


useOldLir

final boolean useOldLir
useOldLir Use old LIR generator (temporary switch for development).


optHirFromC

final boolean optHirFromC
optHirFromC Optimize HIR-C (temporary switch for development).


fHirOptMap

protected java.util.Map fHirOptMap

safeArrayAll

final boolean safeArrayAll

fAssignsForInitiation

protected java.util.HashSet fAssignsForInitiation

fDbgLevel

public final int fDbgLevel
Constructor Detail

ToHir

public ToHir(HirRoot pHirRoot,
             boolean oldlir,
             boolean fromc)
ToHirUtil Constructor to record hirRoot, ioRoot, symRoot to make them available in methods of this class and subclasses.

Method Detail

message

void message(int level,
             java.lang.String mes)
message Output debug message.

Parameters:
level - Debug level
mes - Debug message

warning

void warning(java.lang.String mes)
warning Output warning message.

Parameters:
mes - Message.

warning

void warning(Sym s,
             java.lang.String mes)

error

void error(java.lang.String mes)
error Output error message.

Parameters:
mes - Message.

error

void error(Sym s,
           java.lang.String mes)

fatal

void fatal(java.lang.String mes)
fatal Throws fatal error.

Parameters:
mes - Message.

getOp

java.lang.String getOp(HIR h)
getOp Get operation name of HIR.

Parameters:
h - HIR node.
Returns:
Operation name.

createBlockSym

Sym createBlockSym()
createBlockSym Create block symbol which has unique name.

Returns:
New block symbol.

createLabel

Label createLabel(java.lang.String name)
createLabel Create label. It is defined in symRoot.subpCurrent, and registered in symRoot.symTableCurrent.

Parameters:
name - Label name.
Returns:
Created label.

createLabel

Label createLabel()
createLabel Create label with name which does not overlap. It is defined in symRoot.subpCurrent, and registered in symRoot.symTableCurrent.

Returns:
Created label.

getSubpTable

SymTable getSubpTable()
getSubpTable Get symbol table which current subprogram has. If symTableCurrentSubp is null, return symTableRoot.

Returns:
table

searchGlobalOrdinaryId

Sym searchGlobalOrdinaryId(java.lang.String name)
searchGlobalOrdinaryId Search ordinary identifier (=KIND_VAR,KIND_PARAM,KIND_SUBP,KIND_TYPE) from symTableRoot.

Returns:
Found symbol.

searchLocalOrdinaryId

Sym searchLocalOrdinaryId(java.lang.String name)
searchLocalOrdinaryId Search ordinary identifier (=KIND_VAR,KIND_PARAM,KIND_SUBP,KIND_TYPE) from symTableCurrent.

Returns:
Found symbol.

searchOrdinaryId

Sym searchOrdinaryId(java.lang.String name)
searchOrdinaryId Search ordinary identifier (=KIND_VAR,KIND_PARAM,KIND_SUBP,KIND_TYPE) from symTableCurrent and it's parents.

Returns:
Found symbol.

vectorType

VectorType vectorType(Type t,
                      long n)
vectorType Create vector type. Vector type is created in the same symbol table as element type.

Parameters:
t - Element type.
n - Element count.
Returns:
Vector type element type t.

isCompatible

boolean isCompatible(Type t1,
                     Type t2,
                     boolean checkqualifier)
isCompatible Is compatible types ?

Parameters:
t1 - Type.
t2 - Type.
checkqualifier - true:Check qualifier completely. false:Disregard qualifier.
Returns:
True if compatible type.

compositeType

Type compositeType(Type t1,
                   Type t2,
                   boolean checkqualifier)
compositeType: Create the composite type that is the resultant type of an expression with t1 and t2 as its operand types.

Parameters:
t1 - Type to be synthesized.
t2 - Type to be synthesized.
Returns:
Composite type or null if incompatible.

daPromotedType

Type daPromotedType(Type t)
Return the default argument promoted type.

Parameters:
t - type.
Returns:
default argument promoted type.

iPromotedType

Type iPromotedType(Type t)
Get the resultant type of integral promotion.
 If the rank of t < the rank of int then {
   If (precision of t >= precision of int) and (t is unsigned)
   then resultant type is unsigned int
   else resultant type is int.
 }else
   do not do integral promotion.
 

Parameters:
t - Type
Returns:
(Promoted) resultant type.

isIntegral

boolean isIntegral(Type t)
isIntegral Is integral type ?

Parameters:
t - Type.
Returns:
True if t is integral type (short, int, long, etc.).

isArithmetic

boolean isArithmetic(Type t)
isArithmetic Is arithmetic type ?

Parameters:
t - Type.
Returns:
True if t is arithmetic type.

isScalar

boolean isScalar(Type t)
isScalar Is scalar type ?

Parameters:
t - Type.
Returns:
True if t is scalar type.

isModifierIncluded

boolean isModifierIncluded(Type t1,
                           Type t2)
isModifierIncluded Is type modifier included ?

Parameters:
t1 - Type.
t2 - Type.
Returns:
True if left side type covers the qualifiers of right side.

setFlagPointerOperation

void setFlagPointerOperation(Exp e)
setFlagPointerOperation Set FLAG_POINTER_OPERATION flag. If expression has a variable which type is pointer or array, set FLAG_POINTER_OPERATION flag to the variable.

Parameters:
e - Expression which has a variable.

setFlagAddressTaken

void setFlagAddressTaken(Exp e)
setFlagAddressTaken Set FLAG_ADDRESS_TAKEN flag. If expression has a variable, set FLAG_ADDRESS_TAKEN flag to the variable. If expression is qualifier or subscript, this method is called recursive.

Parameters:
e - Expression which has a variable.

setFlagValueIsAssigned

void setFlagValueIsAssigned(Exp e)
setFlagValueIsAssigned Set FLAG_VALUE_IS_ASSIGNED flag. If expression has a variable, set FLAG_ADDRESS_TAKEN flag to the variable. If expression is qualifier or subscript, this method is called recursive.

Parameters:
e - Expression which has a variable.

decayExp

Exp decayExp(Exp e)
decayExp Create OP_DECAY (convert array to pointer) expression node.

Parameters:
e - Expression whose type is array.
Returns:
Decay expression.

addrExp

Exp addrExp(Exp e)
addrExp Create OP_ADDR (= &e) expression node.

Parameters:
e - Adress taken expression.
Returns:
Taken address.

subsExp

Exp subsExp(Exp e1,
            Exp e2)
subsExp Create OP_SUBS (= e1[e2]) expression node.

Parameters:
e1 - Array expression.
e2 - Index expression.
Returns:
Subscripted expression.

newTempVarNode

VarNode newTempVarNode(Type t)
newTempVarNode Create temporary variable node, with new variable bymbol.

Parameters:
t - New symbol type.
Returns:
Created variable node.

new0Node

ConstNode new0Node()
new0Node Create constant 0 node.

Returns:
Constant 0 node.

new1Node

ConstNode new1Node()
new1Node Create constant 1 node.

Returns:
Constant 1 node.

newTrueNode

Exp newTrueNode()
newTrueNode Create true node.

Returns:
True node.

newFalseNode

Exp newFalseNode()
newFalseNode Create false node.

Returns:
False node.

newBlockStmt

BlockStmt newBlockStmt(Stmt stmt)
newBlockStmt Create block statement with statement stmt.

Parameters:
stmt - Stmt
Returns:
BlockStmt

newIfStmt

IfStmt newIfStmt(Exp condexp,
                 Stmt thenstmt,
                 Stmt elsestmt)
newIfStmt Create if statement, and set position.

Parameters:
condexp - Condition expression.
thenstmt - Then statement.
elsestmt - Else statement.
Returns:
IfStmt

newExpStmt

ExpStmt newExpStmt(Exp exp)
newExpStmt Create expression statement, and set position.

Parameters:
exp - Exp
Returns:
ExpStmt

newAssignStmt

AssignStmt newAssignStmt(Exp e1,
                         Exp e2)
newAssignStmt create assign statement.

Parameters:
e1 - Exp
e2 - Exp
Returns:
AssignStmt

newLabeledStmt

LabeledStmt newLabeledStmt(Stmt stmt)
newLabeledStmt create labeled statement which has statement stmt.

Parameters:
stmt - Stmt
Returns:
LabeledStmt