xref: /csrg-svn/usr.bin/pascal/pxp/0.h (revision 10739)
1 /* static	char *sccsid = "@(#)0.h	1.3 (Berkeley) 02/06/83";*/
2 /* Copyright (c) 1979 Regents of the University of California */
3 /* #define DEBUG */
4 #define	CHAR
5 #define	STATIC
6 /*
7  * pxp - Pascal execution profiler
8  *
9  * Bill Joy
10  * University of California, Berkeley (UCB)
11  * Version 1.1 February 1978
12  */
13 
14 /*
15  * Option flags
16  *
17  * The following options are recognized on the command line by pxp.
18  * Only the u, w, and z options here have effect in comments in the
19  * program; the others are command line only, and unrelated
20  * to the options with the same designations in comments.
21  *
22  *	a	Print all routines in a profile; normally, routines
23  *		which have never been executed have their bodies suppressed.
24  *
25  *	c	Extract profile data from the file core, or the file
26  *		named after the last argument rather than the file 'pmon.out'.
27  *		Must be used with z to have an effect.
28  *
29  *	d	Suppress declarations
30  *
31  *	f	Fully parenthesize expressions.
32  *
33  *	j	Left justify all procedures and functions rather than
34  *		indenting them.
35  *
36  *	n	Eject a new page in the listing as each 'include' file
37  *		is incorporated into the profile.
38  *
39  *	o	Put output prettyprint in first argument file
40  *
41  *	p	Pretty print a main program without processing
42  *		the include statements.
43  *
44  *	t	Print a table summarizing procedure and function call counts.
45  *
46  *	u	Card image mode; only the first 72 chars on a line count.
47  *
48  *	w	Suppress certain warning diagnostics.
49  *
50  *	z	Generate an execution profile of the program.
51  *		May also be followed by a list of procedure and function
52  *		names mixed, if desired, with include file names.
53  *		Only these procedures and functions, and the contents
54  *		of the specified include files will then be profiled.
55  *
56  *  [23456789]	Use the specified number of spaces for the basic
57  *		indenting unit in the program.
58  *
59  *	_	Underline keywords in the output.
60  */
61 
62 char	all, core, nodecl, full, justify, pmain, stripcomm, table, underline;
63 char	profile, onefile;
64 char	*firstname, *stdoutn;
65 #ifdef DEBUG
66 char	fulltrace, errtrace, testtrace, yyunique, typetest;
67 #endif
68 int	unit;
69 
70 /*
71  * The flag nojunk means that header lines
72  * of procedures and functions are to be suppressed
73  * when the z option is off.
74  * It is the default when command line z option
75  * control is specified.
76  *
77  * The flag noinclude indicates that include statements are not
78  * to be processed since we are pretty-printing the contents
79  * of a single file.
80  *
81  * The flag bracket indicates that the source code should be
82  * bracketed with lines of the form
83  *	program x(output);
84  * and
85  *	begin end.
86  * so that an include will pretty print without syntax errors.
87  */
88 char	nojunk, noinclude, bracket;
89 
90 /*
91  * IMPORTANT NOTE
92  *
93  * Many of the following globals are shared by pi and pxp.
94  * For more discussion of these see the available documentation
95  * on the structure of pi.
96  */
97 
98 /*
99  * Each option has a stack of 17 option values, with opts giving
100  * the current, top value, and optstk the value beneath it.
101  * One refers to option `l' as, e.g., opt('l') in the text for clarity.
102  */
103 char	opts[26];
104 int	optstk[26];
105 
106 #define opt(c) opts[c-'a']
107 
108 /*
109  * NOTES ON THE DYNAMIC NATURE OF THE DATA STRUCTURES
110  *
111  * Pxp uses expandable tables for its string table
112  * hash table, and parse tree space.  The following
113  * definitions specify the size of the increments
114  * for these items in fundamental units so that
115  * each uses approximately 1024 bytes.
116  */
117 
118 #define	STRINC	1024		/* string space increment */
119 #define	TRINC	512		/* tree space increment */
120 #define	HASHINC	509		/* hash table size in words, each increment */
121 
122 /*
123  * The initial sizes of the structures.
124  * These should be large enough to profile
125  * an "average" sized program so as to minimize
126  * storage requests.
127  * On a small system or and 11/34 or 11/40
128  * these numbers can be trimmed to make the
129  * profiler smaller.
130  */
131 #define	ITREE	2000
132 #define	IHASH	509
133 
134 /*
135  * The following limits on hash and tree tables currently
136  * allow approximately 1200 symbols and 20k words of tree
137  * space.  The fundamental limit of 64k total data space
138  * should be exceeded well before these are full.
139  */
140 #define	MAXHASH	4
141 #define	MAXTREE	30
142 #define	MAXDEPTH 150
143 
144 /*
145  * ERROR RELATED DEFINITIONS
146  */
147 
148 /*
149  * Exit statuses to pexit
150  *
151  * AOK
152  * ERRS		Compilation errors inhibit obj productin
153  * NOSTART	Errors before we ever got started
154  * DIED		We ran out of memory or some such
155  */
156 #define	AOK	0
157 #define	ERRS	1
158 #define	NOSTART	2
159 #define	DIED	3
160 
161 char	Recovery;
162 /*
163  * The flag eflg is set whenever we have a hard error.
164  * The character in errpfx will precede the next error message.
165  */
166 int	eflg;
167 char	errpfx;
168 
169 #define	setpfx(x)	errpfx = x
170 
171 #define	standard()	setpfx('s')
172 #define	warning()	setpfx('w')
173 #define	recovered()	setpfx('e')
174 #define	quit()		setpfx('Q')
175 #define	continuation()	setpfx(' ')
176 
177 /*
178  * SEMANTIC DEFINITIONS
179  */
180 
181 #define	NIL	0
182 
183 /*
184  * NOCON and SAWCON are flags in the tree telling whether
185  * a constant set is part of an expression.
186  */
187 #define	NOCON	0
188 #define	SAWCON	1
189 
190 /*
191  * The variable cbn gives the current block number.
192  * The variable lastbn gives the block number before
193  * it last changed and is used to know that we were
194  * in a nested procedure so that we can print
195  *	begin { solve }
196  * when solve has nested procedures or functions in it.
197  */
198 int	cbn, lastbn;
199 
200 /*
201  * The variable line is the current semantic
202  * line and is set in stat.c from the numbers
203  * embedded in statement type tree nodes.
204  */
205 int	line;
206 
207 /*
208  * The size of the display
209  * which defines the maximum nesting
210  * of procedures and functions allowed.
211  */
212 #define	DSPLYSZ 20
213 
214 /*
215  * Routines which need types
216  * other than "integer" to be
217  * assumed by the compiler.
218  */
219 int	*tree();
220 int	*hash();
221 char	*alloc();
222 long	cntof();
223 long	nowcnt();
224 
225 /*
226  * Funny structures to use
227  * pointers in wild and wooly ways
228  */
229 struct {
230 	char	pchar;
231 };
232 struct {
233 	int	pint;
234 	int	pint2;
235 };
236 struct {
237 	long	plong;
238 };
239 struct {
240 	double	pdouble;
241 };
242 
243 #define	OCT	1
244 #define	HEX	2
245 
246 /*
247  * MAIN PROGRAM GLOBALS, MISCELLANY
248  */
249 
250 /*
251  * Variables forming a data base referencing
252  * the command line arguments with the "z" option.
253  */
254 char	**pflist;
255 int	pflstc;
256 int	pfcnt;
257 
258 char	*filename;		/* current source file name */
259 char	*lastname;		/* last file name printed */
260 long	tvec;			/* mod time of the source file */
261 long	ptvec;			/* time profiled */
262 char	printed;		/* current file has been printed */
263 char	hadsome;		/* had some output */
264 
265 /*
266  * PROFILING AND FORMATTING DEFINITIONS
267  */
268 
269 /*
270  * The basic counter information recording structure.
271  * This is global only because people outside
272  * the cluster in pmon.c need to know its size.
273  */
274 struct pxcnt {
275 	long	ntimes;		/* the count this structure is all about */
276 	int	counter;	/* a unique counter number for us */
277 	int	gos;		/* global goto count when we hatched */
278 	int	printed;	/* are we considered to have been printed? */
279 } pfcnts[DSPLYSZ];
280 
281 /*
282  * The pieces we divide the output line indents into:
283  *	line#  PRFN  label:   STAT  999.---|  DECL   text
284  */
285 #define	STAT	0
286 #define	DECL	1
287 #define	PRFN	2
288 
289 /*
290  * Gocnt records the total number of goto's and
291  * cnts records the current counter for generating
292  * COUNT operators.
293  */
294 int	gocnt;
295 int	cnts;
296 
297 #include <stdio.h>
298 
299 typedef enum {FALSE, TRUE} bool;
300 
301 #undef putchar
302