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