coins.casttohir
Class ToHirC

java.lang.Object
  extended bycoins.casttohir.ToHirC
All Implemented Interfaces:
TokenId, TypeId, Visitor

public final class ToHirC
extends java.lang.Object
implements Visitor, TypeId, TokenId

Convert ASTree(abstruct syntax tree) to HIR-C.


Field Summary
(package private) static byte[] astPrototype
           
(package private) static int lListNum
           
 
Fields inherited from interface coins.ast.TypeId
ARRAY_T, CHAR_T, CONST_T, DOUBLE_T, ELLIPSIS_T, ENUM_BEGIN, ENUM_END, FLOAT_T, FUNCTION_T, INT_T, LONG_DOUBLE_T, LONG_LONG_T, LONG_T, NO_DIMENSION_T, OFFSET_T, POINTER_T, RESTRICT_T, RETURN_T, S_AUTO, S_EXTERN, S_INLINE, S_NONE, S_REGISTER, S_STATIC, SHORT_T, SIGNED_T, SIZE_T, STRUCT_BEGIN, STRUCT_END, UNION_BEGIN, UNION_END, UNSIGNED_T, VOID_T, VOLATILE_T
 
Fields inherited from interface coins.ast.TokenId
AND_E, ANDAND, ARROW, ASM, AUTO, BAD_TOKEN, BREAK, CASE, CAST_OP, CHAR, CHAR_CONST, COND_OP, CONST, CONTINUE, DEFAULT, DIV_E, DO, DOUBLE, DOUBLE_CONST, ELLIPSIS, ELSE, ENUM, EOF, EQ, EXOR_E, EXTERN, FLOAT, FLOAT_CONST, FOR, FUNCALL, GE, GOTO, IDENTIFIER, IF, IGNORE, INDEX_OP, INLINE, INT, INT_CONST, LE, LONG, LONG_CONST, LONG_DOUBLE_CONST, LONGLONG_CONST, LSHIFT, LSHIFT_E, MINUS_E, MINUSMINUS, MOD_E, MUL_E, MUTABLE, NEQ, OR_E, OROR, PLUS_E, PLUSPLUS, PRAGMA, REGISTER, RESTRICT, RETURN, RSHIFT, RSHIFT_E, SHORT, SIGNED, SIZEOF, SKIP_GCC_ASM, SKIP_GCC_ATTRIBUTE, STATIC, STRING_L, STRING_WL, STRUCT, SWITCH, TYPEDEF, TYPEDEF_NAME, UINT_CONST, ULONG_CONST, ULONGLONG_CONST, UNION, UNSIGNED, VOID, VOLATILE, WHILE
 
Constructor Summary
ToHirC(ToHir tohir)
          Constructor.
 
