1*12412Speter /* static char *sccsid = "@(#)0.h 1.4 (Berkeley) 05/12/83";*/ 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. 60*12412Speter * 61*12412Speter * O remove `others'. if an `others' label is found in a 62*12412Speter * case statement the case statement (minus the others case) 63*12412Speter * is printed as a guarded case statement, and the others case 64*12412Speter * is the else branch of the guard. this transformation 65*12412Speter * causes the case selector to be evaluated twice, a lose 66*12412Speter * if the selector has side-effects. this option is only 67*12412Speter * 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; 72*12412Speter #ifdef RMOTHERS 73*12412Speter char rmothers; 74*12412Speter #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 */ 1302847Speter #define TRINC 512 /* 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 */ 1512847Speter #define MAXHASH 4 1522847Speter #define MAXTREE 30 1532847Speter #define MAXDEPTH 150 1542847Speter 1552847Speter /* 1562847Speter * ERROR RELATED DEFINITIONS 1572847Speter */ 1582847Speter 1592847Speter /* 1602847Speter * Exit statuses to pexit 1612847Speter * 1622847Speter * AOK 1632847Speter * ERRS Compilation errors inhibit obj productin 1642847Speter * NOSTART Errors before we ever got started 1652847Speter * DIED We ran out of memory or some such 1662847Speter */ 1672847Speter #define AOK 0 1682847Speter #define ERRS 1 1692847Speter #define NOSTART 2 1702847Speter #define DIED 3 1712847Speter 1722847Speter char Recovery; 1732847Speter /* 1742847Speter * The flag eflg is set whenever we have a hard error. 1752847Speter * The character in errpfx will precede the next error message. 1762847Speter */ 1772847Speter int eflg; 1782847Speter char errpfx; 1792847Speter 1802847Speter #define setpfx(x) errpfx = x 1812847Speter 1822847Speter #define standard() setpfx('s') 1832847Speter #define warning() setpfx('w') 1842847Speter #define recovered() setpfx('e') 1852847Speter #define quit() setpfx('Q') 18610739Smckusick #define continuation() setpfx(' ') 1872847Speter 1882847Speter /* 1892847Speter * SEMANTIC DEFINITIONS 1902847Speter */ 1912847Speter 1922847Speter #define NIL 0 1932847Speter 1942847Speter /* 1952847Speter * NOCON and SAWCON are flags in the tree telling whether 1962847Speter * a constant set is part of an expression. 1972847Speter */ 1982847Speter #define NOCON 0 1992847Speter #define SAWCON 1 2002847Speter 2012847Speter /* 2022847Speter * The variable cbn gives the current block number. 2032847Speter * The variable lastbn gives the block number before 2042847Speter * it last changed and is used to know that we were 2052847Speter * in a nested procedure so that we can print 2062847Speter * begin { solve } 2072847Speter * when solve has nested procedures or functions in it. 2082847Speter */ 2092847Speter int cbn, lastbn; 2102847Speter 2112847Speter /* 2122847Speter * The variable line is the current semantic 2132847Speter * line and is set in stat.c from the numbers 2142847Speter * embedded in statement type tree nodes. 2152847Speter */ 2162847Speter int line; 2172847Speter 2182847Speter /* 2192847Speter * The size of the display 2202847Speter * which defines the maximum nesting 2212847Speter * of procedures and functions allowed. 2222847Speter */ 2232847Speter #define DSPLYSZ 20 2242847Speter 2252847Speter /* 2262847Speter * Routines which need types 2272847Speter * other than "integer" to be 2282847Speter * assumed by the compiler. 2292847Speter */ 2302847Speter int *tree(); 2312847Speter int *hash(); 2322847Speter char *alloc(); 2332847Speter long cntof(); 2342847Speter long nowcnt(); 2352847Speter 2362847Speter /* 2372847Speter * Funny structures to use 2382847Speter * pointers in wild and wooly ways 2392847Speter */ 2402847Speter struct { 2412847Speter char pchar; 2422847Speter }; 2432847Speter struct { 2442847Speter int pint; 2452847Speter int pint2; 2462847Speter }; 2472847Speter struct { 2482847Speter long plong; 2492847Speter }; 2502847Speter struct { 2512847Speter double pdouble; 2522847Speter }; 2532847Speter 2542847Speter #define OCT 1 2552847Speter #define HEX 2 2562847Speter 2572847Speter /* 2582847Speter * MAIN PROGRAM GLOBALS, MISCELLANY 2592847Speter */ 2602847Speter 2612847Speter /* 2622847Speter * Variables forming a data base referencing 2632847Speter * the command line arguments with the "z" option. 2642847Speter */ 2652847Speter char **pflist; 2662847Speter int pflstc; 2672847Speter int pfcnt; 2682847Speter 2692847Speter char *filename; /* current source file name */ 2702847Speter char *lastname; /* last file name printed */ 2712847Speter long tvec; /* mod time of the source file */ 2722847Speter long ptvec; /* time profiled */ 2732847Speter char printed; /* current file has been printed */ 2742847Speter char hadsome; /* had some output */ 2752847Speter 2762847Speter /* 2772847Speter * PROFILING AND FORMATTING DEFINITIONS 2782847Speter */ 2792847Speter 2802847Speter /* 2812847Speter * The basic counter information recording structure. 2822847Speter * This is global only because people outside 2832847Speter * the cluster in pmon.c need to know its size. 2842847Speter */ 2852847Speter struct pxcnt { 2862847Speter long ntimes; /* the count this structure is all about */ 2872847Speter int counter; /* a unique counter number for us */ 2882847Speter int gos; /* global goto count when we hatched */ 2892847Speter int printed; /* are we considered to have been printed? */ 2902847Speter } pfcnts[DSPLYSZ]; 2912847Speter 2922847Speter /* 2932847Speter * The pieces we divide the output line indents into: 2942847Speter * line# PRFN label: STAT 999.---| DECL text 2952847Speter */ 2962847Speter #define STAT 0 2972847Speter #define DECL 1 2982847Speter #define PRFN 2 2992847Speter 3002847Speter /* 3012847Speter * Gocnt records the total number of goto's and 3022847Speter * cnts records the current counter for generating 3032847Speter * COUNT operators. 3042847Speter */ 3052847Speter int gocnt; 3062847Speter int cnts; 3072847Speter 3082847Speter #include <stdio.h> 3092847Speter 31010737Smckusick typedef enum {FALSE, TRUE} bool; 31110737Smckusick 3122847Speter #undef putchar 313