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