]> git.sur5r.net Git - cc65/blob - src/cc65/expr.h
New optimization
[cc65] / src / cc65 / expr.h
1 /*
2  * expr.h
3  *
4  * Ullrich von Bassewitz, 21.06.1998
5  */
6
7
8
9 #ifndef EXPR_H
10 #define EXPR_H
11
12
13
14 #include "datatype.h"
15
16
17
18 /*****************************************************************************/
19 /*                                   data                                    */
20 /*****************************************************************************/
21
22
23
24 /* Defines for the flags field of the expression descriptor */
25 #define E_MREG          0x0110  /* Special: Expression is primary register */
26 #define E_MGLOBAL       0x0080  /* Reference to static variable */
27 #define E_MLOCAL        0x0040  /* Reference to local variable (stack offset) */
28 #define E_MCONST        0x0020  /* Constant value */
29 #define E_MEXPR         0x0010  /* Result is in primary register */
30 #define E_MEOFFS        0x0011  /* Base is in primary register, const offset */
31
32 #define E_MCTYPE        0x0007  /* Type of a constant */
33 #define E_TCONST        0x0000  /* Constant */
34 #define E_TGLAB         0x0001  /* Global label */
35 #define E_TLIT          0x0002  /* Literal of some kind */
36 #define E_TLOFFS        0x0003  /* Constant stack offset */
37 #define E_TLLAB         0x0004  /* Local label */
38 #define E_TREGISTER     0x0005  /* Register variable */
39
40 /* Defines for the test field of the expression descriptor */
41 #define E_CC            0x0001  /* expr has set cond codes apropos result value */
42 #define E_FORCETEST     0x0002  /* if expr has NOT set CC, force a test */
43 #define E_LOGL          0x0004  /* expr has left a logical value (1 or 0) in AX */
44 #define E_XINV          0x0008  /* flip this bit to invert sense of test */
45 #define E_TEST          0x0010  /* We're evaluating a test */
46
47 /* Describe the result of an expression */
48 struct expent {
49     struct SymEntry*    Sym;     /* Symbol table entry if known */
50     type*               e_tptr;  /* Type array of expression */
51     long                e_const; /* Value if expression constant */
52     unsigned            e_flags;
53     unsigned            e_test;  /* */
54     unsigned long       e_name;  /* Name or label number */
55 };
56
57
58
59 /*****************************************************************************/
60 /*                                   code                                    */
61 /*****************************************************************************/
62
63
64
65 void doasm (void);
66 /* This function parses ASM statements. The syntax of the ASM directive
67  * looks like the one defined for C++ (C has no ASM directive), that is,
68  * a string literal in parenthesis.
69  */
70
71 unsigned assignadjust (type* lhst, struct expent* rhs);
72 /* Adjust the type of the right hand expression so that it can be assigned to
73  * the type on the left hand side. This function is used for assignment and
74  * for converting parameters in a function call. It returns the code generator
75  * flags for the operation.
76  */
77
78 void exprhs (unsigned flags, int k, struct expent *lval);
79 /* Put the result of an expression into the primary register */
80
81 void expression1 (struct expent* lval);
82 /* Evaluate an expression on level 1 (no comma operator) and put it into
83  * the primary register
84  */
85
86 void expression (struct expent* lval);
87 /* Evaluate an expression and put it into the primary register */
88
89 int evalexpr (unsigned flags, int (*f) (struct expent*), struct expent* lval);
90 /* Will evaluate an expression via the given function. If the result is a
91  * constant, 0 is returned and the value is put in the lval struct. If the
92  * result is not constant, exprhs is called to bring the value into the
93  * primary register and 1 is returned.
94  */
95
96 void constexpr (struct expent* lval);
97 /* Get a constant value */
98
99 void intexpr (struct expent* lval);
100 /* Get an integer expression */
101
102 void boolexpr (struct expent* lval);
103 /* Get a boolean expression */
104
105 void test (unsigned label, int cond);
106 /* Generate code to perform test and jump if false. */
107
108 int hie1 (struct expent* lval);
109 /* Parse first level of expression hierarchy. */
110
111 int hie0 (struct expent* lval);
112 /* Parse comma operator (highest level of expression hierarchy) */
113
114 void DefineData (struct expent* lval);
115 /* Output a data definition for the given expression */
116
117
118
119 /* End of expr.h */
120
121 #endif
122
123
124
125