Method Summary
 void astToHirC(java.io.InputStream stream)
          Create ASTree by ast.Parser.read(), and visit ASTree to create corresponding HIR-C.
 void atAddressExpr(AddressExpr ast)
          Create reference expression.
 void atArithBinaryExpr(ArithBinaryExpr ast)
          Create arithmetic binary expression.
 void atArithUnaryExpr(ArithUnaryExpr ast)
          Create arithmetic unary expression.
 void atArrayExpr(ArrayExpr ast)
          Create array subscript expression.
 void atArrayInitializer(ArrayInitializer ast)
          At array initializer.
 void atAsmExpr(AsmExpr ast)
           
 void atAssignExpr(AssignExpr ast)
          Create assign expression.
 void atASTList(ASTList ast)
          At AST list.
 void atBreakStmnt(BreakStmnt ast)
          Create break statement.
 void atCallExpr(CallExpr ast)
          Create function call expression.
 void atCaseLabel(CaseLabel ast)
          Create case statement.
 void atCastExpr(CastExpr ast)
          Create cast expression.
 void atCommaExpr(CommaExpr ast)
          Create comma expression.
 void atCompoundStmnt(CompoundStmnt ast)
          At compound statement.
 void atConditionalExpr(ConditionalExpr ast)
          Create conditional expression.
 void atConstantExpr(ConstantExpr ast)
          Create constant expression.
 void atContinueStmnt(ContinueStmnt ast)
          Create continue statement.
 void atDeclarator(Declarator ast)
          Create symbol and add into symbol table.
 void atDeclaratorList(DeclaratorList ast)
          At declaration list.
 void atDefaultLabel(DefaultLabel ast)
          Create default statement.
 void atDereferenceExpr(DereferenceExpr ast)
          Create dereference expression.
 void atDoStmnt(DoStmnt ast)
          Create do-while statement.
 void atEnum(Enum ast)
          Create EnumType and add symTableCurrent.
 void atExpressionStmnt(ExpressionStmnt ast)
          Create expression statement.
 void atForStmnt(ForStmnt ast)
          Create for statement.
 void atFunction(Function ast)
          Create function, and add programRoot.
 void atGotoStmnt(GotoStmnt ast)
          Create goto statement.
 void atIfStmnt(IfStmnt ast)
          Create if statement.
 void atMemberExpr(MemberExpr ast)
          Create member-access expression.
 void atNamedLabel(NamedLabel ast)
          Create label statement.
 void atNullStmnt(NullStmnt ast)
          Create null statement.
 void atPair(Pair ast)
          At Pair.
 void atPointerBinaryExpr(PointerBinaryExpr ast)
          Create pointer binary expression.
 void atPostfixExpr(PostfixExpr ast)
          Create postfix expression.
 void atPragma(Pragma ast)
          atPragma changes Pragma to InfStmt whose inf-body is the String specified in the pragma statement.
 void atPrefixExpr(PrefixExpr ast)
          Create prefix expression.
 void atReturnStmnt(ReturnStmnt ast)
          Create return statement.
 void atSizeofExpr(SizeofExpr ast)
          Create sizeof expression.
 void atStringLiteral(StringLiteral ast)
          Create string literal expression.
 void atStruct(Struct ast)
          Create StructType and add to symTableCurrent.
 StructType atStructDeclarator(Struct ast)
           
 void atSwitchStmnt(SwitchStmnt ast)
          Create switch statement.
 void atUnion(Union ast)
          Create UnionType and add symTableCurrent.
 UnionType atUnionDeclarator(Union ast)
          Create UnionType and add symTableCurrent.
 void atVariableExpr(VariableExpr ast)
          Create variable expression.
 void atWhileStmnt(WhileStmnt ast)
          Create while statement.
protected  void message(int level, java.lang.String mes)
          Output debug message.
 Exp pPromotion(Exp e)
          Pointer promotion (selfish naming).
 HIR visit(ASTree ast)
          Visit ASTree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

astPrototype

static final byte[] astPrototype

lListNum

static int lListNum
Constructor Detail

ToHirC

public ToHirC(ToHir tohir)
Constructor.

Parameters:
tohir - Offers cooperation with the object of other packages.
Method Detail

message

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

Parameters:
level - Debug level.
mes - Debug message.

astToHirC

public void astToHirC(java.io.InputStream stream)
               throws java.io.IOException,
                      FatalError
Create ASTree by ast.Parser.read(), and visit ASTree to create corresponding HIR-C.

Parameters:
stream - Input stream.
Throws:
java.io.IOException
FatalError

visit

public HIR visit(ASTree ast)
Visit ASTree.


atASTList

public void atASTList(ASTList ast)
At AST list. Declarator list is processed at upper level. Must not reach here.

Specified by:
atASTList in interface Visitor
Parameters:
ast - ASTList

atPragma

public void atPragma(Pragma ast)
atPragma changes Pragma to InfStmt whose inf-body is the String specified in the pragma statement. A pragma statement may take the form of #pragma kindName pragmaBody where kindName is a String and pragmaBody is a sequence of String composed of Sym and list (sequence of Syms and lists enclosed in parenthesis. The resultant InfStmt is tentatively composed by attaching information by addInf(kindName, pragmaBody). It will be transformed into final form by atInfStmt of coins.casttohir.HirVisit. The reason to take tentative form in ToHirC is symbols appearing in pragmaBody may not yet be defined (registered) in SymTable.

Specified by:
atPragma in interface Visitor
Parameters:
ast - Pragma character string contained in the pragma statement.

atAsmExpr

public void atAsmExpr(AsmExpr ast)
Specified by:
atAsmExpr in interface Visitor

atCompoundStmnt

