xref: /csrg-svn/usr.bin/pascal/pxp/0.h (revision 20194)
1*20194Smckusick /* static	char *sccsid = "@(#)0.h	2.3 (Berkeley) 05/13/85";*/
22847Speter /* Copyright (c) 1979 Regents of the University of California */
32847Speter /* #define DEBUG */
42847Speter #define	CHAR
52847Speter #define	STATIC
62847Speter /*
72847Speter  * pxp - Pascal execution profiler
82847Speter  *
92847Speter  * Bill Joy
102847Speter  * University of California, Berkeley (UCB)
112847Speter  * Version 1.1 February 1978
122847Speter  */
132847Speter 
142847Speter /*
152847Speter  * Option flags
162847Speter  *
172847Speter  * The following options are recognized on the command line by pxp.
182847Speter  * Only the u, w, and z options here have effect in comments in the
192847Speter  * program; the others are command line only, and unrelated
202847Speter  * to the options with the same designations in comments.
212847Speter  *
222847Speter  *	a	Print all routines in a profile; normally, routines
232847Speter  *		which have never been executed have their bodies suppressed.
242847Speter  *
252847Speter  *	c	Extract profile data from the file core, or the file
262847Speter  *		named after the last argument rather than the file 'pmon.out'.
272847Speter  *		Must be used with z to have an effect.
282847Speter  *
292847Speter  *	d	Suppress declarations
302847Speter  *
312847Speter  *	f	Fully parenthesize expressions.
322847Speter  *
332847Speter  *	j	Left justify all procedures and functions rather than
342847Speter  *		indenting them.
352847Speter  *
362847Speter  *	n	Eject a new page in the listing as each 'include' file
372847Speter  *		is incorporated into the profile.
382847Speter  *
392847Speter  *	o	Put output prettyprint in first argument file
402847Speter  *
412847Speter  *	p	Pretty print a main program without processing
422847Speter  *		the include statements.
432847Speter  *
442847Speter  *	t	Print a table summarizing procedure and function call counts.
452847Speter  *
462847Speter  *	u	Card image mode; only the first 72 chars on a line count.
472847Speter  *
482847Speter  *	w	Suppress certain warning diagnostics.
492847Speter  *
502847Speter  *	z	Generate an execution profile of the program.
512847Speter  *		May also be followed by a list of procedure and function
522847Speter  *		names mixed, if desired, with include file names.
532847Speter  *		Only these procedures and functions, and the contents
542847Speter  *		of the specified include files will then be profiled.
552847Speter  *
562847Speter  *  [23456789]	Use the specified number of spaces for the basic
572847Speter  *		indenting unit in the program.
582847Speter  *
592847Speter  *	_	Underline keywords in the output.
6012412Speter  *
6112412Speter  *	O	remove `others'.  if an `others' label is found in a
6212412Speter  *		case statement the case statement (minus the others case)
6312412Speter  *		is printed as a guarded case statement, and the others case
6412412Speter  *		is the else branch of the guard.  this transformation
6512412Speter  *		causes the case selector to be evaluated twice, a lose
6612412Speter  *		if the selector has side-effects.  this option is only
6712412Speter  *		available if pxp is compiled with RMOTHERS defined.
682847Speter  */
692847Speter 
702847Speter char	all, core, nodecl, full, justify, pmain, stripcomm, table, underline;
712847Speter char	profile, onefile;
7212412Speter #ifdef RMOTHERS
7312412Speter char	rmothers;
7412412Speter #endif RMOTHERS
752847Speter char	*firstname, *stdoutn;
762847Speter #ifdef DEBUG
772847Speter char	fulltrace, errtrace, testtrace, yyunique, typetest;
782847Speter #endif
792847Speter int	unit;
802847Speter 
812847Speter /*
822847Speter  * The flag nojunk means that header lines
832847Speter  * of procedures and functions are to be suppressed
842847Speter  * when the z option is off.
852847Speter  * It is the default when command line z option
862847Speter  * control is specified.
872847Speter  *
882847Speter  * The flag noinclude indicates that include statements are not
892847Speter  * to be processed since we are pretty-printing the contents
902847Speter  * of a single file.
912847Speter  *
922847Speter  * The flag bracket indicates that the source code should be
932847Speter  * bracketed with lines of the form
942847Speter  *	program x(output);
952847Speter  * and
962847Speter  *	begin end.
972847Speter  * so that an include will pretty print without syntax errors.
982847Speter  */
992847Speter char	nojunk, noinclude, bracket;
1002847Speter 
1012847Speter /*
1022847Speter  * IMPORTANT NOTE
1032847Speter  *
1042847Speter  * Many of the following globals are shared by pi and pxp.
1052847Speter  * For more discussion of these see the available documentation
1062847Speter  * on the structure of pi.
1072847Speter  */
1082847Speter 
1092847Speter /*
1102847Speter  * Each option has a stack of 17 option values, with opts giving
1112847Speter  * the current, top value, and optstk the value beneath it.
1122847Speter  * One refers to option `l' as, e.g., opt('l') in the text for clarity.
1132847Speter  */
1142847Speter char	opts[26];
1152847Speter int	optstk[26];
1162847Speter 
1172847Speter #define opt(c) opts[c-'a']
1182847Speter 
1192847Speter /*
1202847Speter  * NOTES ON THE DYNAMIC NATURE OF THE DATA STRUCTURES
1212847Speter  *
1222847Speter  * Pxp uses expandable tables for its string table
1232847Speter  * hash table, and parse tree space.  The following
1242847Speter  * definitions specify the size of the increments
1252847Speter  * for these items in fundamental units so that
1262847Speter  * each uses approximately 1024 bytes.
1272847Speter  */
1282847Speter 
1292847Speter #define	STRINC	1024		/* string space increment */
130*20194Smckusick #define	TRINC	1024		/* tree space increment */
1312847Speter #define	HASHINC	509		/* hash table size in words, each increment */
1322847Speter 
1332847Speter /*
1342847Speter  * The initial sizes of the structures.
1352847Speter  * These should be large enough to profile
1362847Speter  * an "average" sized program so as to minimize
1372847Speter  * storage requests.
1382847Speter  * On a small system or and 11/34 or 11/40
1392847Speter  * these numbers can be trimmed to make the
1402847Speter  * profiler smaller.
1412847Speter  */
1422847Speter #define	ITREE	2000
1432847Speter #define	IHASH	509
1442847Speter 
1452847Speter /*
1462847Speter  * The following limits on hash and tree tables currently
1472847Speter  * allow approximately 1200 symbols and 20k words of tree
1482847Speter  * space.  The fundamental limit of 64k total data space
1492847Speter  * should be exceeded well before these are full.
1502847Speter  */
15112853Speter /*
15212853Speter  * TABLE_MULTIPLIER is for uniformly increasing the sizes of the tables
15312853Speter  */
15412853Speter #ifdef ADDR32
15512853Speter #define TABLE_MULTIPLIER	8
15612853Speter #endif ADDR32
15712853Speter #ifdef ADDR16
15812853Speter #define TABLE_MULTIPLIER	1
15912853Speter #endif ADDR16
16012853Speter #define	MAXHASH	(4 * TABLE_MULTIPLIER)
161*20194Smckusick #define	MAXTREE	(40 * TABLE_MULTIPLIER)
16212853Speter /*
16312853Speter  * MAXDEPTH is the depth of the parse stack.
16412853Speter  * STACK_MULTIPLIER is for increasing its size.
16512853Speter  */
16612853Speter #ifdef ADDR32
16712853Speter #define	STACK_MULTIPLIER	8
16812853Speter #endif ADDR32
16912853Speter #ifdef ADDR16
17012853Speter #define	STACK_MULTIPLIER	1
17112853Speter #endif ADDR16
17212853Speter #define	MAXDEPTH ( 150 * STACK_MULTIPLIER )
1732847Speter 
1742847Speter /*
1752847Speter  * ERROR RELATED DEFINITIONS
1762847Speter  */
1772847Speter 
1782847Speter /*
1792847Speter  * Exit statuses to pexit
1802847Speter  *
1812847Speter  * AOK
1822847Speter  * ERRS		Compilation errors inhibit obj productin
1832847Speter  * NOSTART	Errors before we ever got started
1842847Speter  * DIED		We ran out of memory or some such
1852847Speter  */
1862847Speter #define	AOK	0
1872847Speter #define	ERRS	1
1882847Speter #define	NOSTART	2
1892847Speter #define	DIED	3
1902847Speter 
1912847Speter char	Recovery;
1922847Speter /*
1932847Speter  * The flag eflg is set whenever we have a hard error.
1942847Speter  * The character in errpfx will precede the next error message.
1952847Speter  */
1962847Speter int	eflg;
1972847Speter char	errpfx;
1982847Speter 
1992847Speter #define	setpfx(x)	errpfx = x
2002847Speter 
2012847Speter #define	standard()	setpfx('s')
2022847Speter #define	warning()	setpfx('w')
2032847Speter #define	recovered()	setpfx('e')
2042847Speter #define	quit()		setpfx('Q')
20510739Smckusick #define	continuation()	setpfx(' ')
2062847Speter 
2072847Speter /*
2082847Speter  * SEMANTIC DEFINITIONS
2092847Speter  */
2102847Speter 
2112847Speter #define	NIL	0
2122847Speter 
2132847Speter /*
2142847Speter  * NOCON and SAWCON are flags in the tree telling whether
2152847Speter  * a constant set is part of an expression.
2162847Speter  */
2172847Speter #define	NOCON	0
2182847Speter #define	SAWCON	1
2192847Speter 
2202847Speter /*
2212847Speter  * The variable cbn gives the current block number.
2222847Speter  * The variable lastbn gives the block number before
2232847Speter  * it last changed and is used to know that we were
2242847Speter  * in a nested procedure so that we can print
2252847Speter  *	begin { solve }
2262847Speter  * when solve has nested procedures or functions in it.
2272847Speter  */
2282847Speter int	cbn, lastbn;
2292847Speter 
2302847Speter /*
2312847Speter  * The variable line is the current semantic
2322847Speter  * line and is set in stat.c from the numbers
2332847Speter  * embedded in statement type tree nodes.
2342847Speter  */
2352847Speter int	line;
2362847Speter 
2372847Speter /*
2382847Speter  * The size of the display
2392847Speter  * which defines the maximum nesting
2402847Speter  * of procedures and functions allowed.
2412847Speter  */
2422847Speter #define	DSPLYSZ 20
2432847Speter 
2442847Speter /*
2452847Speter  * Routines which need types
2462847Speter  * other than "integer" to be
2472847Speter  * assumed by the compiler.
2482847Speter  */
24917686Smckusick struct tnode	*tree();
25017686Smckusick char		*skipbl();
2512847Speter int	*hash();
2522847Speter char	*alloc();
2532847Speter long	cntof();
2542847Speter long	nowcnt();
2552847Speter 
2562847Speter /*
25717686Smckusick  *	type cast nils to keep lint happy.
25817686Smckusick  */
25917686Smckusick #define	TR_NIL	((struct tnode *) NIL)
26017686Smckusick 
26117686Smckusick /*
2622847Speter  * Funny structures to use
2632847Speter  * pointers in wild and wooly ways
2642847Speter  */
26517686Smckusick struct cstruct {
2662847Speter 	char	pchar;
2672847Speter };
2682847Speter struct {
2692847Speter 	int	pint;
2702847Speter 	int	pint2;
2712847Speter };
2722847Speter struct {
2732847Speter 	long	plong;
2742847Speter };
2752847Speter struct {
2762847Speter 	double	pdouble;
2772847Speter };
2782847Speter 
2792847Speter #define	OCT	1
2802847Speter #define	HEX	2
2812847Speter 
2822847Speter /*
2832847Speter  * MAIN PROGRAM GLOBALS, MISCELLANY
2842847Speter  */
2852847Speter 
2862847Speter /*
2872847Speter  * Variables forming a data base referencing
2882847Speter  * the command line arguments with the "z" option.
2892847Speter  */
2902847Speter char	**pflist;
2912847Speter int	pflstc;
2922847Speter int	pfcnt;
2932847Speter 
2942847Speter char	*filename;		/* current source file name */
2952847Speter char	*lastname;		/* last file name printed */
2962847Speter long	tvec;			/* mod time of the source file */
2972847Speter long	ptvec;			/* time profiled */
2982847Speter char	printed;		/* current file has been printed */
2992847Speter char	hadsome;		/* had some output */
3002847Speter 
3012847Speter /*
3022847Speter  * PROFILING AND FORMATTING DEFINITIONS
3032847Speter  */
3042847Speter 
3052847Speter /*
3062847Speter  * The basic counter information recording structure.
3072847Speter  * This is global only because people outside
3082847Speter  * the cluster in pmon.c need to know its size.
3092847Speter  */
3102847Speter struct pxcnt {
3112847Speter 	long	ntimes;		/* the count this structure is all about */
3122847Speter 	int	counter;	/* a unique counter number for us */
3132847Speter 	int	gos;		/* global goto count when we hatched */
3142847Speter 	int	printed;	/* are we considered to have been printed? */
3152847Speter } pfcnts[DSPLYSZ];
3162847Speter 
3172847Speter /*
3182847Speter  * The pieces we divide the output line indents into:
3192847Speter  *	line#  PRFN  label:   STAT  999.---|  DECL   text
3202847Speter  */
3212847Speter #define	STAT	0
3222847Speter #define	DECL	1
3232847Speter #define	PRFN	2
3242847Speter 
3252847Speter /*
3262847Speter  * Gocnt records the total number of goto's and
3272847Speter  * cnts records the current counter for generating
3282847Speter  * COUNT operators.
3292847Speter  */
3302847Speter int	gocnt;
3312847Speter int	cnts;
3322847Speter 
3332847Speter #include <stdio.h>
33417686Smckusick #include <sys/types.h>
3352847Speter 
33610737Smckusick typedef enum {FALSE, TRUE} bool;
33710737Smckusick 
3382847Speter #undef putchar
339