|
|
1.1 root 1: /* static char ID[] = "@(#) optim.h: 1.7 1/20/84"; */
2:
3: /* machine independent include file for code improver */
4:
5: #include <stdio.h>
6: #include <ctype.h>
7: #include "defs"
8:
9: #ifndef MEMFCN /* remove after 5.0 when memcpy is in all UNIX releases */
10: #define memcpy strncpy
11: #endif
12:
13: #ifndef MAXOPS
14: #define MAXOPS 1
15: #endif
16:
17: /* booleans */
18:
19: typedef int boolean;
20: #define false 0
21: #define true 1
22:
23: /* predefined "opcodes" for various nodes */
24:
25: #define GHOST 0 /* temporary, to prevent linking node in */
26: #define TAIL 0 /* end of text list */
27: #define MISC 1 /* miscellaneous instruction */
28: #define FILTER 2 /* nodes to be filtered before optim */
29:
30: #ifdef LIVEDEAD
31: extern void ldanal();
32: #if LIVEDEAD - 0 < 2
33: #undef LIVEDEAD
34: #define LIVEDEAD 16
35: #endif
36: #endif
37:
38: /* structure of each text node */
39:
40: typedef struct node {
41: struct node *forw; /* forward link */
42: struct node *back; /* backward link */
43: char *ops[MAXOPS + 1]; /* opcode or label and operand field strings */
44: #ifdef IDVAL
45: IDTYPE uniqid; /* unique identification for this node */
46: #endif
47: unsigned short op; /* operation code */
48: #ifdef LIVEDEAD
49: unsigned
50: nlive:LIVEDEAD, /* registers used by instruction */
51: ndead:LIVEDEAD; /* registers set but not used by instruction */
52: #endif
53: #ifdef USERDATA
54: USERTYPE userdata; /* user-defined data for this node */
55: #endif
56: } NODE;
57:
58: #define opcode ops[0]
59: #define op1 ops[1]
60: #if MAXOPS > 1
61: #define op2 ops[2]
62: #if MAXOPS > 2
63: #define op3 ops[3]
64: #if MAXOPS > 3
65: #define op4 ops[4]
66: #if MAXOPS > 4
67: #define op5 ops[5]
68: #if MAXOPS > 5
69: #define op6 ops[6]
70: #endif
71: #endif
72: #endif
73: #endif
74: #endif
75:
76: /* structure of non-branch text reference node */
77:
78: typedef struct ref {
79: char *lab; /* label referenced */
80: struct ref *nextref; /* link to next ref */
81: } REF;
82:
83: /* externals */
84:
85: extern NODE n0; /* header node of text list */
86: extern NODE ntail; /* trailer node of text list */
87: extern NODE *lastnode; /* pointer to last node on text list */
88: extern REF *lastref; /* pointer to last label reference */
89:
90: extern int dflag; /* display live-dead info */
91: extern int sflag; /* statistics (on stderr) */
92: extern int ndisc; /* # of instructions discarded */
93: extern int ninst; /* total # of instructions */
94: extern int npass; /* # of times through this function */
95: extern int fnum; /* # of this function */
96:
97: extern NODE *Saveop();
98: extern boolean same(), sameaddr();
99: extern char *getspace(), *strcpy(), *memcpy(), *xalloc(), *memset();
100: extern void addref(), fatal(), filter(), init(), optim(), prtext(), xfree();
101:
102: /* user-supplied functions or macros */
103:
104: #ifndef getp
105: extern char *getp();
106: #endif
107: #ifndef newlab
108: extern char *newlab();
109: #endif
110:
111: #define saveop(opn, str, len, op) \
112: (void) Saveop((opn), (str), (unsigned)(len), (op))
113: #define addtail(p) /* superfluous */
114: #define appinst() /* superfluous */
115: #define appmisc(str, len) saveop(0, (str), (len), MISC)
116: #define appfl(str, len) saveop(0, (str), (len), FILTER)
117: #define applbl(str, len) \
118: (setlab(Saveop(0, (str), (unsigned)(len), MISC)), --ninst)
119: #define ALLN(p) p = n0.forw; p != &ntail; p = p->forw
120: #define PRINTF (void) printf
121: #define FPRINTF (void) fprintf
122: #define SPRINTF (void) sprintf
123: #define PUTCHAR(c) (void) putchar(c)
124: #define DELNODE(p) ((p)->back->forw = (p)->forw, \
125: (p)->forw->back = (p)->back)
126: #define APPNODE(p, q) PUTNODE((p), (q), back, forw)
127: #define INSNODE(p, q) PUTNODE((p), (q), forw, back)
128: #define PUTNODE(p, q, f, b) ((p)->f = (q), (p)->b = (q)->b, \
129: (q)->b = (q)->b->f = (p))
130: #define GETSTR(type) (type *) getspace(sizeof(type))
131: #define COPY(str, len) ((len) != 0 ? memcpy(getspace(len), str, (int)(len)) : str)
132: #ifndef ISLABREF
133: #define ISLABREF(p) 0
134: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.