xref: /original-bsd/usr.bin/pascal/pxp/0.h (revision 0b685140)
1 /* static	char *sccsid = "@(#)0.h	1.1 (Berkeley) 03/02/81";*/
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 
176 /*
177  * SEMANTIC DEFINITIONS
178  */
179 
180 #define	NIL	0
181 
182 /*
183  * NOCON and SAWCON are flags in the tree telling whether
184  * a constant set is part of an expression.
185  */
186 #define	NOCON	0
187 #define	SAWCON	1
188 
189 /*
190  * The variable cbn gives the current block number.
191  * The variable lastbn gives the block number before
192  * it last changed and is used to know that we were
193  * in a nested procedure so that we can print
194  *	begin { solve }
195  * when solve has nested procedures or functions in it.
196  */
197 int	cbn, lastbn;
198 
199 /*
200  * The variable line is the current semantic
201  * line and is set in stat.c from the numbers
202  * embedded in statement type tree nodes.
203  */
204 int	line;
205 
206 /*
207  * The size of the display
208  * which defines the maximum nesting
209  * of procedures and functions allowed.
210  */
211 #define	DSPLYSZ 20
212 
213 /*
214  * Routines which need types
215  * other than "integer" to be
216  * assumed by the compiler.
217  */
218 int	*tree();
219 int	*hash();
220 char	*alloc();
221 long	cntof();
222 long	nowcnt();
223 
224 /*
225  * Funny structures to use
226  * pointers in wild and wooly ways
227  */
228 struct {
229 	char	pchar;
230 };
231 struct {
232 	int	pint;
233 	int	pint2;
234 };
235 struct {
236 	long	plong;
237 };
238 struct {
239 	double	pdouble;
240 };
241 
242 #define	OCT	1
243 #define	HEX	2
244 
245 /*
246  * MAIN PROGRAM GLOBALS, MISCELLANY
247  */
248 
249 /*
250  * Variables forming a data base referencing
251  * the command line arguments with the "z" option.
252  */
253 char	**pflist;
254 int	pflstc;
255 int	pfcnt;
256 
257 char	*filename;		/* current source file name */
258 char	*lastname;		/* last file name printed */
259 long	tvec;			/* mod time of the source file */
260 long	ptvec;			/* time profiled */
261 char	printed;		/* current file has been printed */
262 char	hadsome;		/* had some output */
263 
264 /*
265  * PROFILING AND FORMATTING DEFINITIONS
266  */
267 
268 /*
269  * The basic counter information recording structure.
270  * This is global only because people outside
271  * the cluster in pmon.c need to know its size.
272  */
273 struct pxcnt {
274 	long	ntimes;		/* the count this structure is all about */
275 	int	counter;	/* a unique counter number for us */
276 	int	gos;		/* global goto count when we hatched */
277 	int	printed;	/* are we considered to have been printed? */
278 } pfcnts[DSPLYSZ];
279 
280 /*
281  * The pieces we divide the output line indents into:
282  *	line#  PRFN  label:   STAT  999.---|  DECL   text
283  */
284 #define	STAT	0
285 #define	DECL	1
286 #define	PRFN	2
287 
288 /*
289  * Gocnt records the total number of goto's and
290  * cnts records the current counter for generating
291  * COUNT operators.
292  */
293 int	gocnt;
294 int	cnts;
295 
296 #include <stdio.h>
297 
298 #undef putchar
299