1 /****************************************************************************
2 *
3 *                            Open Watcom Project
4 *
5 *    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
6 *
7 *  ========================================================================
8 *
9 *    This file contains Original Code and/or Modifications of Original
10 *    Code as defined in and that are subject to the Sybase Open Watcom
11 *    Public License version 1.0 (the 'License'). You may not use this file
12 *    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
13 *    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
14 *    provided with the Original Code and Modifications, and is also
15 *    available at www.sybase.com/developer/opensource.
16 *
17 *    The Original Code and all software distributed under the License are
18 *    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
19 *    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
20 *    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
21 *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
22 *    NON-INFRINGEMENT. Please see the License for the specific language
23 *    governing rights and limitations under the License.
24 *
25 *  ========================================================================
26 *
27 * Description:  interface to expression evaluator
28 *
29 ****************************************************************************/
30 
31 
32 #ifndef EXPREVAL_H
33 #define EXPREVAL_H
34 
35 /* v2.11: EXPR_UNDEF changed to EXPR_ERROR, value -1 */
36 
37 enum exprtype {
38     EXPR_EMPTY = EMPTY,
39     EXPR_ERROR = ERROR, /* undefined type when error occures or result is undefined */
40     EXPR_CONST = 0,     /* constant; note that "label1 - label2" -> constant */
41     EXPR_ADDR,          /* e.g. "foo", "seg foo" and "offset foo", also indirect mem ops */
42     EXPR_REG,           /* register */
43     EXPR_FLOAT          /* v2.05: float */
44 };
45 
46 /* argument types accepted by unary operators */
47 
48 enum oparg_types {
49     AT_TYPE  = 0x01, /* type */
50     AT_LABEL = 0x02, /* label (direct memory) */
51     AT_IND   = 0x04, /* indirect memory */
52     AT_REG   = 0x08, /* register */
53     AT_FIELD = 0x10, /* struct field */
54     AT_NUM   = 0x20, /* number */
55     AT_BF    = 0x40, /* bitfield and record types */
56     AT_UNDEF = 0x80, /* undefined label */
57     AT_FLOAT = 0x100,/* float constant */
58     AT_CONST = AT_TYPE | AT_NUM,
59     AT_TL    = AT_TYPE | AT_LABEL,
60     AT_TLN   = AT_TYPE | AT_LABEL | AT_NUM,
61     AT_TLF   = AT_TYPE | AT_LABEL | AT_FIELD,
62     AT_TLFN  = AT_TYPE | AT_LABEL | AT_FIELD | AT_NUM,
63     AT_TBF   = AT_TYPE | AT_BF,
64     AT_LF    = AT_LABEL| AT_FIELD,
65     AT_LIF   = AT_LABEL| AT_IND | AT_FIELD,
66     AT_LFN   = AT_LABEL| AT_FIELD | AT_NUM,
67     AT_TLR   = AT_TYPE | AT_LABEL | AT_REG,
68     AT_ALL   = AT_TYPE | AT_LABEL | AT_IND | AT_REG | AT_FIELD | AT_NUM | AT_UNDEF | AT_BF | AT_FLOAT
69 };
70 
71 /* expression, returned by expression evaluator */
72 
73 struct expr {
74     union {                         /* value of expression */
75         struct {
76             int_32  value;
77             int_32  hvalue;
78         };
79         struct {
80             uint_64 llvalue;
81             uint_64 hlvalue;
82         };
83         uint_32     uvalue;
84         int_64      value64;
85         float       fvalue;
86         int         st_idx;         /* EXPR_REG: index if reg is ST */
87         uint_8      chararray[16];
88     };
89     union {
90         struct asm_tok *quoted_string; /* for EXPR_CONST + quoted strings only */
91         struct asm_tok *float_tok;     /* for EXPR_FLOAT only */
92     };
93     struct asm_tok  *base_reg;      /* EXPR_ADDR: base register token */
94                                     /* EXPR_REG: register token */
95     struct asm_tok  *idx_reg;       /* EXPR_ADDR: index register token */
96     union {
97         struct asm_tok  *label_tok; /* token holding the label (EXPR_ADDR, used for overrides, inside expreval only) */
98         struct asm_tok  *type_tok;  /* v2.10: token if target type of a label (SYM_STACK, MT_PTR) is to be stored */
99     };
100     struct asm_tok  *override;      /* EXPR_ADDR: token holding the override label */
101                                     /* or segment register */
102     enum special_token instr;       /* operator token */
103 
104     enum exprtype   kind;           /* Type of expression */
105     enum memtype    mem_type;       /* memory type if expr is a memory ref. */
106     uint_8          scale;          /* EXPR_ADDR: scaling factor 1, 2, 4, or 8 - 386 code only */
107     uint_8          Ofssize;        /* 16,32,64 bit if MT_NEAR, MT_FAR */
108     union {
109         uint_8      flags1;
110         struct {
111             unsigned indirect : 1;  /* indirect addressing used */
112             unsigned explicit : 1;  /* Whether expression type explicitly given (to be removed!) */
113             unsigned is_abs   : 1;  /* external ABS */
114             unsigned is_type  : 1;  /* constant is a type */
115             unsigned is_opattr: 1;  /* current operator is OPATTR */
116             unsigned negative : 1;  /* for EXPR_FLOAT only */
117             //unsigned ftype    : 1;  /* for EXPR_FLOAT only (float type) */
118             unsigned assumecheck: 1;/* v2.07: for ASSUMEd std registers */
119             unsigned is_dot: 1;     /* v2.10: see regression test dotop5.asm */
120         };
121     };
122     struct asym     *sym;   /* label used */
123     struct asym     *mbr;   /* struct member */
124     struct asym     *type;  /* for DOT operator. Must be last (see TokenAssign)! */
125 };
126 
127 /* flags for last argument of EvalOperand() */
128 enum expr_flags {
129     EXPF_NOERRMSG  = 1,  /* suppress error messages */
130     EXPF_NOUNDEF   = 2,  /* don't accept or create undefined symbols */
131     EXPF_ONEOPND   = 4,  /* private flag, used inside expreval.c only */
132     EXPF_IN_SQBR   = 8   /* private flag, used inside expreval.c only */
133 };
134 
135 extern ret_code     EvalOperand( int *, struct asm_tok[], int, struct expr *, uint_8 );
136 extern void         ExprEvalInit( void );
137 extern ret_code     EmitConstError( const struct expr * );
138 
139 #endif
140