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