home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dosdisas.zip / dccsrcoo.zip / ast.h < prev    next >
Text File  |  1997-04-09  |  5KB  |  160 lines

  1. /* 
  2.  *$Log:    ast.h,v $
  3.  * Revision 1.8  94/03/15  11:39:53  cifuente
  4.  * condOpJCond[] array.
  5.  * 
  6.  * Revision 1.7  94/02/22  15:19:24  cifuente
  7.  * Code generation is done.
  8.  * 
  9.  * Revision 1.6  93/12/13  12:26:02  cifuente
  10.  * Interprocedural live analysis finished.
  11.  * 
  12.  * Revision 1.5  93/11/10  17:30:01  cifuente
  13.  * Procedure header, locals
  14.  * 
  15.  * Revision 1.4  93/11/01  15:06:02  cifuente
  16.  * Finds byte and integer expressions
  17.  * 
  18.  * Revision 1.3  93/10/25  11:00:07  cifuente
  19.  * New SYNTHETIC instructions for d/u analysis
  20.  * 
  21.  * Revision 1.2  93/10/11  11:45:26  cifuente
  22.  * New routines for conditional and arithmetic expressions
  23.  * 
  24.  * File:    ast.h
  25.  * Purpose: definition of the abstract syntax tree ADT.
  26.  * Date:    September 1993
  27.  */
  28.  
  29.  
  30. #define operandSize        20
  31.  
  32. /* The following definitions and types define the Conditional Expression
  33.  * attributed syntax tree, as defined by the following EBNF:
  34.     CondExp     ::= CondTerm AND CondTerm | CondTerm
  35.     CondTerm    ::= (CondFactor op CondFactor)
  36.     CondFactor  ::= Identifier | ! CondFactor
  37.     Identifier  ::= globalVar | register | localVar | parameter | constant
  38.     op          ::= <= | < | = | != | > | >=
  39.  */
  40.  
  41. /* Conditional Expression enumeration nodes and operators               */
  42. typedef enum {
  43.     BOOLEAN_OP,            /* condOps              */
  44.     NEGATION,           /* not (2's complement)    */ 
  45.     ADDRESSOF,            /* addressOf (&)        */
  46.     DEREFERENCE,        /* contents of (*)         */
  47.     IDENTIFIER,         /* {register | local | param | constant | global} */
  48.     /* The following are only available to C programs */
  49.     POST_INC,            /* ++ (post increment)    */
  50.     POST_DEC,            /* -- (post decrement)    */
  51.     PRE_INC,            /* ++ (pre increment)    */
  52.     PRE_DEC,            /* -- (pre decrement)    */
  53. } condNodeType;
  54.  
  55. typedef enum {
  56.     GLOB_VAR,       /* global variable  */
  57.     REGISTER,       /* register         */
  58.     LOCAL_VAR,      /* negative disp    */
  59.     PARAM,          /* positive disp    */
  60.     GLOB_VAR_IDX,    /* indexed global variable *//*** should merge w/glob-var*/
  61.     CONSTANT,        /* constant         */
  62.     STRING,            /* string            */
  63.     LONG_VAR,        /* long variable    */
  64.     FUNCTION,        /* function            */
  65.     OTHER           /* other **** tmp solution */
  66. } condId;
  67.  
  68. typedef enum {
  69.         /* For conditional expressions */
  70.     LESS_EQUAL = 0, /* <=   */
  71.     LESS,           /* <    */ 
  72.     EQUAL,          /* ==   */
  73.     NOT_EQUAL,      /* !=   */
  74.     GREATER,        /* >    */
  75.     GREATER_EQUAL,  /* >=   */
  76.         /* For general expressions */
  77.     AND,            /* &    */
  78.     OR,                /* |    */
  79.     XOR,            /* ^    */
  80.     NOT,            /* ~    */  /* 1's complement */
  81.     ADD,            /* +    */
  82.     SUB,            /* -    */
  83.     MUL,            /* *    */
  84.     DIV,            /* /    */
  85.     SHR,            /* >>    */
  86.     SHL,            /* <<    */
  87.     MOD,            /* %    */
  88.     DBL_AND,        /* &&    */
  89.     DBL_OR,            /* ||    */
  90.     DUMMY,            /*      */
  91. } condOp;
  92.  
  93. /* High-level BOOLEAN conditions for iJB..iJNS icodes */
  94. static condOp condOpJCond[12] = {LESS, LESS_EQUAL, GREATER_EQUAL, GREATER, 
  95.                                 EQUAL, NOT_EQUAL, LESS, GREATER_EQUAL, 
  96.                                 LESS_EQUAL, GREATER, GREATER_EQUAL, LESS};
  97.  
  98. static condOp invCondOpJCond[12] = {GREATER_EQUAL, GREATER, LESS, LESS_EQUAL,
  99.                                     NOT_EQUAL, EQUAL, GREATER_EQUAL, LESS, 
  100.                                     GREATER, LESS_EQUAL, LESS, GREATER_EQUAL};
  101.  
  102.  
  103. /* Register types */
  104. typedef enum {
  105.     BYTE_REG, WORD_REG
  106. } regType;
  107.  
  108.  
  109. typedef struct
  110. {
  111.     condId           idType;
  112.     regType          regiType;  /* for REGISTER only                */
  113.     union _idNode {
  114.         Int          regiIdx;   /* index into localId, REGISTER        */
  115.         Int          globIdx;   /* index into symtab for GLOB_VAR   */
  116.         Int          localIdx;  /* idx into localId,  LOCAL_VAR        */
  117.         Int          paramIdx;  /* idx into args symtab, PARAMS     */
  118.         Int             idxGlbIdx;    /* idx into localId, GLOB_VAR_IDX   */
  119.         struct _kte    {            /* for CONSTANT only                    */
  120.             dword    kte;       /*   value of the constant            */
  121.             byte     size;        /*   #bytes size constant             */
  122.         }             kte;
  123.         dword         strIdx;    /* idx into image, for STRING         */
  124.         Int             longIdx;    /* idx into LOCAL_ID table, LONG_VAR*/
  125.         struct _call {            /* for FUNCTION only                */
  126.             struct _proc     *proc;
  127.             struct _STKFRAME *args;
  128.         }             call;
  129.         struct {                /* for OTHER; tmp struct            */
  130.             byte     seg;       /*   segment                        */
  131.             byte     regi;      /*   index mode                     */
  132.             int16    off;       /*   offset                         */
  133.         }            other;
  134.     }                idNode;
  135. } IDENTTYPE;
  136.  
  137.  
  138. /* Expression data type */
  139. typedef struct _condExpr {
  140.     condNodeType            type;       /* Conditional Expression Node Type */
  141.     union _exprNode {                   /* Different cond expr nodes        */
  142.         struct {                        /* for BOOLEAN_OP                    */
  143.             condOp           op;
  144.             struct _condExpr *lhs;
  145.             struct _condExpr *rhs;
  146.         }                    boolExpr;
  147.         struct _condExpr    *unaryExp;  /* for NEGATION,ADDRESSOF,DEREFERENCE*/
  148.         IDENTTYPE             ident;     /* for IDENTIFIER                   */
  149.     }                        expr;  
  150. } COND_EXPR;
  151.  
  152. /* Sequence of conditional expression data type */
  153. /*** NOTE: not used at present ****/
  154. typedef struct _condExpSeq {
  155.     COND_EXPR           *expr;
  156.     struct _condExpSeq  *next;
  157. } SEQ_COND_EXPR;
  158.  
  159.  
  160.