public void atCompoundStmnt(CompoundStmnt ast)
At compound statement.

Specified by:
atCompoundStmnt in interface Visitor
Parameters:
ast - ASTList

atStruct

public void atStruct(Struct ast)
Create StructType and add to symTableCurrent.

Specified by:
atStruct in interface Visitor
Parameters:
ast - Struct

atStructDeclarator

public StructType atStructDeclarator(Struct ast)

atUnion

public void atUnion(Union ast)
Create UnionType and add symTableCurrent.

Specified by:
atUnion in interface Visitor
Parameters:
ast - Union

atUnionDeclarator

public UnionType atUnionDeclarator(Union ast)
Create UnionType and add symTableCurrent.

Parameters:
ast - Union

atEnum

public void atEnum(Enum ast)
Create EnumType and add symTableCurrent.

Specified by:
atEnum in interface Visitor
Parameters:
ast - Enum

atDeclarator

public void atDeclarator(Declarator ast)
Create symbol and add into symbol table. (= typedef, function prototype, variable declaration)

Specified by:
atDeclarator in interface Visitor
Parameters:
ast - Declarator

atDeclaratorList

public void atDeclaratorList(DeclaratorList ast)
At declaration list. Declarator list is processed at upper level. Must not reach here.

Specified by:
atDeclaratorList in interface Visitor
Parameters:
ast - DeclaratorList

atArrayInitializer

public void atArrayInitializer(ArrayInitializer ast)
At array initializer. Array initializer is processed at upper level. Must not reach here.

Specified by:
atArrayInitializer in interface Visitor
Parameters:
ast - ArrayInitializer

atFunction

public void atFunction(Function ast)
Create function, and add programRoot.

Specified by:
atFunction in interface Visitor
Parameters:
ast - Function

atPair

public void atPair(Pair ast)
At Pair. Pair is processed at upper level. Must not reach here.

Specified by:
atPair in interface Visitor
Parameters:
ast - Pair

atAddressExpr

public void atAddressExpr(AddressExpr ast)
Create reference expression.

Specified by:
atAddressExpr in interface Visitor
Parameters:
ast - AddressExpr

atArithBinaryExpr

public void atArithBinaryExpr(ArithBinaryExpr ast)
Create arithmetic binary expression.

Specified by:
atArithBinaryExpr in interface Visitor
Parameters:
ast - ArithBinaryExpr

atArithUnaryExpr

public void atArithUnaryExpr(ArithUnaryExpr ast)
Create arithmetic unary expression.

Specified by:
atArithUnaryExpr in interface Visitor
Parameters:
ast - ArithUnaryExpr

atArrayExpr

public void atArrayExpr(ArrayExpr ast)
Create array subscript expression.

Specified by:
atArrayExpr in interface Visitor
Parameters:
ast - ArrayExpr

atAssignExpr

public void atAssignExpr(AssignExpr ast)
Create assign expression.

Specified by:
atAssignExpr in interface Visitor
Parameters:
ast - AssignExpr

atCallExpr

public void atCallExpr(CallExpr ast)
Create function call expression.

Specified by:
atCallExpr in interface Visitor
Parameters:
ast - CallExpr

atCastExpr

public void atCastExpr(CastExpr ast)
Create cast expression.

Specified by:
atCastExpr in interface Visitor
Parameters:
ast - CastExpr

atSizeofExpr

public void atSizeofExpr(SizeofExpr ast)
Create sizeof expression.

Specified by:
atSizeofExpr in interface Visitor
Parameters:
ast - SizeofExpr

atCommaExpr

public void atCommaExpr(CommaExpr ast)
Create comma expression.

Specified by:
atCommaExpr in interface Visitor
Parameters:
ast - CommaExpr

atConditionalExpr

public void atConditionalExpr(ConditionalExpr ast)
Create conditional expression.

Specified by:
atConditionalExpr in interface Visitor
Parameters:
ast - ConditionalExpr

atConstantExpr

public void atConstantExpr(ConstantExpr ast)
Create constant expression.

Specified by:
atConstantExpr in interface Visitor
Parameters:
ast - ConstantExpr

atDereferenceExpr

public void atDereferenceExpr(DereferenceExpr ast)
Create dereference expression.

