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