package
coins.ir.hir;
import
coins.*;
import
coins.ir.IrList; //##12
import
coins.ir.*;
import
coins.ir.hir.*;
import
coins.sym.*;
import
coins.flow.*;
import
java.util.*;
//========================================//
//
(##20):Revised on
Feb., Mar. 2003-.
//
(##19):Revised on Dec. 2002-.
//
(##14):Revised on Jun. 2002.
//
(##12):Revised on Mar. 2002.
//
(##10):Revised on Nov., Dec. 2001.
//
(##9): Revised on Oct. 2001.
/** HIR
interface:
<PRE>
* High Level Intermediate Representation
(HIR) interface.
* All HIR classes implement all methods
declared in HIR interface
* and IR interface which is inherited by
the HIR interface.
* See IR, Stmt, Exp, Sym interfaces and
HirRoot class.
*
* Preliminaries
* High level intermediate representation is composed of
operation
* information in a tree form, symbol information, data
flow
* information, and others.
* The operation information tree is composed of nodes
and edges.
* A node with children is called as nonleaf node and a
node without
* child is called a leaf node.
* The term "node" means either leaf node or nonleaf
node,
* the term "subtree" means either pure subtree
composed of
* several nonleafs and leafs, or one leaf.
*
* Class/interface hierarchy:
* (Root is a class, others are interfaces.
* An interface xxx is implemented by corresponding
class
* named xxxImpl or xxx_Impl.)
*
* Root
* |
* |- Sym
* | |- ...
* |
* |- Flow
* | |- ...
* |
* |- IR
* |- IR_factory // IR object creation factory.
* |- IrList // List of indefinite
number of objects.
* | |- HirList
// IrList whose elements are HIR objects. //##12
* |
* |- LIR // Low
level Intermediate Representation
* | |- ...
* |
* |- HIR // High level Intermediate
Representation.
* | // Usual operations on HIR are done by
using HIR methods.
* |
* |- Program
// Program definition node.
* |-
SubpDefinition // Subprogram
definition node.
* |- HirSeq // Sequence
of definite number of
* |
// HIR objects.
* |- HirList
// IrList whose elements are HIR objects.
* |
// (Multi-inheritance of interface) //##14
* |- Stmt
// Statement
* | |- LabeledStmt // Labeled statement.
* | |- AssignStmt // Assignment statement.
* | |- IfStmt //
If-statement.
* | |- JumpStmt // Jump (goto) statement.
* | |
// (Jump unconditionally)
* | |- LoopStmt // Loop statement.
* | | |- ForLoop // For-loop.
* | | |- WhileLoop // While-loop.
* | | |- UntilLoop // Repeat-until loop.
* | | |- IndexedLoop // Loop with index range
* | |
// (such as Fortran DO loop).
* | |- ReturnStmt // Return statement.
* | |- SwitchStmt // Switch (case) statement.
* | |- BlockStmt // Block representing a
sequence
* | |
// of statements.
* | |- ExpStmt // Expression
treated as a statement.
* | |
// Call statement is treated as an
* | |
// expression statement of function call.
* | |
// Loop start condition expression has
* | |
// label and treated as ExpStmt.
* | |- InfStmt // An
information node
* |
// which can be treated as a statement.
* |
// (pragma, comment line,
etc.)
* |- LabelDef
// Label definition node.
* // |- InfNode // IR
information node. //##17 DELETED
* // |
// (pragma, comment line,
etc.)
* |- Exp // Expression
*
|- ConstNode // Constant node
*
|- SymNode // Symbol
node
*
| |- VarNode // Variable name node.
* // | | |- ParamNode // formal parameter name node
* // | | |
//##16 DELETED
*
| | |- ElemNode // struct/union element name node
*
| |
//##16 not DELETED
*
| |- SubpNode // Subprogram name node.
* | |- LabelNode // Label reference
node.
*
| |- TypeNode // Type name node.
*
|
*
|- SubscriptedExp // Subscripted variable.
*
|- PointedExp
// Pointed object.
*
|- QualifiedExp //
Qualified variable.
*
|- FunctionExp
// Function call expression.
*
|- PhiExp //
Phi function used in SSA
*
|- ExpList_ // List of
expressions
*
|
// (implemented as a kind of IrList).
*
|- NullNode // Null
(no-operation) node
*
*
Deleted classes:
* ParamNode, //##16
* StmtBody, AssignExp,
* Nonleaf, Leaf, HIRdetail, BBlock, PBlock,
ExitStmt,
* ContinueStmt. (##10)
*
* Abstract syntax of HIR:
*
*
Abstract syntax of HIR is shown as BNF syntax
*
in the form ( operationCode attr child1 child2 ... ),
*
where, child1 represents source operand 1, child2 represents
*
source operand 2, ...
. Instance of HIR may be regarded
*
as a tree attached with operands as its subtree.
*
The result operand is represented by the root node
*
of the tree. The attr represents attributes
*
such as type of the tree, etc.
*
(Each node may be attached an expression identifier (expId)
*
as an attribute. In such case, the expId attached to
*
the root node of a subtree may be regarded as the identifier
*
corresponding to the result value of the operation
*
specified by the subtree.)
*
Each child is also a subtree of the same form.
*
Some child may be null.
//##20
*
The operationCode and attr are not subtree but
*
information attached to the root node of the subtree.
*
(This notation is not explaining parse tree of HIR but
*
explaining abstract syntax tree of HIR.)
*
*
Notations in the following BNF descriptions..
* identifier starting with lower case letter
except attr: terminal
* identifier starting with upper case letter: nonterminal
* identifier ending with
"_":
* nonterminal that is not an interface
* identifier that does not end with
"_":
*
nonterminal representing an interface
* xxxCode: operation code xxx
* xxxSym : symbol recorded in the symbol table
*
progSym : program name symbol
*
subpSym : subprogram name symbol
*
varSym : variable name
symbol
*
(including array/struct/union name symbol)
*
paramSym: formal parameter name symbol
*
elemSym : struct/union element name symbol
* // fieldSym: field name symbol of a
class
* // classSym: class name symbol
*
labelSym: label name symbol
*
typeSym : type name symbol
* xxxConst: constant recorded in the symbol table
*
intConst : integer
constant
*
(int/short/long/unsigned int/ ...)
*
floatConst : floating constant (float/double/ ...)
*
charConst : character
constant (signed/unsigned)
*
stringConst: character string constant
*
boolConst : boolean
constant
*
(true is 1, false is 0 in integer)
* intConstValue: integer constant
*
(not a symbol table entry but value itself).
* stringConstValue: string constant
*
(not a symbol table entry but value itself).
* null : empty
* NullNode : a leaf node with operation code null.
* List_of_xxx: java.util.List with elements xxxx.
(##10)
*
*
Note:
* Following items are not represented as a subtree
* dangling to a node but are represented as
information
* attached to the node. They are not traversed
when HIR tree
* is traversed but can be get by applying
corresponding HIR
* methods to the node.
* Operation code (xxxCode)
* Symbol table entry
(xxxSym)
* Constant symbol (xxxConst)
* Symbol table
(SymTable, GlobalSymTable_, LocalSymTable_)
* attr
(attribute such as node type which is
*
a symbol representing the type
*
of the result of HIR subtree.)
* Items represented as a subtree is indicated by @
to clarify.
* (@ is not
a syntactic component but a postfix marker
* to decrease misunderstanding.)
*
*
Program ->
// Program represents a compile unit.
* ( progCode attr //
* GlobalSymTable_ // Global symbols of
the program
* ProgSym_ @ // Program
name (may be null).
* InitiationPart_ @ // Initial value specification.
* SubpList_ @ ) //
Subprogram definition list.
*
ProgSym_ ->
* ( symCode attr progSym ) // Program name symbol.
* | null
*
GlobalSymTable_ -> // Global symbol table of the
program.
* SymTable // As
for SymTable, see Sym and SymTable.
* | null
*
InitiationPart_ ->
// Initial value specification (##14)
* InitiationBlock_
* | NullNode
*
InitiationBlock_ ->
// Block containing initiation statements.
* ( blockCode attr
* InitiationStmtSeq_ @ )
*
InitiationStmtSeq_ -> // Sequence of initiation statements
* InitiationStmt_ @ InitiationStmtSeq_ @
* | null
*
InitiationStmt_ ->
// Initiation statement
* ( setDataCode attr
// with Exp_l_: l-value
* Exp_l_ @ ValueSpec_ @ )
// ValueSpec_: constant Exp.
* | AssignStmt
*
ValueSpec_ ->
* ConstNode // Constant value
* | ( listCode attr // List of ValueSpec_
* List_of_ValueSpec_ @ )
* | ( repeatCode attr //
Repeat ValueSpec_
* ValueSpec_ @ intConst @ )
// intConst-times.
*
SubpList_ ->
* ( listCode attr // Subprogram definition list
* List_of_SubpDefinition @ )
*
SubpDefinition -> // Subprogram definition
* ( subpCode attr
* LocalSymTable_ // SymTable local in the
subprogram.
* SubpNode @ //
Subprogram name.
* InitiationPart_ @ //
Subprogram initiation.
* BlockStmt @ // HIR subprogram body
*
// (Control flow should be ended by return).
* LIR @ ) // LIR
representation for the subprogram.
*
SubpNode -> // Subprogram
name node.
* ( symCode attr
* subpSym )
*
LocalSymTable_ -> // Local symbol table (for subprogram, block, etc.)
* SymTable
* | null
*
BlockStmt ->
* ( blockCode attr
* LocalSymTable_ // Define symbols local in the block.
* StmtSeq_ @ ) // Block makes a sequence
of statements
*
// to be treated as one statement.
*
// Statements in StmtSeq_ can be get
*
// by getFirstStmt() and getNextStmt().
*
StmtSeq_ ->
* Stmt @ StmtSeq_ @ // Statement sequence is a statement
* | null
// followed by statements or empty.
*
Stmt
-> // Statement
is
* LabeledStmt // a statement with
label definitions or
* | StmtBody_ // a
statement without label definition.
*
LabeledStmt -> // Labeled statement.
* ( labeledStmtCode attr
* LabelDefinitionList_ @
// List of label definitions.
* StmtBody_ @ ) // Statement
body (statement that is
*
// peeled label off).
*
LabelDefinitionList_ ->
// List of LabelDef nodes.
* ( listCode attr
* List_of_LabelDef @ )
*
LabelDef ->
// Label definition node.
* ( labelDefCode attr
* labelSym )
*
StmtBody_ -> // Statement body.
* AssignStmt // Assignment statement.
* | IfStmt // If statement.
* | JumpStmt // Jump (goto) statement.
* | LoopStmt // Loop statement.
* | CallStmt_ // Subprogram call statement.
* | ReturnStmt // Return statement.
* | SwitchStmt // Switch (case selection) statement.
* | BlockStmt // Block statement.
* | ExpStmt // Expression treated as
a statement.
*
*
AssignStmt ->
// Assign statement.
* ( assignCode attr
* Exp_l_ @ // l_value expression
* Exp @ ) // Expression
to be assigned.
* | ( CompoundAssignOperator_ attr // HIR-C only
* Exp_l_ @
* Exp @ )
* | ( IncrDecrOperator_ attr // HIR-C only
* Exp_l_ @ )
*
Exp_l_ ->
// l-value expression is
* Exp
// an expression representing an object
*
// (memory area to contain data).
*
IfStmt
->
// If statement
* ( ifCode attr
* ConditionalExp_ @ // Conditional expression.
* ThenPart_ @ //
Then-part
* ElsePart_ @ //
Else-part.
* LabeledNull_ @ ) // End-of-if label.
*
ThenPart ->
* LabeledStmt // Executed if ConditionalExp is true.
* | null //
*
ElsePart ->
* LabeledStmt // Executed if ConditionalExp is false.
* | null //
*
LabeledNull_
-> //
LabeledNull_ is
* ( labeledStmtCode attr // a labeled statement
* LabelDefinitionList_ @ // with
null stmt body.
* null @ )
*
JumpStmt ->
* ( jumpCode attr // Jump to the statement with
* LabelNode @ ) // specified label.
*
LoopStmt -> // Loop
statement is either for-loop, while-loop,
*
// until-loop, indexed loop, or other general loop.
*
// All of them are implemented as a general loop
*
// with some restriction depending on the loop type.
*
// Compiler components (other than front part) should
*
// treat general loop, that is, do not assume some child
*
// is null without checking whether the child is null
*
// or not.
* ( LoopCode_ attr // Loop kind code.
* LoopInitPart_ @ // Loop initiation part to
be executed
*
// before repetition. This may be null.
* ConditionalInitPart_ @ //
Conditional initiation part.
*
// Executed once if attached loop
*
// start condition is satisfied.
*
// See LoopStmt interface for detail.
* StartConditionPart_ @ // Loop start conditional expression
*
// with loopBackLabel.
*
// If true, pass through to LoopBody_,
*
// otherwise transfer to LoopEndPart_.
*
// If loop start condition part is null,
*
// pass through to
LoopBody_.
* LoopBody_ @ //
Loop body repetitively executed.
*
// Pass through to EndCondition_.
*
// It is a block statement (BlockStmt)
*
// with loop start label and the blcok
*
// statement contains a labeled statement
*
// with loopStepLabel as its last statement.
*
// This
should not be null but the block may
*
// have no executable statement and contains
*
// only a labeled statement with loopStepLabel.
*
// "continue" jumps to the loopStepLabel.
*
// The loopStepLabel may be omitted if
*
// there is no "jump loopStepLabel".
* EndCondition_ @ // Loop end condition expression.
*
// If true, transfer to LoopEndPart_,
*
// otherwise pass through to
*
// LoopStepPart_.
* LoopStepPart_ @ // Loop step part executed
*
// before jumping to loopBackLabel.
* LoopEndPart_ @ ) // Loop end part
*
// with loopEndLabel.
*
// "exit" (break in C) jumps to here.
* IndexedLoop_ attr // Attributes for IndexedLoop.
//##21
*
// Not given for other loops.
//##21
*
LoopCode_ attr ->
* whileCode attr // while-loop
* | forCode attr // for-loop
* | untilCode attr // until-loop
* | indexedLoopCode attr// indexed-loop //##21
* | loopCode attr // general loop other than
above loops. //##21
*
LoopInitPart_
-> // Loop initiation
part.
* Stmt
* | null
*
ConditionalInitPart_ ->
// Executed at first time only.
* Stmt
// Semantics of this is the same
* | null // to the
following if-statement with label:
*
// if
(exp_of_StartCondition_) {
*
//
statement of ConditionalInitPart_;
*
// goto
loopStartlabel of LoopBody_;
* // }else
*
// goto
loopEndlabel:
*
// where, statement of ConditionalInitPart_
*
// is executed once if start condition
*
// (exp_of_StartCondition_) is true.
*
// Control transfers to LoobBody_
*
// if the exp_of_StartCondition_ is true.
*
StartConditionPart_ -> // Show start condition with
* ( labeledStmtCode attr // loopBacklabel.
* LabelDefinitionList_ @
* ExpStmtOrNull_ @ ) //
loopStartConditionExpression.
*
LoopBody_ ->
// Block statement with loopBodyLabel.
* ( labeledStmtCode attr // The last statement of the
block
* LabelDefinitionList_ @ // is a LabeledNull_
statement with
* BlockStmt_ @ )
// loopStepLabel.
*
EndCondition_ ->
// ExpStmt showing loop end condition.
* ExpStmtOrNull_
*
LoopStepPart_ -> // Statement to be executed
before jumping
* Stmt
// to loopBackLabel.
* | null
*
LoopEndPart_ -> // LabeledNull_
statement with loopEndLabel.
* LabeledNull_
*
NullOrStmt_ -> // Usually null but it may be
* null
// a statement (created during
* | Stmt
// HIR transformation). //##20
*
ExpStmtOrNull_ ->
// Expression statement or null.
* ExpStmt
* | null
*
IndexedLoop_ attr -> //
Attributes for IndexedLoop.
* loopIndex attr // Loop index (induction variable).
*
// See getLoopIndex().
* startValue attr // Start value of the loop index.
*
// See getStartValue().
* endValue attr // End value of the loop index.
*
// See getEndValue().
* stepValue attr // Step value for the loop index.
*
// See getStepValue().
*
*
// Note. LoopInf may contain goto-loop that is difficult or
*
// impossible to be
represent by above LoopStmt.
*
// (goto-loop is not
implemented by LoopStmt.) //##21
*
*
// LoopStmt is executed as follows:
*
// LoopInitPart_;
*
// if
(loopStartConditionExpression != null) {
*
// if
(loopStartConditionExpression == true) {
*
//
ConditionalInitPart_;
*
//
jump to loopBodyLabel;
*
// }else
*
//
jump to loopEndLabel;
*
// }else
*
// jump
to loopBodyLabel;
*
// loopBackLabel:
*
// if
((loopStartConditionExpression != null)&&
*
//
(loopStartConditionExpression == false))
*
//
jump to loopEndLabel;
*
// loopBodyLabel:
*
// Start
of BlockStmt of LoopBody_
*
//
Stastement sequence of the BlockStmt;
*
//
loopStepLabel:;
*
// End of
BlockStmt of LoopBody_
*
// if
((loopEndConditionExpression != null)&&
*
//
(loopEndConditionExpression == false))
*
//
jump to loopEndLabel;
*
//
LoopStepPart;
*
// jump
to loopBackLabel;
*
// loopEndLabel:
*
// Loop
end part;
*
*
// BEGIN #21
*
// ForStmt is created as a general loop where contents of
*
//
ConditionalInitPart_, EndCondition_, LoopEndPart_
*
// are null at first
(but they may become not null
*
// by some optimizing
transformation).
*
// See
isSimpleForLoop().
*
// WhileStmt is created as a general loop where contents of
*
// LoopInitPart_,
ConditionalInitPart_, EndCondition_,
*
// LoopStepPart_,
LoopEndPart_
*
// are null at first
(but they may become not null
*
// by some optimizing
transformation).
*
// See
isSimpleWhileLoop().
*
// UntilStmt is created as a general loop where contents of
*
// LoopInitPart,
ConditionalInitPart_, StartCondition_,
*
// LoopStepPart_,
LoopEndPart_
*
// are null at first
(but they may become not null
*
// by some optimizing
transformation).
*
// See
isSimpleUntilLoop().
*
// IndexedLoopStmt is created as a general loop where contents of
*
//
ConditionalInitPart_, EndCondition_, LoopEndPart_
*
// are null at first
(but they may become not null
*
// by some optimizing
transformation).
*
// See
isSimpleIndexedLoop().
*
// IndexedLoopStmt represents a Fortran type loop where
*
// value of loop
index is incremented or decremented by loop
*
// step value
starting from loop start value and stops
*
// to loop before
crossing the barrier of loop end value.
*
// (See
IndexedLoopStmt interface.)
*
// Indexed loop attributes (IndexedLoopAttr_) are available
*
// only for IndexedLoopStmt.
*
// END #21
*
*
// BEGIN old specifications
*
// Following specifications of LoopStmt are covered by
*
// the previous specifications of LoopStmt.
*
// LoopStmt ->
*
//
WhileStmt // While-loop
*
// | ForStmt // For-loop
*
// | UntilStmt
// Repeat-until-loop
*
// | IndexedLoopStmt // Loop with index range
*
// WhileStmt ->
*
// ( whileCode
attr
*
// NullOrStmt_ @ // Loop initiation part //##20
*
//
ExpStmt @ // ExpStmt in
conditional
*
//
// initiation part
*
//
StartCondition_ @ // Loop start condition
*
//
// with loopBackLabel.
*
//
LoopBody_ @ // Loop body statement.
*
//
LabeledNull_ @
// Loop end condition (null)
*
//
// with loopStepLabel
*
//
LabeledNull_ @
// continue statement jumps here.
*
// LabeledNull_
@ // Loop end part
with loopEndLabel
*
//
// (exit statement jumps to here.)
*
//
null @ ) // No index
range.
*
//
// Repetitively execute while ConditionalExp_ is true.
*
// ForStmt ->
*
// ( forCode
attr //
C-type for-loop statement.
*
//
LoopInitStmt_ @ //
Loop initiation statement.
*
//
ExpStmt @ // ExpStmt in
conditional
*
//
// initiation part
*
//
LoopCondition_ @ // Loop
start condition
*
//
// with loopBackLabel.
*
//
LoopBody_ @ // Loop body statement.
*
//
LabeledNull_ @
// Loop end condition (null)
*
//
// with loopStepLabel
*
//
LoopStepPart_ @ //
continue statement jumps here.
*
//
LabeledNull_ @
// Loop end part with loopEndLabel
*
//
null @ ) // No index
range.
*
// UntilStmt ->
*
// ( untilCode
attr
*
//
NullOrStmt_ @
// Loop initiation part
*
//
NullOrStmt_ @
// Conditional initiation part
*
//
LabeledNull_ @
// Loop start condition
*
//
// with loopBackLabel.
*
//
LoopBody_ @ // Loop body statement.
*
//
LoopCondition_ @ // Loop
end condition (null)
*
//
// with loopStepLabel
*
//
LabeledNull_ @
// continue statement jumps here.
*
//
LabeledNull_ @
// Loop end part with loopEndLabel
*
// null @ ) // No index
range.
*
//
// Repetitively execute until ConditionalExp_
*
//
// becomes true.
*
// IndexedLoop_ ->
//##21
*
// ( indexedLoopCode
attr
*
//
LoopInitPart_ @ // This part may be
null.
*
//
ConditionalInitPart_ @ // This part may be null.
*
//
StartConditionPart_ @ //
LabeledStmt with null statement body.
*
//
// Its label is loopBackLabel.
*
//
LoopBody_ @ // A block statement
(BlockStmt)
*
//
// with loop start label and the blcok
*
//
// statement contains a labeled statement
*
//
// with loopStepLabel as its last statement.
*
//
EndCondition_ @
// This part is null.
*
//
LoopStepPart_ @
// This part may be null.
*
// LoopEndPart_
@ //
LabeledNull_ with loopEndLabel.
*
// IndexRange_
@ ) // Index
range may be null in general loop.
*
// IndexRange_ -> // Show the summary of loop
control for loops
*
// ( seqCode
attr // with variable
incremented/decremented.
*
//
VarNode @ // Induction variable.
*
//
Exp @ //
LoopStartBound.
*
//
Exp @ // LoopEndBound.
*
//
Exp @ ) // StepValue for
the induction variable.
*
// | null
*
// LoopCondition_ ->
*
// (
labeledStmtCode attr
// Expression statement
*
//
LabelDefinitionList_ @ //
with label.
*
//
ExpStmt @ )
*
// The indexed loop is the same to a general loop having
*
// following components:
*
// LoopInitPart_ is ( assignCode attr VarNode loopStartBound ),
*
// loopStartConditionExpression is either
*
// ( cmpLeCode attr VarNode
loopEndBound ) or
*
// ( cmpGeCode attr
VarNode loopEndBound )
*
// (If stepValue is
plus, then former is taken, otherwise
*
// latter is
taken.),
*
// LoopStepPart_ is
*
// ( assignCode attr
VarNode
*
//
( addCode attr VarNode stepValue )).
*
// END old specifications
*
*
CallStmt_ ->
// Subprogram call statement.
* ( expStmtCode attr // Expression statement
* FunctionExp @ ) // with FunctionExp.
*
FunctionExp -> // Subprogram call
expression.
* ( callCode attr
* Exp @
// Expression specifying
*
// subprogram to be called.
* ExpList_ @ ) // Actual
parameter list.
*
ReturnStmt -> // Return
statement.
* ( returnCode attr
* ReturnValue_ @ ) // Return value.
*
ReturnValue_ ->
* Exp
* | null
*
SwitchStmt -> // Switch
statement.
* ( switchCode attr
* Exp @
// Case selection expression.
* JumpTable_ @ // List of
constants and statement labels.
* Stmt @
// Collection of statements to be selected.
* LabeledNull_ @ ) // Indicate end of case statement.
*
JumpTable_ -> // Jump
table.
* ( seqCode attr
* JumpList_ @ // List
of constant-label pairs.
* LabelNode @ ) // Default label.
*
JumpList_ ->
// Jump list.
* ( listCode attr //
Correlate Exp value
* List_of_SwitchCase @ ) // and list of SwitchCase_ pairs.
*
SwitchCase_ -> // List of SwitchCase_ pairs.
* ( seqCode attr
* ConstNode @ // Correlate Exp
value and
* LabelNode @ ) // switch statement label.
*
ExpStmt ->
// Expression statement.
* ( expStmtCode attr
* Exp @ )
// Expression treated as a Stmt.
*
NullNode ->
* ( nullCode attr ) // NullNode is a
terminal
*
// that is not null.
*
InfNode ->
* ( infCode attr // Information node (terminal).
* InfKind_ //
Information kind identifier.
* InfObject_ ) // Information.
*
// (InfKind_ and InfObject_ are not
*
// traversed by HIR traverse operations.)
*
InfKind_ ->
* stringConst // String constant showing the
kind of
*
// information such as pragma, comment, etc.
*
InfObject_ -> //
Information.
* Object // Object such as Sym, Exp, etc. or
* //
a list of Objects. It may or may not be HIR.
*
ConditionalExp_ -> // boolean expression
* Exp
*
Exp ->
// Expression.
* Factor_
* | UnaryExp_
* | BinaryExp_
* | SelectExp //
HIR-C only
* | NullNode
* | InfNode
*
Factor_ ->
* ConstNode
* | SymNode
* | CompoundVar_
* | FunctionExp
* | PhiExp
* //| AssignStmt // HIR-C
* | ExpList_
* | HirSeq
// Sequence of objects
*
UnaryExp_ -> //
Unary expression.
* ( UnaryOperator_ attr
* Exp @ )
* | ( sizeofCode attr@ // size of the type of Exp
* Exp @ ) @@@@
* | ( sizeofCode attr // size of the type
* TypeNode @ ) // represented by
TypeNode.
*
BinaryExp_ -> // Binary
expression.
* ( BinaryOperator_ attr
* Exp @
* Exp @ )
*
CompoundVar_ ->
// Compound variable.
* SubscriptedExp // Subscripted variable.
* | PointedExp // Pointed variable.
* | QualifiedExp // Qualified variable.
*
SubscriptedExp ->
Subscripted variable. //##14
* ( subsCode attr // Array with subscript
expression.
* Exp @ //
Expression indicating the array.
* Exp @ ) // Subscript
expression.
* | ( subsCode attr
* Exp @ //
Expression indicating an array.
* ExpList @ ) // List of
Subscripts.
*
// (1st subscript, 2nd subscript,
*
// etc. for rectangular
array.)
* // At
present, SubscriptedExp takes following form
* // but
it will be changed as above in near future.
*
( subsCode attr //
Array with index expression
*
Exp @
// Expression indicating an array.
*
( indexCode attr
*
Exp @
// Subscript expression
*
ElemSize_ @ )) // Size of
elements (offset
*
// corresponding to subscript increment).
*
ElemSize_
-> //
Element size.
* Exp
*
QualifiedExp ->
// Qualified expression.
* ( qualCode attr // Qualified variable
* Exp @
// Should represent a structure or union.
* ElemNode @ ) // struct/union element.
* // | ( qualCode attr // Class field
* // Exp @ // Should
represent a class.
* // FieldNode @ ) // Field of the class.
*
PointedExp -> // Pointed expression.
* ( arrowCode attr // Pointed variable
* Exp @
// Expression representing
a variable
* PointedElem_ @ ) // Pointed
element.
*
PointedElem_ ->
* ElemNode // Pointed element (with displacement).
* | null // Pointed location (0
displacement).
*
ConstNode ->
//
Constant symbol.
* ( constCode attr intConst ) // integer constant
* | ( constCode attr floatConst ) // float constant
* | ( constCode attr charConst ) // character constant
* | ( constCode attr stringConst ) // string constant
* | ( constCode attr boolConst ) // boolean constant
*
SymNode -> //
Symbol node.
* (symCode Sym ) // Program name, etc.
* | VarNode
* //| ParamNode //##16 DELETED
* | SubpNode
* | LabelNode
* | ElemNode
//##16 not DELETED
* | TypeNode
*
VarNode ->
* ( symCode attr varSym ) // Variable name node
*
SubpNode ->
* ( symCode attr subpSym ) // Subprogram name node
*
LabelNode ->
* ( symCode attr labelSym ) // Label reference
node
*
ElemNode ->
* ( symCode attr elemSym ) // structure/union element
*
// name node.
*
// FieldNode -> ( symCode attr fieldSym ) // Field name node.
*
TypeNode ->
* ( symCode attr typeSym ) // Type name node
*
FunctionExp -> // Function expression.
* ( callCode attr
* Exp @
// Expression specifying function
*
// to be called (SubpNode, etc.).
* ExpList_ @ ) // Actual parameter list.
*
ExpList_ ->
* ( listCode attr // IrList of Exp (List of
* List_of_Exp @ ) // expressions in HIR form.)
*
IrList
->
* ( listCode attr // A List that can be treated as IR.
* List_of_Objects_ @ )
*
HirList ->
* ( listCode attr // An IrList that can be treated as HIR.
* List_of_Objects_ @ )
*
HirSeq ->
* ( seqCode attr HIR @ ) // Sequence of some definite
* | ( seqCode HIR @ HIR @ ) // number of HIR nodes.
*
| ( seqCode HIR @ HIR @ HIR @ )
* | ( seqCode HIR @ HIR @ HIR @ HIR @ )
*
PhiExp ->
* (phiCode attr FlowVarList_ @ ) // phi function
*
FlowVarList_ ->
* ( listCode attr
* List_of_VarLabelPair @ )
* //
List of (Var Label) pairs.
*
VarLabelPair ->
* ( listCode attr VarNode @ Label @) //##9
*
UnaryOperator_ ->
* notCode // bitwise not (~) one's complement
*
// logical not for bool (!)
* | negCode // negate (unary minus)
* | addrCode // get address (&)
* | contentsCode // get contents of pointed memory
* | convCode // type conversion for basic type
* | decayCode // convert array to pointer
* | castCode // type conversion by cast for pointer
* | sizeofCode // sizeof operator
* | encloseCode
// honor parenthesis
* | IncrDecrOperator_ // Increment/decrement. HIR-C only.
*
BinaryOperator_ ->
* | addCode // add
(+)
* | subCode // subtract
(-)
* | offsetCode // Offset between pointers (HIR-C only)
* | multCode // multiply
(*)
* | divCode // divide
(/)
* | modCode // modulo
(%)
* | andCode // bitwise and
(&)
* | orCode // bitwise or
(|)
* | xorCode // bitwise exclusive or (^)
* | shiftLLCode
// shift left logical (<<) //
* | shiftRCode // shift right arithmetic (>>)
* | shiftRLCode
// shift right logical
(>>) //
* | indexCode // index (subscript)
* | undecayCode
// convert pointer to array //##10
* | CompareOperator_
* | CompareZeroOperator_
// HIR-C only //##20
* | ShortCircuitOperator_ //
HIR-C only
* | commaCode // comma operator // HIR-C only
*
CompareOperator_ ->
* cmpEqCode // equal
* | cmpNeCode // not equal
* | cmpGtCode // greater than
* | cmpGeCode // greater or equal
* | cmpLtCode // less than
* | cmpLeCode // less or equal
*
CompareZeroOperator_ ->
// HIR-C only //##20
* eqZeroCode // equal zero // HIR-C
only //##20
*
ShortCircuitOperator_ ->
// HIR-C only
* lgAndCode // logical and (&&) // HIR-C only
* | lgOrCode // logical or (||)
// HIR-C only
*
IncrDeclOperator_ ->
// HIR-C only
* preIncrCode // pre-increment
(++) // HIR-C only
* | preDecrCode
// pre-decrement (--) //
HIR-C only
* | postIncrCode // post-increment (++) // HIR-C only
* | postDecrCode // post-decrement (--) // HIR-C only
*
CompoundAssignmentOperator_ -> // HIR-C only
* multAssignCode // *= // HIR-C only
* | divAssignCode // /= // HIR-C only
* | modAssignCode // %= // HIR-C only
* | addAssignCode // += // HIR-C only
* | subAssignCode // -= // HIR-C only
* | shiftLAssignCode // <<= // HIR-C only
* | shiftRAssignCode // >>= // HIR-C only
* | andAssignCode // &= // HIR-C only
* | xorAssignCode // ^= // HIR-C only
* | orAssignCode // |= // HIR-C only
*
SelectExp -> // (Exp ? Exp : Exp) // HIR-C only
* ( selectCode attr
* ConditionalExp @ Exp @ Exp @ )
*
*
attr ->
// Attribute attached to the HIR node //##20
* typeSym // Shows the
type of HIR subtree.
* OptionalAttrSeq_ // Sequence of optional
attributes
*
// that are not inevitable at the first stage
*
// of HIR generation. The optional attributes
*
// may be attached to give information used
*
// in some specific compiler modules or
*
// to help compiling processes.
*
OptionalAttrSeq_ ->
* OptionalAttr_ OptionalAttrSeq_
* | null
*
OptionalAttr_ ->
* StmtAttr_ // Attributes for statements
* | IndexNumber_ // Index number to identify the HIR node.
* | Flag_ //
true/false flag.
* | InfItem_ // Node-wise information.
* | ExpId //
Expression identifier used in flow analysis.
* | Work_ //
Phase-wise information.
*
StmtAttr_ -> // Attributes attached to statement
subtrees.
* FileName_ // Source program file containing
the statement.
* LineNumber_ // Line number of the line in which the
*
// statement started.
*
FileName_ ->
* stringConstValue
*
LineNumber_
* intConstvalue
*
IndexNumber_ ->
* intConstValue
*
Flag_ ->
* FlagNumber_
* FlagValue_
*
FlagNumber_ ->
* intConstValue // Such as
FLAG_NOCHANGE, FLAG_C_PTR,
*
// FLAG_CONST_EXP
*
FlagValue_ ->
* true
* | false
*
InfItem_ ->
* InfKind_ InfObject_
*
*
*
Deleted methods:
* buildXxx, getSym (use getSym in IR or
getSymNodeSym in SymNode)
* insertBBlockCode, insertGBlockCode,
insertPBlockCode.
*
Deleted operators:
* addUCode, subUCode, multUCode, divUCode.
* (Decide by Type attached to each node.)
* addA, subA, multA, divA, modA, shiftL. (##9)
* lgNot
(##10)
*
*
Construction of HIR objects:
*
Most HIR objects are constructed by object factory methods
*
such as program(....), subpDefinition(....), assignStmt(....),
*
ifStmt(....), exp(....), etc. specified in the HIR interface.
*
Users are recommended to use the object factory methods so as
*
to avoid forgetting to specify essential data and to make
*
relation with other objects.
It is not recommended to use
*
"new" directly to construct HIR objects.
*
***
Operator number
public static final int
OP_PROG = 1, // Program
OP_SUBP_DEF = 2, // SubpDefinition
OP_LABEL_DEF = 3, // LabelDef node
OP_INF = 4, // Information node
OP_CONST
= 5, // ConstNode
OP_SYM = 6, // SymNode
OP_VAR = 7, // VarNode
OP_PARAM
= 8, // VarNode
OP_SUBP = 9, // SubpNode
OP_TYPE = 10, // TypeNode
OP_LABEL
= 11, // LabelNode
OP_ELEM = 12, // ElemNode
OP_LIST = 14, // List of CompilerObjects
// such as IR nodes and symbols
OP_SEQ =
15, // Sequence of HIR
objects //##10
OP_ENCLOSE =
16, // Enclose subexpression
//##9
OP_SUBS = 17, // subscripted variable
OP_INDEX
= 18, // index
modification of subscripted var
OP_QUAL = 19, // struct/union qualification
OP_ARROW
= 20, // pointer
reference
OP_STMT = 21, // Statement code lower. Stmt is
// an abstract class and there is
// no instance having OP_STMT.
OP_LABELED_STMT = 21, // Use the same number as Stmt
// because Stmt
is an abstract class.
OP_ASSIGN =
22, // AssignStmt
OP_IF
= 23, // IfStmt
OP_WHILE
= 24, // WhileStmt
OP_FOR =
25, // ForStmt
OP_UNTIL
= 26, // UntilStmt
OP_INDEXED_LOOP
= 27, //
IndexedLoopStmt (not yet implemented)
OP_JUMP = 28, // JumpStmt
OP_SWITCH =
32, // SwitchStmt
OP_CALL = 33, // Subprogram call
OP_RETURN =
34, // ReturnStmt
OP_BLOCK
= 35, // BlockStmt
OP_EXP_STMT = 36, // ExpStmt (expression statement)
OP_STMT_UPPER = 37,
OP_ADD = 38,
OP_SUB = 39,
OP_MULT = 41,
OP_DIV = 42,
OP_MOD = 43,
OP_AND = 46,
OP_OR
= 47,
OP_XOR = 48,
OP_CMP_EQ =
51,
OP_CMP_NE =
52,
OP_CMP_GT =
53,
OP_CMP_GE =
54,
OP_CMP_LT =
55,
OP_CMP_LE =
56,
OP_SHIFT_LL = 58,
OP_SHIFT_R = 59,
OP_SHIFT_RL = 60,
OP_NOT = 62,
OP_NEG = 63,
OP_ADDR = 64,
OP_CONV = 65,
OP_DECAY
= 66,
OP_UNDECAY =
67, //##10
OP_CONTENTS = 68,
OP_SIZEOF =
70,
OP_SETDATA =
71, //##15
OP_PHI = 72,
OP_NULL = 73,
OP_OFFSET =
76,
OP_LG_AND =
77,
OP_LG_OR
= 78,
OP_SELECT =
79,
OP_COMMA
= 80,
OP_EQ_ZERO =
81, //##20
OP_PRE_INCR = 82,
OP_PRE_DECR = 83,
OP_POST_INCR = 84,
OP_POST_DECR = 85,
OP_ADD_ASSIGN = 86,
OP_SUB_ASSIGN = 87,
OP_MULT_ASSIGN = 88,
OP_DIV_ASSIGN = 89,
OP_MOD_ASSIGN = 90,
OP_SHIFT_L_ASSIGN= 91,
OP_SHIFT_R_ASSIGN= 92,
OP_AND_ASSIGN = 93,
OP_OR_ASSIGN = 94,
OP_XOR_ASSIGN = 95,
OP_EXPLIST = 96, // list of datacode
OP_EXPREPEAT = 97 // repeat of datacode
;
*** Flag
numbers applied to HIR nodes:
static
final int //
Flag numbers used in setFlag/getFlag.
// They should be a number between 1 to 31.
FLAG_NOCHANGE = 1, // This subtree
should not be
// changed in optimization.
FLAG_C_PTR = 2, // The operation (add, sub) is
// pointer operation peculiar to C.
FLAG_CONST_EXP= 3; // This subtree is a
constant expression.
// (constant, address constant, null,
// sizeof
fixed-size-variable,
// expression whose
operands are all constant
// expression)
// Flag numbers 24-31 can
be used in each phase for apbitrary purpose.
// They may be destroyed by
other phases.
*** Coding
rules applied to all classes in the sym packege:
*
* Methods begin with lower case letter.
* Constants (final static int, etc.) are
spelled in upper case letters.
* Indentation is 2 characters. Tab is
not used for indentation.
* Formal parameters begin with p.
* Local variables begin with l.
* Methods and variables are named so
that meaning is easily guessed.
* Short names less than 3 characters are
not used except for
* very local purpose.
*
</PRE>
**/
public
interface
HIR
extends IR, Cloneable {
//##18
//====
Access methods available to build IR nodes. ====//
// (Factory methods for
creating HIR will be explained later.)
/**
program: Make a program node.
*
See Program interface.
*
@param pProgName: Program name (may be null).
*
@param pGlobalSymTable: Symbol table for global symbols.
*
@param pInitiationPart: Initiation statement (may be null).
*
@param pSubpList: List of subprograms. At first, it may be
* an empty list. (See
addSubpDefinition of Program interface.)
**/
public
Program
program(
Sym pProgName, SymTable pGlobalSymTable,
IR pInitiationPart, IrList pSubpList);
/**
subpDefifnition:
*
Make a subprogram definition node and
*
set symRoot.subpCurrent = pSubpSym,
*
set symRoot.symTableCurrentSubp = pLocalSymTable.
*
You may add initiation-part, HIR-body later
*
by using addInitiationStmt, setHirBody of SubpDefinition
*
interface.
*
Start label and end label for the given subprogram
*
are generated to make getStartLabel(), getEndLabel()
*
of Subp interface effective.
*
@param pSubpSym: Subprogram symbol. Should be given.
*
@param pLocalSymTable: Symbol table local in the subprogram;
* If subprogram uses a local symbol
table, this should
* be given (by using pushSymTable() of
SymTable interface).
*
@return the created SubpDefinition instance.
**/
public SubpDefinition
subpDefinition(
Subp pSubpSym, SymTable pLocalSymTable );
/**
subpDefinition without SymTable
*
If source language admits no local symbol for subprogram,
*
use this method to create SubpDefinition without
*
local symbol table.
* Other items are the same as the previous method.
*
@param pSubpSym: Subprogram symbol. Should be given.
*
@return the created SubpDefinition instance.
**/
public
SubpDefinition
subpDefinition(
Subp pSubpSym );
/**
subpDefinition with full specification.
*
Other items are the same as the previous method.
*
@param pSubpSym: Subprogram symbol. Should be given.
*
@param pLocalSymTable: should be given.
*
@param pInitiationPart: Initiation statement block. optional.
*
@param pHirBody: Subprogram body in HIR. optional.
**/
public
SubpDefinition
subpDefinition(
Subp pSubpSym, SymTable pLocalSymTable,
BlockStmt pInitiationPart, BlockStmt pHirBody);
/**
irList: Make an HirList node that makes a LinkedList.
*
The created list can be treated as an HIR node.
*
@param pList: List of objects to be included in the HirList;
* The elements of the list are an HIR
object or Sym object. //##19
*
@return IrList containing pList;
* Resultant list is also an instance
of HIR. //##12
**/
public
coins.ir.IrList
irList(
LinkedList pList );
/**
irList: Make an empty HirList node that make a LinkedList.
*
Use methods of IrList to add elements to the list.
*
The elements to be added are an HIR object or Sym object. //##19
*
The created list can be treated as an HIR node.
*
@return an empty IrList;
* Resultant list is also an instance
of HIR. //##12
**/
public
coins.ir.IrList
irList();
/**
infNode:
*
Build an InfNode representing some information.
*
The information may be defined in each compiler for arbitrary purpose.
*
@param pInfKindInterned: a string to identify the information kind of
* the InfNode; It should be an
interned string (string with intern()).
* See coins.Registry.
*
@param pInfData : any object to be attached (such as Sym or HIR node);
* The object kind is indicated by the
pInfKindInterned;
* If it is an IrList, then it can
represent complicated
* information structure.
**/
public
InfNode
infNode(
String pInfKindInterned, Object pInfData ); //##17
/**
infStmt:
*
Build an InfStmt representing some information.
*
The information may be defined in each compiler for arbitrary purpose.
*
@param pInfKindInterned: a string to identify the information kind of
* the InfNode. It should be an
interned string (string with intern());
* See coins.Registry.
*
@param pInfData : any object to be attached (such as Sym or HIR node);
* The object kind is indicated by the
pInfKindInterned;
* If it is an IrList, then it can
represent complicated
* information structure.
**/
public
InfStmt
infStmt(
String pInfKindInterned, Object pInfData ); //##17
//====
Methods to get/set HIR node information ====//
/**
getType:
*
Get the type attached to this node.
*
The type is usually attached when node is built by HIR
*
factory methods such as exp.
*
@return the type attached to this node.
**/
Type
getType();
/**
setType:
*
Attach a type to this node.
*
When HIR node is created by HIR factory methods,
*
its type is set in the factory methods so that
*
it is unnecessary to call setType again.
*
@param pType: type to be attached to this node;
* It should represent a proper type
corresponding to the
* result of subtree represented by
this node.
**/
void
setType(
Type pType );
/**
getNextStmt: Get statement next to this statement.
*
@return the statement next to this statement if
* this is a statement; If this is not
a statement,
* return null.
**/
public
Stmt
getNextStmt();
/**
getBBlock:
*
Get the basic block containing this node.
*
@return the basic block containing this node if the subprogram
* containing this node is already
devided into basic blocks;
* return null if basic block is not
yet created.
*
See controlFlowAnal of Flow for the creation of basic blocks.
**/
public
BBlock
getBBlock();
/**
getFlag: returns the value (true/false) of the flag indicated
*
by pFlagNumber.
*
See FLAG_NOCHANGE, FLAG_CONST_EXP, etc. of HIR interface.
*
@param pFlagNumber: flag identification number.
*
@return the value of the flag.
**/
boolean
getFlag(
int pFlagNumber);
/**
setFlag: sets the flag specified by pFlagNumber.
*
See FLAG_NOCHANGE, FLAG_CONST_EXP, etc. of HIR interface.
*
Some local flag numbers can be added in each phase.
*
@param pFlagNumber: flag identification number.
*
@param pYesNo: true or false to be set to the flag.
**/
void
setFlag(
int pFlagNumber, boolean pYesNo);
/**
flagsAreAllFalse:
*
@return true if all flags are false or no flag is set,
* false if some flag is true.
**/
boolean
flagsAreAllFalse();
/**
getFlagBox:
*
Users are recommended to use getFlag( int pFlagNumber )
*
except when they understand the treatment of FlagBox
*
in detail.
*
@return the flag box attached to this node;
* null if flag box is not attached (no
flag is set).
**/
public
FlagBox
getFlagBox();
/** setWork:
*
Set information privately used in each phase.
*
@param pWork: any information of arbitrary class to be set to this node;
* You may define a new class that
represents arbitrary information
* and give its reference as pWork.
*
This method is moved to IR interface.
**/
// void
//
setWork( Object pWork );
/**
getWork:
*
Get information set by setWork for this node.
*
Users should cast by the name of the class used in setWork.
*
@return the information object set by setWork.
*
This method is moved to IR interface.
**/
// Object
//
getWork();
//========================================//
/**
getExpId:
*
Get the expression identifier assigned to this node.
*
@return the expression identifier assigned to this node,
* or return null if it is not
assigned.
**/
ExpId
getExpId();
/**
setExpId:
*
Set the expression identifier computed for this node.
**/
void
setExpId(
ExpId pExpId );
/**
setFlowAnalSym:
*
Set ExpId as the flow analysis symbol for this node.
*
@param pFlowAnalSym: ExpId to be assigned to this node.
**/
void
setFlowAnalSym(
ExpId pFlowAnalSym );
/**
getChildNumber:
*
Get the child number of this node.
*
If not found, return -1.
*
(Usually, it is unnecessary to use this because
* the child number is known by stack, etc.)
**/
public int
getChildNumber();
/**
isStmt:
*
@return true if this node is a statement node,
* otherwise return false.
**/
public
boolean
isStmt();
/**
isTerminal:
*
@return true if this node is a terminal node having no child,
* otherwise return false. HirList is
nonterminal node.
**/
public
boolean
isTerminal();
//##20
/**
getStmtContainingThisNode:
*
Get the innermost statement or LabeledStmt containing this node
*
by traversing ancestors of this node.
*
If this is a statement, then this is the innermost statement.
*
If the the parent of the innermost statement is a LabeledStmt,
*
then the LabeledStmt is returned else the innermost statement
*
is returned.
*
@return the innermost statement or LabeledStmt
* containing this node.
**/
public
Stmt
getStmtContainingThisNode();
/**
cutParentLink:
*
Cut both links from/to parent node if they exist.
*
(Used to prepare for moving a node.)
*
This method is prepared for factory methods and it is not
*
recommended to use this method except when user knows the
*
structure of HIR in detail.
**/
public
void
cutParentLink();
/**
cutParentLink: //##19
*
Cut both links from/to parent node if they exist.
*
(Used to prepare for moving a node.)
*
@param pChildNumber: Show that this node is pChildNumber-th child
* of the parent.
*
This method is prepared for factory methods and it is not
*
recommended to use this method except when user knows the
*
structure of HIR in detail.
**/
public
void
cutParentLink(
int pChildNumber );
//==========
Factory methods to create HIR node ==========//
//====
Factory methods to create terminal nodes ====//
/**
varNode:
*
Make a VarNode instance having Var symbol pVar.
*
@param pVar: Variable symbol to be attached to the node.
*
@return the resultant VarNode.
**/
public
VarNode
varNode(
Var pVar );
// public
ParamNode
//
paramNode( Param pParam ); //##16 DELETED
/**
elemNode:
*
Make an ElemNode instance having Elem symbol pElem.
*
@param pElem: Struct/union element symbol to be attached to the node.
*
@return the resultant ElemNode.
**/
public
ElemNode
elemNode(
Elem pElem ); //##16 not DELETED
/**
subpNode:
*
Make a SubpNode instance having Subp symbol pSubp.
*
@param pSubp: Subprogram symbol to be attached to the node.
*
@return the resultant SubpNode.
**/
public
SubpNode
subpNode(
Subp pSubp );
/**
labelNode:
*
Make a LabelNode instance having Label symbol pLabel.
*
(See labelDef.)
*
@param pLabel: Label symbol to be attached to the node.
*
@return the resultant LabelNode.
**/
public
LabelNode
labelNode(
Label pLabel );
/**
constNode:
*
Make a ConstNode instance having constant symbol pConst.
*
@param pConst: Constant symbol to be attached to the node.
*
@return the resultant ConstNode.
**/
public
ConstNode
constNode(
Const pConst );
/**
intConstNode:
*
Make a ConstNode instance having pIntValue as its value.
*
The constant value is changed to Const symbol and attached to
*
the constant node.
*
@param pIntValue: Integer value to be attached to the node.
*
@return the resultant ConstNode.
**/
public ConstNode
intConstNode(
int pIntValue );
///////////////////////////////////////
S.Fukuda 2002.9.3 begin
/**
offsetConstNode:
*
Make a ConstNode instance having pIntValue as its offset value.
*
The offset value pIntValue is changed to Const symbol and
*
attached to the constant node.
*
@param pIntValue: Offset value to be attached to the node.
*
@return the resultant ConstNode.
**/
public
ConstNode
offsetConstNode(
int pIntValue );
///////////////////////////////////////
S.Fukuda 2002.9.3 end
/**
trueNode:
*
Make a ConstNode instance having boolean true value.
*
@return the true ConstNode.
**/
public
ConstNode
trueNode();
/**
falseNode:
*
Make a ConstNode instance having boolean false value.
*
@return the false ConstNode.
**/
public
ConstNode
falseNode();
/**
symNode:
*
Make a SymNode instance having pSym as attached symbol.
*
This method is used for symbols other than Var, Elem, Subp,
*
Label, and constant.
*
@param pSym: Symbol to be attached to the node.
*
@return the resultant SymNode.
**/
public
SymNode
symNode(
Sym pSym );
/**
nullNode:
*
Make a NullNode instance.
*
@return the NullNode.
**/
public
NullNode
nullNode(
);
/**
labelDef:
*
Make a LabelDef instance that defines the label pLabel.
*
(See labelNode.)
*
@param pLabel: Label symbol to be defined.
*
@return the resultant LabelDef.
**/
public
LabelDef
labelDef(
Label pLabel );
//====
Factory methods to create nonterminal nodes ====//
/** exp:
*
Build unary expression except cast.
*
@param pOperator: unary operator such as OP_NOT, OP_NEG, etc.
* defined in HIR interface.
*
@param pExp1: operand expression.
*
@return the resultant unary expression subtree.
**/
public Exp
exp( int pOperator,
Exp pExp1 );
/** exp:
*
Build binary expression.
*
@param pOperator: binary operator such as OP_ADD, OP_MULT, etc.
* defined in HIR interface.
*
@param pExp1: operand 1 expression.
*
@param pExp2: operand 2 expression.
*
@return the resultant binary expression subtree.
**/
public Exp
exp( int
pOperator, Exp pExp1, Exp pExp2 );
/** exp:
*
Build ternary expression (OP_SELECT, etc.).
*
@param pExp1: operand 1 expression.
*
@param pExp2: operand 2 expression.
*
@param pExp3: operand 3 expression.
*
@return the resultant ternary expression subtree.
**/
public Exp
exp( int
pOperator, Exp pExp1, Exp pExp2, Exp pExp3 );
/**
castExp:
//##10 Use convExp
*
Cast pExp to pType.
**/
//## public
Exp
//##
castExp( Type pType, Exp pExp ); //##10
/**
decayExp: //##12
*
Build an expression that decay a vector to a pointer to vector element,
*
or decay a String into a pointer to Char element.
*
@param pExp: vector variable or string constant.
*
@return decay expression with pointer type.
**/
public Exp
decayExp(
Exp pExp );
/**
undecayExp: //##14
*
Build an expression that undecay a pointer to a vector whose element
*
type is pointed type.
*
@param pPointerExp: pointer expression pointing to the
* first element of the resultant
vector.
*
@param pElemCount: Expression showing element count of
* the resultant vector (constant
expression).
*
@return the vector expression.
**/
public Exp
undecayExp(
Exp pPointerExp, ConstNode pElemCount );
public Exp
//SF030531
undecayExp(
Exp pPointerExp, int pElemCount ); //SF030531
/**
subscriptedExp:
*
Build a subscripted expression.
*
@param pArrayExp: array expression to which subscript is
* to be attached;
* If multi-dimensional subscript is
required, make pArrayExp
* as a subscripted variable and add
more by this method.
*
@param pSubscript: subscript expression.
*
@return subscripted expression node having operation code subsCode.
**/
public
SubscriptedExp
subscriptedExp(
Exp pArrayExp, Exp pSubscript );
/**
subscriptedExp with element size parameter: //##12 To be DELETED
*
Build a subscripted expression.
*
@param pArrayExp: array expression to which subscript is
* to be attached;
* If multi-dimensional subscript is
required, make pArrayExp
* as a subscripted variable and add
more by this method.
*
@param pSubscript: subscript expression.
*
@param pElemSize: array element size which is an offset
* incremented according to subscript
increment.
*
@return subscripted expression node having operation code subsCode.
**/
public
SubscriptedExp
subscriptedExp(
Exp pArrayExp, Exp pSubscript, Exp pElemSize );
/**
qualifiedExp:
* Build a qualified expression.
*
@param pStructUnionExp: expression specifying structure or union
* to qualify.
*
@param pElemNode: An element of pStructUnionExp.
*
@return qualified expression node having operation code qualCode.
**/
public
QualifiedExp
qualifiedExp(
Exp pStructUnionExp, ElemNode pElemNode );
/**
pointedExp:
*
Build a pointed expression.
*
@param pStructUnionExp: expression specifying structure or union
* whose element is to be pointed.
*
@param pElemNode: An element of pStructUnionExp.
*
@return pointed expression node having operation code arrowCode.
**/
public
PointedExp
pointedExp(
Exp pStructUnionExp, ElemNode pElemNode );
/**
contentsExp:
*
Build an expression that gets the contents pointed by pPointerExp.
*
@param pPointerExp: Expression representing a pointer.
*
@return the expression that gets the pointed expression.
**/
public Exp
contentsExp(
Exp pPointerExp );
/**
convExp:
*
Build an expression to convert the type of pExp to pType.
*
@param pType: Type to which pExp is to be changed.
*
@param pExp: Expression to be converted.
*
@return the expression converted to pType.
**/
public Exp
convExp(
Type pType, Exp pExp );
/**
sizeofExp:
*
Build the expression that get the size of pType.
*
@param pType: Type of object.
*
@return the expression representing the size of pType.
**/
public Exp
sizeofExp(
Type pType );
/**
sizeofExp:
*
Build the expression that get the size of pExp.
*
@param pExp: Expression whose size is to be taken.
*
@return the expression representing the size of pExp.
**/
public Exp
sizeofExp(
Exp pExp );
/**
functionExp:
*
Build a function expression node that computes function value.
*
The function may have no return value (void return value).
*
If pFunctionSpec is (addr SubpNode) or SubpNode, then the
*
subprogram represented by it is added to the call list
*
of the current subprogram (symRoot.subpCurrent).
*
@param pFunctionSpec: function specification part which may be either
* a function name (SubpNode), or an
expression specifying
* a function name ((addr SubpNode),
etc.).
*
@param pActualParamList: actual parameter list (made by hirList).
*
@return function expression node having operation code opCall.
**/
public
FunctionExp
functionExp(
Exp pFunctionSpec, IrList pActualParamList );
/**
callStmt:
*
Build a subprogram call statement.
*
Parameters are the same as those of functionExp.
*
@param pSubpSpec: subprogram specification part which may be either
* a subprogram name (SubpNode), or an
expression specifying
* a subprogram name ((addr SubpNode),
etc.).
*
@param pActualParamList: actual parameter list (made by hirList).
*
@return function expression node having operation code opCall.
**/
public
ExpStmt
callStmt(
Exp pSubpSpec, IrList pActualParamList );
/**
assignStmt:
*
Build an assignemnt statement.
*
@param pLeft: left hand side (l-value) expression to which
* the value of expression is to be
assigned.
*
@param pRight: expression (subtree) that is to be assigned
* to pLeftSide.
*
@return the subtree of the built statement
* with statement body operator
assignCode.
**/
public
AssignStmt
assignStmt(
Exp pLeft, Exp pRight );
/**
ifStmt:
*
Build an if-statement with then-part (pThenPart) and
*
else-part (pElsePart).
*
Internal labels (then-label and else-label) are generated
*
to be attached to the then-part and else-part.
*
If pThenPart or pElsePart is null, a LabeledStmt with null
*
statement body is generated as then-part or else-part.
*
(null else-part can be deleted by deleteUselessLabeledStmtOfHir()
*
of coins.flow.DeleteUnusedLabels1.)
*
@param pCondition: conditional expression subtree.
*
@param pThenPart: then-part statement that is executed when
* pCondition is true.
*
@param pElsePart: else-part statement that is executed when
* pCondition is false.
*
@return the subtree of the built statement
* with statement body operator OP_IF;
* If else-part is not given, it is
treated as null.
**/
public
IfStmt
ifStmt(
Exp pCondition, Stmt pThenPart, Stmt pElsePart );
/*
whileStmt (simple):
* Build while-loop statement.
* If it contains break or continue
statement, use getLoopSteplabel()
* or getLoopEndLabel() of LoopStmt
interface to get the label
* to be used in the jump statement
corresponding to the continue
* or break statement. User may also use the general
* whileStmt method that has
pLoopStepLabel and pLoopEndLabel.
* @param pCondition: Loop start
condition expression.
* @param pLoopBody: Loop body to be
repetitively executed.
* @return WhileStmt subtree.
**/
public
WhileStmt
whileStmt(
Exp pCondition, Stmt pLoopBody );
/*
whileStmt (general):
* Build while-loop statement.
* If user want to make a jump statement
corresponding to break or
* continue statement, generate
pLoopStepLabel and pLoopEndLabel by
*
symRoot.symTableCurrent.generateLabel() and use the labels in
* the jump statement.
* @param pLoopBacklabel: Label to be
attached to the
* loop body.
* @param pCondition: Loop start
condition expression.
* @param pLoopBody: Loop body to be
repetitively executed.
* @param pLoopStepLabel: Label to which
continue statement should jump.
* @param pLoopEndLabel: Label to whicjh
break statement should jump.
* @return WhileStmt subtree.
**/
public
WhileStmt
whileStmt(
Label pLoopBackLabel, Exp pCondition, Stmt pLoopBody,
Label pLoopStepLabel,
Label pLoopEndLabel );
/* forStmt
(simple):
* Build for-loop statement.
* If it contains break or continue
statement, use getLoopSteplabel()
* or getLoopEndLabel() of LoopStmt
interface to get the label
* to be used in the jump statement
corresponding to the continue
* or break statement. User may also use the general
* forStmt method that has pLoopStepLabel
and pLoopEndLabel.
* @param pInitStmt: Loop initiation
statement that is executed
* before testing the loop start condition.
* @param pCondition: Loop start
condition expression.
* @param pLoopBody: Loop body to be
repetitively executed.
* @param pStepPart: Step part statement
that is executed
* at the first of the next iteration.
* @return forStmt subtree.
**/
public
ForStmt
forStmt(
Stmt pInitStmt, Exp pCondition,
Stmt pLoopBody, Stmt pStepPart );
/* forStmt
(general):
* Build for-loop statement.
* @param pInitStmt: Loop initiation
statement that is executed
* before testing the loop start condition.
* @param pLoopBacklabel: Label to be
attached to the
* loop body.
* @param pCondition: Loop start
condition expression.
* @param pLoopBody: Loop body to be
repetitively executed.
* @param pLoopStepLabel: Label to which
break statement should jump.
* @param pStepPart: Step part statement
that is executed
* at the first of the next iteration.
* @param pLoopEndLabel: Label to whicjh
break statement should jump.
* @return forStmt subtree.
**/
public
ForStmt
forStmt(
Stmt pInitStmt, Label pLoopBackLabel, Exp pCondition,
Stmt pLoopBody, Label pLoopStepLabel, Stmt pStepPart,
Label pLoopEndLabel );
/*
untilStmt (simple):
* Build until-loop statement.
* If it contains break or continue
statement, use getLoopSteplabel()
* or getLoopEndLabel() of LoopStmt
interface to get the label
* to be used in the jump statement
corresponding to the continue
* or break statement. User may also use the general
* untilStmt method that has pLoopStepLabel
and pLoopEndLabel.
* @param pLoopBody: Loop body to be
repetitively executed.
* @param pCondition: Loop end condition
expression.
* @return untilStmt subtree.
**/
public
UntilStmt
untilStmt(
Stmt pLoopBody, Exp pCondition );
/* untilStmt
(general):
* Build until-loop statement.
* @param pLoopBacklabel: Label to be
attached to the
* loop body.
* @param pLoopBody: Loop body to be
repetitively executed.
* @param pLoopStepLabel: Label to which
break statement should jump.
* @param pCondition: Loop end condition
expression.
* @param pLoopEndLabel: Label to whicjh
break statement should jump.
* @return untilStmt subtree.
**/
public
UntilStmt
untilStmt(
Label pLoopBackLabel, Stmt pLoopBody, Label pLoopStepLabel,
Exp
pCondition, Label pLoopEndLabel );
/*
indexedLoopStmt: //##21
* Build simple indexed-loop
(Fortran-type loop) statement.
* @param pLoopIndex: Simple variable
that is incremented
* by pStepValue at each repetition of the loop
* starting from pStartValue toward pEndValue while
not exceeding
* pEndvalue; Usually it is an integer variable but
* floating variable is also permitted.
* @param pStartValue: Start value of the
loop index.
* @param pEndValue: End limit of the loop
index.
* @param pStepValue: Step value to be
used to increment
* the loop index; It should represent
positive number.
* @param pLoopBody: Loop body to be
repetitively executed.
* @return IndexedLoopStmt subtree.
* @see IndexedLoopStmt.
**/
public
IndexedLoopStmt //##21
indexedLoopStmt(
Var pLoopIndex, Exp pStartValue,
Exp pEndValue, Exp pStepValue, Stmt
pLoopBody );
/*
indexedLoopStmt: //##21
* Build general indexed-loop
(Fortran-type loop) statement.
* @param pLoopIndex: Simple variable
that is incremented or
* decremented by pStepValue at each repetition of
the loop
* starting from pStartValue toward pEndValue while
not crossinging
* pEndvalue; Usually it is an integer variable but
* floating variable is also permitted.
* @param pStartValue: Start value of the
loop index.
* @param pEndValue: End limit of the
loop index.
* @param pStepValue: Step value to be
used to increment
* the loop index; It should represent
positive number.
* @pUpward: true if the loop index is
incremented upward,
* false if it is decremented downward; If
false,
* pEndValue is expected to be less or equal
to pStartValue.
* @param pLoopBody: Loop body to be
repetitively executed.
* @return IndexedLoopStmt subtree.
* @see IndexedLoopStmt.
**/
public
IndexedLoopStmt //##21
indexedLoopStmt(
Var pLoopIndex, Exp pStartValue,
Exp pEndValue, Exp pStepValue, boolean
pUpward, Stmt pLoopBody );
/**
labeledStmt:
*
Build labeled statement using pLabel as its label and
*
pStmt as its statement body.
*
It is recommended to use attachLabel of Stmt
*
except in HIR access methods to make a labeled statement.
*
If you want to use labeledStmt, give null as pStmt parameter.
*
Relations between pStmt and others (such as previousStmt,
*
nextStmt, parentNode) are not kept. If it is necessary to
*
transfer such relations to this LabeledStmt, apply
*
attachLabel method to pStmt instead of calling labeledStmt.
**/
public
LabeledStmt
labeledStmt(
Label pLabel, Stmt pStmt );
/**
blockStmt:
*
Make an instance of block statement that may contain a sequence of
*
statements.
*
It is recommended to make an empty block statement by
*
blockStmt(null) and then add statements by successively calling
*
addLastStmt method of BlockStmt.
*
@param pStmtSequence: statement to be included in BlockStmt.
*
@return the resultant BlockStmt.
**/
public
BlockStmt
blockStmt(
Stmt pStmtSequence );
/**
returnStmt:
*
Build return statement that terminates the execution of
* current subprogram under
construction.
*
@param pReturnValue: return value of function subprogram.
* If the subprogram has no return
value, it is null.
*
@return the subtree of the built statement
* with statement body operator OP_RETURN.
**/
public
ReturnStmt
returnStmt(
Exp pReturnValue );
/**
returnStmt:
*
Build return statement that terminates the execution of
*
current subprogram under construction.
*
It has no return value.
* @return the subtree of the built statement
* with statement body operator
OP_RETURN.
**/
public
ReturnStmt
returnStmt();
/**
jumpStmt:
*
Create a jump statement and increment reference count of pLabelSym.
*
@param pLabelSym: jump target label.
*
@return the created jump statement.
**/
public
JumpStmt
jumpStmt(
Label pLabelSym );
/**
switchStmt:
*
Make a SwitchStmt instance.
*
The jump list pJumpList is a list of pairs of case constant
*
and case label. Following sequence may create a jump list:
* created an empty list by irList() of HIR;
* generate a case-label and attach it to the
statement
* corresponding to the
case-constant;
* add hir.hirSeq(case-constant node,
case-label node) to the list;
* repeat the generation of case-label and
addition to the jump list;
*
@param pSelectExp: Expression to select case statement.
*
@param pJumpList: Jump list that correlate case constant
* and case label.
*
@param pDefaultLabel: label to be attached to default statement part.
*
@param pSwitchBody: Switch statement body that contains statements
* with case-label.
*
@param pEndLabel: Label as the target of jump corresponding to break.
*
@return the resultant SwitchStmt.
**/
public
SwitchStmt
switchStmt(
Exp pSelectExp, IrList pJumpList, Label pDefaultLabel,
Stmt pSwitchBody, Label pEndLabel );
/**
expStmt:
*
Create a statement treating pExp as a statement.
*
ExpStmt appears as loop-condition, call statement, etc.
*
The loop-condition is an expression but it has label, and so,
*
it should be ExpStmt. The call statement is a function call
*
expression treated as a stand alone statement, and so,
*
it should be ExpStmt.
*
@param pExp: expression to be treated as a statement.
*
@return the resultant ExpStmt.
**/
public
ExpStmt
expStmt(
Exp pExp );
/**
nullStmt:
*
Make a statement having NullNode as its statement body.
*
@return the null statement.
**/
public
Stmt
nullStmt();
/**
phiExp:
*
Make a phi expression used in SSA.
*
@param pVar: variable to be selected.
*
@param pLabel: label attached to a basic block from which
* control tranfers.
*
@return PhiExp.
**/
public
PhiExp
phiExp(
Var pVar, Label pLabel );
/**
hirSeq: Make an HirSeq node that have some definite number of
*
children.
*
@param pChild1: Child 1 HIR node.
*
@return HirSeq with one child.
**/
public
HirSeq
hirSeq(
HIR pChild1 );
/**
hirSeq: Make an HirSeq node that have some definite number of
*
children.
*
@param pChild1: Child 1 HIR node.
*
@param pChild2: Child 2 HIR node.
*
@return HirSeq with 2 children.
**/
public
HirSeq
hirSeq(
HIR pChild1, HIR pChild2 );
/**
hirSeq: Make an HirSeq node that have some definite number of
*
children.
*
@param pChild1: Child 1 HIR node.
*
@param pChild2: Child 2 HIR node.
*
@param pChild3: Child 3 HIR node.
*
@return HirSeq with 3 children.
**/
public
HirSeq
hirSeq(
HIR pChild1, HIR pChild2, HIR pChild3 );
/**
hirSeq: Make an HirSeq node that have some definite number of
*
children.
*
@param pChild1: Child 1 HIR node.
*
@param pChild2: Child 2 HIR node.
*
@param pChild3: Child 3 HIR node.
*
@param pChild4: Child 4 HIR node.
*
@return HirSeq with 4 children.
**/
public
HirSeq
hirSeq(
HIR pChild1, HIR pChild2, HIR pChild3, HIR pChild4 );
/**
hirSeq: Make an HirSeq node that have some definite number of
*
children.
*
@param pChild1: Child 1 HIR node.
*
@param pChild2: Child 2 HIR node.
*
@param pChild3: Child 3 HIR node.
*
@param pChild4: Child 4 HIR node.
*
@param pChild5: Child 5 HIR node.
*
@return HirSeq with 5 children.
**/
public
HirSeq
hirSeq(
HIR pChild1, HIR pChild2, HIR pChild3, HIR pChild4, HIR pChild5 );
/**
hirSeq: Make an HirSeq node that have some definite number of
*
children.
*
@param pChild1: Child 1 IR node.
*
@return HirSeq with one IR child.
**/
public
HirSeq
hirSeq( IR
pChild1 );
/**
hirSeq: Make an HirSeq node that have some definite number of
*
children.
*
@param pChild1: Child 1 IR node.
*
@param pChild2: Child 2 IR node.
*
@return HirSeq with 2 IR children.
**/
public
HirSeq
hirSeq( IR
pChild1, IR pChild2 );
//====
Primitive methods to make HIR node ====//
// Not recommmended to be used
except in HIR factory methods.
/**
hirNode:
*
make an HIR node with no operand.
*
hirNode methods are not recommmended to be used except in
*
HIR factory methods.
*
@param pOperator: Operator constant of HIR.
*
@return the HIR node.
**/
public HIR
hirNode(
int pOperator );
public HIR
hirNode(
int pOperator, HIR pOperand1 );
public HIR
hirNode(
int pOperator, HIR pOperand1, HIR pOperand2 );
public HIR
hirNode(
int pOperator, HIR pOperand1, HIR pOperand2,
HIR pOperand3 );
public HIR
hirNode(
int pOperator, HIR pOperand1, HIR pOperand2,
HIR pOperand3, HIR pOperand4 );
/**
hirNodeWithN_sources:
*
Create an HIR node having pOperator as its operator
*
and n null source operands.
*
This method is not recommmended to be used except in
*
HIR factory methods.
*
@param pOperator: operation code of the node to be created.
*
@param pSourceNumber: number of null source operands to be
* attached to the created node.
*
@return the created node having pOperator as its operator and
* null source operands counting up to
pSourceNumber.
**/
public HIR
NodeWithN_sources(
int pOperator, int pSourceNumber );
//====
Methods to link children to HIR node ====//
// Not recommmended to be used
except in HIR factory methods.
public
void setChildren( IR p1, IR p2 );
public
void setChildren( IR p1, IR p2, IR p3 );
public
void setChildren( IR p1, IR p2, IR p3, IR p4 );
public
void setChildren( IR p1, IR p2, IR p3, IR p4, IR p5 );
//======
Methods for manipulating HIR nodes ======//
/**
copyWithOperands:
*
Make a subtree that is the same to this subtree.
*
(Labels are not renamed.)
*
In general, a subtree represents the computation of
*
an operation and also the computation of its operands.
*
Flow information is invalid as for copied subtree and
*
should be computed again if required.
*
If the subtree contains labels, it is recommended to use
*
copyWithOperandsChangingLabels. Note that, IfStmt, LoopStmt
*
(for, while, until, etc.), SwitchStmt
*
contain internal labels and it is recommended to use
*
copyWithOperandsChangingLabels to the subtree that may contain
*
these statements.
*
"this" should be the root node of a subtree contained
*
in a subprogram body. Subprogram body itself should not be copied.
*
@return the subtree made by the copy operation.
**/
HIR
copyWithOperands();
/**
copyWithOperandsChangingLabels:
*
Make a new subtree that is the same to this subtree.
*
If this subtree contains a label definition, then
*
the label is renamed to avoid conflict.
*
Flow information is invalid as for copied subtree and
*
should be computed again if required.
*
"this" should be the root node of a subtree contained
*
in a subprogram body. Subprogram body should not be copied.
*
@param pLabelCorrespondence: label correspondence list;
* It is usually null; If label
correspondence is to be
* specified, it should be of the form
* (IrList (IrList of
original labels) (IrList of new labels) )
* "this" subtree should not
contain labels listed
* in (IrList of new labels) so as
escape from infinite
* replacement loop; This restriction
is satisfied when
* pLabelCorrespondence is null;
* If this parameter is null, it is
computed in this method
* and passed to HirModify subclass
after calling copyWithOperands
* (without changing label).
*
@return the copied subtree with labels changed.
**/
public HIR
copyWithOperandsChangingLabels(
IrList pLabelCorrespondence );
/**
replaceResultOperand:
*
Replace result operand (variable) of "this" node by pOperand.
*
"this" should be a node that can have
*
result operand, that is, "this" should be HIR assign node or
*
LIR store node.
*
If "this" is HIR assign node, its child 1 representing left
*
hand side variable is replaced by pOperand.
*
If "this" is LIR store node, the result variable is replaced
*
by pOperand which may be a simple variable or a register
*
or some other expression representing address of variable. (##2)
*
(This method is moved to IR interface.) //##20
*
@param pOperand: node that takes place of result variable;
* If "this" is HIR node then
it should be HIR node,
* if "this" is LIR node then
it should be LIR node.
**/
// void
//
replaceResultOperand( IR pOperand );
/**
replaceResultVar: //##20 To be DELETED. Use replaceResultOperand
*
Replace result variable of "this" node by pOperand.
*
"this" should be a node that can have variable as its
*
result operand, that is, "this" should be HIR assign node or
*
LIR store node.
*
If "this" is HIR assign node, its child 1 representing left
*
hand side variable is replaced by pOperand.
*
If "this" is LIR store node, the result variable is replaced
*
by pOperand which may be a simple variable or a register
*
or some other expression representing address of variable. (##2)
*
@param pOperand: node that takes place of result variable;
* If "this" is HIR node then
it should be HIR node,
* if "this" is LIR node then
it should be LIR node.
**/
void
replaceResultVar(
IR pOperand ); //##20 To be DELETED. Use replaceResultOperand
/**
replaceOperator: //##20 To be DELETED
*
Replace the operator of "this" node by pOperator.
*
The operator should have the same number and type of operands.
*
It is not recommended to use this method.
*
@param pOperator: operation code for replacement.
**/
void
replaceOperator(
int pOperator ); //##20 To be DELETED.
/**
getClone: //##20
*
Make the clone of this node to get a clone in the situation
*
where clone() can not be used directly.
*
@return the clone of this node.
**/
// public
IR //##20
//
getClone()throws CloneNotSupportedException;
/**
hirClone: //##20
*
Make the clone of this node to get a clone in the situation
*
where clone() can not be used directly.
*
@return the clone of this node.
*/
public HIR
hirClone()throws
CloneNotSupportedException;
/**
isTree: //##16
*
Test if this does not violates tree structure, that is,
*
detect node adherence in branches and
*
handshake miss in parent-child relation.
*
Issues message if some node is encountered twice in
*
the process of traversing this subtree.
*
@return true if this a tree else return false.
**/
public
boolean
isTree(); //##16
/**
isTree: //##20
*
Test if this does not violates tree structure, that is,
* detect node adherence in branches and
*
handshake miss in parent-child relation.
*
Issues message if some node is encountered twice in
*
the process of traversing this subtree.
*
@param pVisitedNodes: Give null in usual case;
* Set of visited nodes is given
when isTree is
* invoked recursively by isTree.
*
@return true if this a tree else return false.
**/
public
boolean
isTree(java.util.Set
pVisitedNodes ); //##20
//====
Iterators to traverse HIR ====//
/**
subpIterator:
*
Make an iterator that traverses all subprogram definitions
*
in the current compile unit.
*
Sequence of SubpDefinition will be get by using next()
*
of the iterator successively.
*
@return the iterator to traverse subprogram definitions.
**/
public
Iterator
subpIterator();
/**
hirIterator:
<PRE>
*
Get an iterator to traverse all nodes or statements under
*
pSubtree. YOu can traverse the subtree by following methods
*
of HirIterator:
* next(): traverse all nodes.
* getNextStmt(): traverse all statements.
* getNextExecutableNode(): traverse
executable nodes only.
*
See HirIterator interface.
*
@param pSubtree: root of the subtree to be traversed.
*
@return teh resultant HirIterator.
</PRE>
**/
public
HirIterator
hirIterator(
IR pSubtree );
//##
public Iterator
//##
lirIterator( IR pSubtree );
//====
Visitor/Acceptor to process HIR ====//
/**
public
void visitHir( HIR pHir);
public
void visitChildren( HIR pHir );
**/
/** accept:
*
Acceptor used in HIR visitor.
*
See HirVisitor, HirVisitorModel1, HirVisitormodel2.
*
@param pVisitor: HirVisitor
**/
public
void
accept(
HirVisitor pVisitor );
//====
Methods to print HIR node ====//
/**
toStringShort
*
Get text string of this node showing node name and index only.
**/
public
String toStringShort();
/**
toStringDetail
*
Get text string of this node showing detail information.
**/
public
String toStringDetail();
/** print:
*
Print this subtree in text format traversing all children
*
of this node.
*
"this" may be any subtree (it may be a leaf node).
*
@param pIndent: number of heading spaces for indentation.
*
@param pDetail: true if print all main attributes,
* false if some detail
attributes are to be omitted.
**/
public
void print( int pIndent, boolean pDetail );
/**
getIndentSace:
*
Get a sequence of spaces specified by pIndent.
*
@param pIndent: number of spaces to be generated.
*
@return a string of spaces.
**/
public
String getIndentSpace( int pIndent );
/**
setIndexNumberToAllNodes:
*
Set sequencial index number to all nodes traversing the subtree
*
rooted by this node.
*
@param pStartNumber: starting value of the index.
*
@return (the last index number) + 1.
**/
public int
setIndexNumberToAllNodes(
int pStartNumber );
//======
Constants available in HIR classes ======//
/**
Operator number
**/
public static final int
OP_PROG = 1, // Program
OP_SUBP_DEF = 2, // SubpDefinition
OP_LABEL_DEF = 3, // LabelDef node
OP_INF = 4, // Information node
OP_CONST
= 5, // ConstNode
OP_SYM = 6, // SymNode
OP_VAR = 7, // VarNode
OP_PARAM
= 8, // VarNode
OP_SUBP = 9, // SubpNode
OP_TYPE = 10, // TypeNode
OP_LABEL
= 11, // LabelNode
OP_ELEM = 12, // ElemNode
// OP_FIELD = 13,
//
OP_CONST - OP_FIELD has a symbol attached
// and it is get bey getSym().
OP_LIST = 14, // List of CompilerObjects
// such as IR nodes and symbols
OP_SEQ = 15, // Sequence of HIR objects //##10
OP_ENCLOSE =
16, // Enclose subexpression
//##9
OP_SUBS = 17, // subscripted variable
OP_INDEX
= 18, // index
modification of subscripted var
OP_QUAL = 19, // struct/union qualification
OP_ARROW
= 20, // pointer
reference
OP_STMT = 21, // Statement code lower. Stmt is
// an abstract class and there is
// no instance having OP_STMT.
OP_LABELED_STMT = 21, // Use the same number as Stmt
// because Stmt is an abstract class.
OP_ASSIGN =
22, // AssignStmt
OP_IF
= 23, // IfStmt
OP_WHILE
= 24, // WhileStmt
OP_FOR =
25, // ForStmt
OP_UNTIL
= 26, // UntilStmt
OP_INDEXED_LOOP = 27, // IndexedLoopStmt (not yet implemented)
OP_LOOP = 28, // General loop other than above
loops. //##21
OP_JUMP = 29, // JumpStmt //##21
OP_SWITCH =
32, // SwitchStmt
OP_CALL = 33, // Subprogram call
OP_RETURN =
34, // ReturnStmt
OP_BLOCK
= 35, // BlockStmt
OP_EXP_STMT = 36, // ExpStmt (expression statement)
//##
OP_NOCHANGE_STMT = 37, //## See
FLAG_NOCHANGE //##10
OP_STMT_UPPER = 37,
OP_ADD = 38,
OP_SUB = 39,
OP_MULT = 41,
OP_DIV = 42,
OP_MOD = 43,
OP_AND = 46,
OP_OR
= 47,
OP_XOR = 48,
OP_CMP_EQ =
51,
OP_CMP_NE =
52,
OP_CMP_GT =
53,
OP_CMP_GE =
54,
OP_CMP_LT =
55,
OP_CMP_LE =
56,
// OP_SHIFT_L = 57, // Deleted because real
machines have not such instr.
OP_SHIFT_LL = 58, // Sfift
logical abd shift arithmetic may be
// properly used by seeing whether operand type
// is unsigned or signed,
but some languages such
// as Java use different operator for logocal
// and arithmetic shift. //##20
OP_SHIFT_R = 59,
OP_SHIFT_RL = 60,
//## OP_LG_NOT = 61, //
Use OP_NOT //##10
OP_NOT = 62,
OP_NEG = 63,
OP_ADDR = 64,
OP_CONV = 65,
OP_DECAY
= 66,
OP_UNDECAY =
67, //##10
OP_CONTENTS = 68,
//## OP_CAST
= 69, //##10
OP_SIZEOF =
70,
//##
OP_NOCHANGE_EXP = 71, // See
FLAG_NOCHANGE //##10
OP_SETDATA =
71, //##15
OP_PHI = 72,
OP_NULL = 73,
//##
OP_ADD_A = 74, // DELETE //##9
//##
OP_SUB_A = 75, // DELETE //##9
OP_OFFSET =
76,
OP_LG_AND =
77,
OP_LG_OR
= 78,
OP_SELECT =
79,
OP_COMMA
= 80,
OP_EQ_ZERO =
81, //##20 !
OP_PRE_INCR = 82,
OP_PRE_DECR = 83,
OP_POST_INCR = 84,
OP_POST_DECR = 85,
OP_ADD_ASSIGN = 86,
OP_SUB_ASSIGN = 87,
OP_MULT_ASSIGN = 88,
OP_DIV_ASSIGN = 89,
OP_MOD_ASSIGN = 90,
OP_SHIFT_L_ASSIGN= 91,
OP_SHIFT_R_ASSIGN= 92,
OP_AND_ASSIGN = 93,
OP_OR_ASSIGN = 94,
OP_XOR_ASSIGN = 95,
//////////////////////////////////// S.Fukuda 2002.9.12 begin
OP_EXPLIST = 96, //
list of datacode
OP_EXPREPEAT = 97 // repeat of datacode
//////////////////////////////////// S.Fukuda 2002.9.12 end
;
public static final String[] // Operator
name for printing.
OP_CODE_NAME = {
"none00 ",
"prog ", "subpDef
", "labelDef", "inf ", "const ",
"sym ",
"var
", "param
", "subp
", "type
",
"label ",
"elem ",
"none13 ",
"list ",
"seq
",
"enclose
", "subs
", "index
", "qual
", "arrow
", //##9
"labeldSt", "assign
", "if ", "while ", "for ",
"until ",
"indxLoop", "loop ", "jump ", "none30 ", //##21
"none31 ",
"switch ",
"call ",
"return ",
"block ",
"expStmt
", "none37 ",
"add
", "sub ", "none40 ", //##12
"mult ", "div ",
"mod
", "none44
", "none45
",
"and ", "or ",
"xor
", "none49
", "none50
",
"cmpEq ",
"cmpNe ",
"cmpGt ",
"cmpGe ",
"cmpLt ",
"cmpLe ",
"non57 ",
"shiftLl ", "shiftR
", "shiftRl ", //##9
"lgNot ",
"not
", "neg ", "addr ", "conv ",
"decay ",
"undecay ", "contents", "cast ", "sizeof ", //##10
"setData
", "phi
", "nullNode", "addA ", "subA ", //##15
"offset ",
"lgAnd ",
"lgOr ",
"select ",
"comma ",
"eqZero ",
"preIncr ", "preDecr ", "postIncr",
"postDecr", //##20
"addAsgn
", "subAsgn ", "multAsgn", "divAsgn ",
"modAsgn ",
"sftLAsgn", "sftRAsgn", "andAsgn ",
"orAsgn ", "xorAsgn
",
////////////////////
S.Fukuda 2002.9.12 begin
"expList
", "expRep "
//////////////////// S.Fukuda 2002.9.12 end
};
public static final String[] // Operator
name with no space
OP_CODE_NAME_DENSE = {
"none00" ,
"prog" , "subpDef" ,
"labelDef", "inf" , "const" ,
"sym"
, "var" , "param" , "subp" , "type" ,
"label" ,
"elem" ,
"none13" ,
"list" ,
"seq"
,
"enclose" , "subs" , "index" , "qual" , "arrow" , //##9
"labeldSt", "assign" , "if" , "while" , "for" ,
"until" ,
"indxLoop", "loop" , "jump" , "none30" , //##21
"none31" ,
"switch" ,
"call" ,
"return" ,
"block" ,
"expStmt" , "nochngSt", "add" ,
"sub"
, "none40" ,
//##9
"mult"
, "div" , "mod" ,
"none44" ,
"none45" ,
"and"
, "or" , "xor" ,
"none49" ,
"none50" ,
"cmpEq" ,
"cmpNe" ,
"cmpGt" ,
"cmpGe" ,
"cmpLt" ,
"cmpLe" ,
"none57" ,
"shiftLl" , "shiftR"
, "shiftRl" , //##9
"lgNot" ,
"not"
, "neg" , "none54" , "addr" ,
"conv"
, "decay" ,
"contents", "cast" , "sizeof" ,
"setData" , "phi" , "nullNode",
"addA" ,
"subA" , //##15
"offset" ,
"lgAnd" ,
"lgOr" ,
"select" ,
"comma" ,
"eqZero" ,
"preIncr" , "preDecr" , "postIncr",
"postDecr", //##20
"addAsgn" , "subAsgn" , "multAsgn",
"divAsgn" , "modAsgn" ,
"sftLAsgn", "sftRAsgn", "andAsgn" ,
"orAsgn" ,
"xorAsgn" ,
//////////////////// S.Fukuda 2002.9.12 begin
"expList" , "expRep"
//////////////////// S.Fukuda 2002.9.12 end
};
/** Flag
numbers applied to HIR nodes
**/
static
final int // Flag numbers used in
setFlag/getFlag.
// They should be a number between 1 to 31.
FLAG_NOCHANGE = 1, // This subtree should not
be
// changed in optimization.
FLAG_C_PTR = 2, // The operation (add, sub) is
// pointer operation peculiar to C.
FLAG_CONST_EXP= 3, // This subtree is a
constant expression.
// (constant, address constant, null,
// sizeof
fixed-size-variable,
// expression whose operands are all
constant
// expression)
FLAG_INIT_BLOCK= 4; // BlockStmt made for setting initial
// values. This flag is set
for BlockStmt
// only. //##20
// Flag numbers 24-31 can
be used in each phase for apbitrary purpose.
// They may be destroyed by
other phases. //##15
//======
Methods to be deleted ======//
/**
attachInfNode: //##16
*
Attach pInfNode as information defined for aribitrary purpose.
*
InfNode is usually built by infNode method.
*
The InfNode instance has information identifier and
*
arbitrary information acceptable by HIR.
*
The structure and meaning of the information is indicated by
*
the information identifier.
*
See coins.ir.hir.InfNode.
*
@param pInfNode: an InfNode instance representing some information.
**/
//##
public void attachInfNode( InfNode pInfNode );
/**
getInfNode: //##16
*
Get the information node indicated by pInfIdInterned.
*
@param pInfIdInterned: information identifier.
* It should be an interned string.
*
@return InfNode having pInfIdInterned as its information ID.
* If no InfNode having pInfIdInterned,
then return null.
**/
//##
public InfNode getInfNode( String pInfIdInterned );
} // HIR
interface