Specified by:
atDereferenceExpr in interface Visitor
Parameters:
ast - DereferenceExpr

atMemberExpr

public void atMemberExpr(MemberExpr ast)
Create member-access expression.

Specified by:
atMemberExpr in interface Visitor
Parameters:
ast - MemberExpr

atPointerBinaryExpr

public void atPointerBinaryExpr(PointerBinaryExpr ast)
Create pointer binary expression.

Specified by:
atPointerBinaryExpr in interface Visitor
Parameters:
ast - PointerBinaryExpr

atPostfixExpr

public void atPostfixExpr(PostfixExpr ast)
Create postfix expression.

Specified by:
atPostfixExpr in interface Visitor
Parameters:
ast - PostfixExpr

atPrefixExpr

public void atPrefixExpr(PrefixExpr ast)
Create prefix expression.

Specified by:
atPrefixExpr in interface Visitor
Parameters:
ast - PrefixExpr

atStringLiteral

public void atStringLiteral(StringLiteral ast)
Create string literal expression.

Specified by:
atStringLiteral in interface Visitor
Parameters:
ast - StringLiteral

atVariableExpr

public void atVariableExpr(VariableExpr ast)
Create variable expression.

Specified by:
atVariableExpr in interface Visitor
Parameters:
ast - VariableExpr

atBreakStmnt

public void atBreakStmnt(BreakStmnt ast)
Create break statement.

Specified by:
atBreakStmnt in interface Visitor

atCaseLabel

public void atCaseLabel(CaseLabel ast)
Create case statement.

Specified by:
atCaseLabel in interface Visitor
Parameters:
ast - CaseLabel

atContinueStmnt

public void atContinueStmnt(ContinueStmnt ast)
Create continue statement.

Specified by:
atContinueStmnt in interface Visitor
Parameters:
ast - ContinueStmnt

atDefaultLabel

public void atDefaultLabel(DefaultLabel ast)
Create default statement.

Specified by:
atDefaultLabel in interface Visitor
Parameters:
ast - DefaultLabel

atDoStmnt

public void atDoStmnt(DoStmnt ast)
Create do-while statement.

Specified by:
atDoStmnt in interface Visitor
Parameters:
ast - DoStmnt

atExpressionStmnt

public void atExpressionStmnt(ExpressionStmnt ast)
Create expression statement.

Specified by:
atExpressionStmnt in interface Visitor
Parameters:
ast - ExpressionStmnt

atForStmnt

public void atForStmnt(ForStmnt ast)
Create for statement.

Specified by:
atForStmnt in interface Visitor
Parameters:
ast - ForStmnt

atGotoStmnt

public void atGotoStmnt(GotoStmnt ast)
Create goto statement.

Specified by:
atGotoStmnt in interface Visitor
Parameters:
ast - GotoStmnt

atIfStmnt

public void atIfStmnt(IfStmnt ast)
Create if statement.

Specified by:
atIfStmnt in interface Visitor
Parameters:
ast - IfStmnt

atNamedLabel

public void atNamedLabel(NamedLabel ast)
Create label statement.

Specified by:
atNamedLabel in interface Visitor
Parameters:
ast - NamedLabel

atNullStmnt

public void atNullStmnt(NullStmnt ast)
Create null statement.

Specified by:
atNullStmnt in interface Visitor
Parameters:
ast - NullStmnt

atReturnStmnt

public void atReturnStmnt(ReturnStmnt ast)
Create return statement.

Specified by:
atReturnStmnt in interface Visitor
Parameters:
ast - ReturnStmnt

atSwitchStmnt

public void atSwitchStmnt(SwitchStmnt ast)
Create switch statement.

Specified by:
atSwitchStmnt in interface Visitor
Parameters:
ast - SwitchStmnt

atWhileStmnt

public void atWhileStmnt(WhileStmnt ast)
Create while statement.

Specified by:
atWhileStmnt in interface Visitor
Parameters:
ast - WhileStmnt

pPromotion

public Exp pPromotion(Exp e)
Pointer promotion (selfish naming). Convert expression has VectorType/SubpType to PointerType.

Parameters:
e - Expression which has VectorType/SubpType.
Returns:
Expression which has PointerType.