Pristine Ack-5.5
[Ack-5.5.git] / util / opt / pattern.h
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5 /* $Id: pattern.h,v 2.4 1994/06/24 10:40:30 ceriel Exp $ */
6
7 /*
8  * pattern contains the optimization patterns in an apparently
9  * unordered fashion. All patterns follow each other unaligned.
10  * Each pattern looks as follows:
11  *   Byte 0:    high byte of hash value associated with this pattern.
12  *   Byte 1-2:  index of next pattern with same low byte of hash value.
13  *   Byte 3- :  pattern and replacement.
14  *                First comes the pattern length
15  *                then the pattern opcodes,
16  *                then a boolean expression,
17  *                then the one-byte replacement length
18  *                then the intermixed pattern opcodes and operands or
19  *                0 followed by the one-byte special optimization expression.
20  *   If the DIAGOPT option is set, the optimization is followed
21  *   by the line number in the tables.
22  */
23
24 #undef ALLOWSPECIAL /* Special optimizations allowed */
25
26 #define PO_HASH         0
27 #define PO_NEXT         1
28 #define PO_MATCH        3
29
30 struct exprnode {
31         short ex_operator;
32         short ex_lnode;
33         short ex_rnode;
34 };
35 typedef struct exprnode expr_t;
36 typedef struct exprnode *expr_p;
37
38 /*
39  * contents of .ex_operator
40  */
41
42 #define EX_CON          0
43 #define EX_ARG          1
44 #define EX_CMPEQ        2
45 #define EX_CMPNE        3
46 #define EX_CMPGT        4
47 #define EX_CMPGE        5
48 #define EX_CMPLT        6
49 #define EX_CMPLE        7
50 #define EX_OR2          8
51 #define EX_AND2         9
52 #define EX_OR1          10
53 #define EX_XOR1         11
54 #define EX_AND1         12
55 #define EX_PLUS         13
56 #define EX_MINUS        14
57 #define EX_TIMES        15
58 #define EX_DIVIDE       16
59 #define EX_MOD          17
60 #define EX_LSHIFT       18
61 #define EX_RSHIFT       19
62 #define EX_UMINUS       20
63 #define EX_NOT          21
64 #define EX_COMP         22
65 #define EX_ROM          23
66 #define EX_NOTREG       24
67 #define EX_POINTERSIZE  25
68 #define EX_WORDSIZE     26
69 #define EX_DEFINED      27
70 #define EX_SAMESIGN     28
71 #define EX_SFIT         29
72 #define EX_UFIT         30
73 #define EX_ROTATE       31
74 #define N_EX_OPS        32      /* must be one higher then previous */
75
76
77 /*
78  * Definition of special opcodes used in patterns
79  */
80
81 #define op_pfirst op_LLP
82 #define op_LLP  (op_last+1)
83 #define op_LEP  (op_last+2)
84 #define op_SLP  (op_last+3)
85 #define op_SEP  (op_last+4)
86 #define op_plast op_SEP
87
88 /*
89  * Definition of the structure in which instruction operands
90  * are kept during pattern matching.
91  */
92
93 typedef struct eval eval_t;
94 typedef struct eval *eval_p;
95
96 struct eval {
97         short   e_typ;
98         union {
99                 offset  e_con;
100                 num_p   e_np;
101         } e_v;
102 };
103
104 /*
105  * contents of .e_typ
106  */
107 #define EV_UNDEF        0
108 #define EV_CONST        1
109 #define EV_NUMLAB       2
110 #define EV_FRAG         3       /* and all higher numbers */
111
112 typedef struct iarg iarg_t;
113 typedef struct iarg *iarg_p;
114
115 struct iarg {
116         eval_t  ia_ev;
117         sym_p   ia_sp;
118 };
119
120 /*
121  * The next extern declarations refer to data generated by mktab
122  */
123
124 extern byte pattern[];
125 extern short  lastind;
126 extern iarg_t iargs[];
127 extern byte nparam[];
128 extern bool nonumlab[];
129 extern bool onlyconst[];
130 extern expr_t enodes[];