|
|
1.1 root 1: /*
2: * h/cc1.h
3: * Definitions, macros, structures and types
4: * used by the portable code generator (cc1).
5: */
6:
7: #include <stdio.h>
8: #include <setjmp.h>
9: #ifdef vax
10: #include "INC$LIB:mch.h"
11: #include "INC$LIB:host.h"
12: #include "INC$LIB:cc1mch.h"
13: #include "INC$LIB:ops.h"
14: #include "INC$LIB:var.h"
15: #include "INC$LIB:varmch.h"
16: #include "INC$LIB:opcode.h"
17: #include "INC$LIB:stream.h"
18: #else
19: #include "mch.h"
20: #include "host.h"
21: #include "cc1mch.h"
22: #include "ops.h"
23: #include "var.h"
24: #include "varmch.h"
25: #include "opcode.h"
26: #include "stream.h"
27: #endif
28:
29: /*
30: * Table sizes, etc.
31: */
32: #define NSTORE 20 /* # of entries in storelist */
33: #define NNSW 16 /* Nested switches */
34: #define NTNODE 350 /* Tree nodes */
35: #define NSHASH 64 /* Symbol hash buckets */
36: #define SHMASK 077 /* Mask for above */
37:
38: /*
39: * This structure is used to
40: * buffer the case constants and the
41: * case labels.
42: */
43: typedef struct cases {
44: ival_t c_val; /* Value */
45: int c_lab; /* Label */
46: } CASES;
47:
48: /*
49: * Code patterns.
50: * There is an array of these for
51: * most of the operators.
52: * The 'pat' table holds a pointer
53: * to the first one and the number
54: * of entries.
55: */
56: typedef struct pat {
57: INDEX p_flag; /* Some flags */
58: INDEX p_ntype; /* Node type */
59: REGNAME p_ntemp; /* Temp. spec. */
60: REGNAME p_ltemp; /* Left. spec. */
61: REGNAME p_rtemp; /* Right spec. */
62: REGNAME p_result; /* Result spec. */
63: INDEX p_lflag; /* Flags for left subtree */
64: INDEX p_ltype; /* Types for left subtree */
65: INDEX p_rflag; /* Flags for right subtree */
66: INDEX p_rtype; /* Types for right subtree */
67: char *p_macro; /* The macro */
68: #if !TINY
69: int p_fname; /* Pattern file name */
70: int p_fline; /* Pattern file line */
71: #endif
72: } PAT;
73:
74: /*
75: * Pattern index.
76: * The 'pat' table (one of these)
77: * is indexed by operator number to
78: * get the patterns for the op.
79: */
80: typedef struct patx {
81: PAT *px_pp; /* Pointer to patterns */
82: int px_npat; /* # of patterns */
83: } PATX;
84:
85: /* Flags */
86: #define PEFFECT ((PATFLAG)0x0001) /* Effect */
87: #define PLVALUE ((PATFLAG)0x0002) /* Lvalue load */
88: #define PRVALUE ((PATFLAG)0x0004) /* Rvalue load */
89: #define PFNARG ((PATFLAG)0x0008) /* Function argument */
90: #define PEQ ((PATFLAG)0x0010) /* Conditionals */
91: #define PNE ((PATFLAG)0x0020)
92: #define PGT ((PATFLAG)0x0040)
93: #define PGE ((PATFLAG)0x0080)
94: #define PLE ((PATFLAG)0x0100)
95: #define PLT ((PATFLAG)0x0200)
96: #define PUGT ((PATFLAG)0x0400)
97: #define PUGE ((PATFLAG)0x0800)
98: #define PULE ((PATFLAG)0x1000)
99: #define PULT ((PATFLAG)0x2000)
100:
101: #define P_SLT ((PATFLAG)0x4000) /* Share left temp */
102: #define P_SRT ((PATFLAG)(unsigned)0x8000) /* Share right temp */
103: #define P_SHR (P_SLT|P_SRT) /* Any share */
104:
105: /*
106: * Macros.
107: */
108: #define M_ORG 200 /* Origin of non opcodes */
109:
110: #define M_END 200 /* End of macro */
111: #define M_OP0 201 /* Op 0 */
112: #define M_OP1 202 /* Op 1 */
113: #define M_OP2 203 /* Op 2 */
114: #define M_AL 204 /* Address, left */
115: #define M_AR 205 /* Address, right */
116: #define M_RL 206 /* Register, left */
117: #define M_RR 207 /* Register, right */
118: #define M_R 208 /* Temp. register */
119: #define M_HI 209 /* Hi prefix */
120: #define M_LO 210 /* Lo prefix */
121: #define M_EMASK 211 /* Field extract mask */
122: #define M_LAB 212 /* Label */
123: #define M_LAB0 213 /* Generate label 0 */
124: #define M_LAB1 214 /* Generate label 1 */
125: #define M_NSE 215 /* No side effects prefix */
126: #define M_IFR 216 /* If relational */
127: #define M_IFV 217 /* If value */
128: #define M_CMASK 218 /* Field clear mask */
129: #define M_SIZE 219 /* Size */
130: #define M_BITL 220 /* Extract bit # left side */
131: #define M_BITR 221 /* Extract bit # right side */
132: #define M_ENDIF 222 /* End if */
133: #define M_DLAB0 223 /* Define label 0 */
134: #define M_DLAB1 224 /* Define label 1 */
135: #define M_ICON 225 /* Ival_t constant */
136: #define M_REGNO 226 /* Register */
137: #define M_AN 227 /* Address form of node */
138: #define M_TOS 228 /* Top of stack address */
139: #define M_STAR 229 /* Indirection on address */
140: #define M_GID 230 /* Global name for calling routines */
141: #define M_IFE 231 /* If effect */
142: #define M_REL0 232 /* Rel. 0 */
143: #define M_REL1 233 /* Rel. 1 */
144: #define M_LREL0 234 /* Long rel. 0 */
145: #define M_LREL1 235 /* Long rel. 1 */
146: #define M_LREL2 236 /* Long rel. 2 */
147: #define M_CALL 237 /* Call opcode */
148: #define M_LCON 238 /* Lval_t constant */
149: #define M_TN 239 /* Type of node op */
150: #define M_TR 240 /* Type of right */
151: #define M_TL 241 /* Type of left */
152: #define M_SSIZE 242 /* Stack size */
153: #define M_JMP1 243 /* One byte jump */
154: #define M_JMP2 244 /* Two byte jump */
155: #define M_JMPB 245 /* One byte jump back relative */
156:
157: /*
158: * Symbol structure.
159: */
160: typedef struct sym {
161: struct sym *s_fp; /* Hash link */
162: char s_id[]; /* Name */
163: } SYM;
164:
165: /*
166: * This is the tree node structure. All
167: * nodes are the same size; this makes it much easier
168: * for the modify phases to make a node of one type into a
169: * node of any other type. Note the use of fully qualified
170: * references into the structure; this makes the structure
171: * compile correctly under either Bell or UCB structure
172: * member rules. Noce names for the members is provided
173: * by the block of #define's at the end of the declaration.
174: */
175: typedef struct tree {
176: int t_op; /* Operation */
177: TYPE t_type; /* Type */
178: COST t_cost; /* Cost of evaluation */
179: PAT *t_patp; /* Pattern */
180: int t_size; /* Size */
181: FLAG t_flag; /* Flags */
182: REGNAME t_treg; /* Temp reg */
183: REGNAME t_rreg; /* Result reg */
184: PREGSET t_used; /* Used */
185: union {
186: struct {
187: struct tree *t_xlp;
188: union {
189: struct tree *t_xrp;
190: struct {
191: char t_xfw;
192: char t_xfb;
193: } t_1;
194: } t_2;
195: } t_3;
196: ival_t t_xival;
197: lval_t t_xlval;
198: dval_t t_xdval;
199: struct {
200: sizeof_t t_xoffs;
201: int t_xseg;
202: union {
203: int t_xlab;
204: SYM *t_xsp;
205: } t_4;
206: } t_5;
207: int t_xreg;
208: } t_6;
209: } TREE;
210:
211: #define t_lp t_6.t_3.t_xlp /* Left tree */
212: #define t_rp t_6.t_3.t_2.t_xrp /* Right tree */
213: #define t_width t_6.t_3.t_2.t_1.t_xfw /* Width of field in bits */
214: #define t_base t_6.t_3.t_2.t_1.t_xfb /* Base bit */
215: #define t_ival t_6.t_xival /* ICON value */
216: #define t_lval t_6.t_xlval /* LCON value */
217: #define t_dval t_6.t_xdval /* DCON value */
218: #define t_offs t_6.t_5.t_xoffs /* Offset from label */
219: #define t_seg t_6.t_5.t_xseg /* Segment of label */
220: #define t_label t_6.t_5.t_4.t_xlab /* Local label */
221: #define t_sp t_6.t_5.t_4.t_xsp /* Global symbol */
222: #define t_reg t_6.t_xreg /* REG register number */
223:
224: /*
225: * Register table.
226: */
227: typedef struct reg {
228: KIND r_lvalue; /* Kinds in lvalue sense */
229: KIND r_rvalue; /* Kinds in rvalue sense */
230: int r_goal; /* Goal for TREG loading */
231: REGNAME r_enpair; /* Enclosing pair name */
232: REGNAME r_hihalf; /* Hi half */
233: REGNAME r_lohalf; /* Lo half */
234: PREGSET r_phys; /* Physical regs */
235: } REGDESC;
236:
237: /*
238: * Per type info.
239: */
240: typedef struct pertype {
241: REGNAME p_frreg; /* Function return reg */
242: char p_frcxt; /* Return context */
243: char p_size; /* Size of temp, function arg */
244: char p_incr; /* Real size */
245: TYPESET p_type; /* Match type bits */
246: KIND p_kind; /* Kind of register needed */
247: KIND p_pair; /* Kind for a pair */
248: } PERTYPE;
249:
250: /*
251: * Contexts.
252: * Used to indicate the context of a computation.
253: * Passed to all (modify, selection, output) phases of
254: * the code generator.
255: */
256: #define MEFFECT 0 /* Effect only */
257: #define MLVALUE 1 /* Left value context */
258: #define MRVALUE 2 /* Right value context */
259: #define MFNARG 3 /* Function argument */
260: #define MLADDR 4 /* Address, left side */
261: #define MRADDR 5 /* Address, right side */
262: #define MRETURN 6 /* Return value of function */
263: #define MSWITCH 7 /* Switch value */
264: #define MINIT 8 /* Initialisor */
265: #define MFLOW 9 /* Flow of control */
266: #define MPASSED 10 /* For modify3.c tables */
267: #define MJUNK 11 /* Ditto */
268: #define MHARD 12 /* Ditto */
269: #define MEQ 13 /* == */
270: #define MNE 14 /* != */
271: #define MGT 15 /* > signed */
272: #define MGE 16 /* >= signed */
273: #define MLE 17 /* <= signed */
274: #define MLT 18 /* < signed */
275: #define MUGT 19 /* > unsigned */
276: #define MUGE 20 /* >= unsigned */
277: #define MULE 21 /* <= unsigned */
278: #define MULT 22 /* < unsigned */
279:
280: /*
281: * Macros.
282: */
283: #define isleaf(x) ((x) < MIOBASE)
284: #define isbool(x) (x==ANDAND || x==OROR || x==NOT || (x>=EQ && x<=ULT))
285: #define snap(tp) snaptree((tp), 0)
286: #define isrelop(x) ((x)>=EQ && (x)<=ULT)
287: #define isurelop(x) ((x)>=UGT && (x)<=ULT)
288: #define isncon(x) ((x)<LID)
289: #define iscon(x) ((x)<LID || (x)==ADDR)
290: #define isconvert(op) ((op)==CONVERT || (op)==CAST)
291: #define isrealreg(r) ((r) < NRREG)
292: #define binit() (curbusy = regbusy)
293: #define islvadr(pflag) ((pflag&(T_ADR|T_LV))==(T_ADR|T_LV))
294: #define isrvadr(pflag) ((pflag&(T_ADR|T_LV))==T_ADR)
295: #define isadr(flag) ((flag&T_ADR) != 0)
296: #define isofs(flag) ((flag&T_OFS) != 0)
297: #define isind(flag) ((flag&T_INDIR) != 0)
298: #define ishlvadr(pflag) ((pflag&(T_ADR|T_LV|T_INDIR))==(T_ADR|T_LV))
299: #define isflow(op) (op==NOT || op==ANDAND || op==OROR)
300:
301: /*
302: * These bit packing macros are used
303: * to pack the subgoal table used by the
304: * leaf insert routines.
305: */
306: #define ndown(l,r) (((l)<<5) | (r))
307: #define getri(n) ((n)&037)
308: #define getli(n) (((n)>>5)&037)
309:
310: /*
311: * Functions and variables.
312: */
313: /* Arrays. */
314: #if !YATC
315: extern char file[];
316: extern FLAG flagcache[];
317: extern char fliprel[];
318: extern char *gidcache[];
319: extern SYM *hash1[];
320: extern char id[];
321: extern ival_t ivalcache[];
322: extern int ldtab[];
323: extern lval_t lvalcache[];
324: extern char macros[];
325: extern char module[];
326: #if !TINY
327: extern char *namecache[];
328: #endif
329: extern unsigned char optab[][3];
330: extern char otherel[];
331: extern PATFLAG patcache[];
332: extern PATX patx[];
333: extern PERTYPE pertype[];
334: extern REGDESC reg[];
335: extern TREE *storelist[];
336: extern TYPESET typecache[];
337: extern char wtype[];
338:
339: /* Functions. */
340: extern TREE *alocnode();
341: extern int amd();
342: extern TREE *basenode();
343: extern lval_t constcvt();
344: extern TREE *copynode();
345: extern TREE *findoffs();
346: extern TREE *fold1();
347: extern TREE *foldaddr();
348: extern SYM *gidpool();
349: extern lval_t grabnval();
350: extern TREE *gvalnode();
351: extern TREE *ivalnode();
352: extern TREE *leafnode();
353: extern TREE *leftnode();
354: extern TREE *lvalnode();
355: extern TREE *makenode();
356: extern TREE *modargs();
357: extern TREE *modcall();
358: extern TREE *modefld();
359: extern TREE *modfold();
360: extern TREE *modify();
361: extern TREE *modleaf();
362: extern TREE *modlfld();
363: extern TREE *modmul();
364: extern TREE *modoper();
365: extern TREE *modsasg();
366: extern TREE *modtree();
367: extern TREE *modtruth();
368: extern TREE *modxfun();
369: extern TREE *ripout();
370: extern int snapf();
371: extern TREE *talloc();
372: extern TREE *tempnode();
373: extern TREE *treeget();
374: extern TREE *treeget1();
375:
376: /* Variables. */
377: #if !TINY
378: extern int mflag;
379: extern int oflag;
380: extern int sflag;
381: #endif
382: extern CASES *cases;
383: extern PREGSET curbusy;
384: extern ival_t curtemp;
385: extern PREGSET curxreg;
386: extern int labgen;
387: extern int line;
388: extern ival_t maxauto;
389: extern PREGSET maxbusy;
390: extern ival_t maxtemp;
391: extern int nstorelist;
392: extern FILE *ofp;
393: #endif
394: #if OVERLAID
395: extern jmp_buf death;
396: #endif
397: extern FILE *ifp;
398: extern int nerr;
399: extern int oldseg;
400: extern char *passname;
401:
402: /* end of h/cc1.h */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.