home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / MAPOVLAY.ZIP / MAP.DOC next >
Encoding:
Text File  |  1986-05-23  |  7.5 KB  |  130 lines

  1. Documentation for MAP.PAS
  2. -------------------------
  3.  
  4. Version 1.7 for CP/M 80 and PC/MS-DOS Turbo Pascal Version 3
  5.   by Scott Bussinger -- May 1986
  6.      Professional Practice Systems, Inc.
  7.      110 S. 131st Street
  8.      Tacoma, WA  98444
  9.      (206)531-8944
  10.      Compuserve [72247,2671]
  11.  
  12. What it does
  13. ------------
  14.   MAP.PAS is a program which analyzes a Pascal program and provides the
  15. programmer with information on the sizes of each of the overlay routines.
  16. This information can be useful in several ways.  For example, since an overlay
  17. group occupies only as much space as its largest member you can determine
  18. which routines should be worked on in order to save code space.  The current
  19. version is configurable for either CP/M 80 or PC/MS-DOS Turbo Pascal version 3.
  20.  
  21. How to use it
  22. -------------
  23.   MAP.PAS can be either command line or prompt driven.  There are four pieces
  24. of information which can be provided to the program.  All but one of these has
  25. default values.  Command Line options are separated by spaces.
  26.   The first command line parameter is the name of the main Pascal source file.
  27. The default extension is .PAS.  If no parameters are entered on the command
  28. line, you will be asked for the file name.
  29.   The second command line parameter, if entered, is the output file name.  The
  30. file name can include drive/path references or be one of the standard logical
  31. devices used by Turbo Pascal (i.e. LST: or CON:).  If prompted, the default
  32. selection is the console.
  33.   The third command line parameter, if entered, is the output sorting option.
  34. The choices are N (for not sorted), A (for alphabetic sorting of routine
  35. names) and S (for sorting by size of routine).  The default choice if not
  36. entered is not sorted in which case the output is in the same sequence as
  37. defined in the source code.  Only the first letter of the option is significant
  38. but extra letters do no harm.  If the program is prompting, then it asks first
  39. if the output is to be sorted and if so, the sequence to use.  The responses to
  40. these questions are single letters without hitting the RETURN key.
  41.   The fourth command line parameter is the number of lines per page.  If not
  42. entered on the command line, there is no prompting and the default of 66 lines
  43. per page is used.
  44.   The last parameter is the number of lines to be used for the top and bottom
  45. page margins.  Again, if not entered on the command line, there is no prompt
  46. and the default of 6 lines (1 inch) is used.
  47.   The source code for the entire program must be online just as it would be
  48. during compilation.  The program must be compiled to a .COM file before MAP is
  49. run and the resulting overlay files left on the drive where the compiler put
  50. them.  In other words, the time to run MAP is immediatly after compiling the
  51. program to be tested to a .COM file.  MAP should only be run on files which
  52. have been successfully compiled without errors.
  53.  
  54. What it generates
  55. -----------------
  56.   The output from the program is a formatted text file suitable for printing
  57. or viewing with a TYPE command.  The defaults for the number of lines per page
  58. and top and bottom margins are correct for standard 8 1/2" x 11" paper.  All
  59. lines are less than 80 characters long.  For each overlay group in the program
  60. being analyzed, the output will start on a new page.  The first line shows the
  61. overlay group number and the amount of space reserved in memory (not on the
  62. disk) for this overlay group.  The space reserved is given in both bytes and
  63. records.  Turbo Pascal overlay areas are always rounded up to the next
  64. 256 (DOS) or 128 (CP/M) byte boundary and a record is one of these even-sized
  65. chunks.  Because of this, an overlay 129 bytes long reserves exactly as much
  66. space as one which is 255 bytes long.  The number of records required for the
  67. group will be equal to that of its longest member routine.
  68.   The rest of the page consists of a list of each of the member routines of
  69. the overlay group.  The order of this list is either the order they were
  70. defined in the source code, alphabetically by routine name, or by size from
  71. largest to smallest.  Each entry consists of the routine name, the exact length
  72. of the overlay in bytes, the number of 256 (128) byte records required for the
  73. routine, the number of bytes left unused by this routine within the overlay
  74. area and a indication of how much of the available area was used (expressed as
  75. a percentage used).  Note that the bytes to spare equals the total bytes
  76. reserved by the overlay group less the length of the individual routine.  Below
  77. this numeric information is a bar graph showing the percentage used, where a
  78. full line of X's represents 100%.
  79.  
  80. Using the output
  81. ----------------
  82.   Probably the most effective way to use the output to help squeeze some more
  83. code space out of your already overlayed program.  Since the amount of space
  84. occupied in memory is dependent only the largest overlay routine in an
  85. overlay group, it does no good to spend time making the other routines in the
  86. overlay group smaller.  By either sorting the output by size, you can
  87. concentrate your work on the largest routines.  Often splitting the offending
  88. routine in two or moving it to a different overlay area can free up a great
  89. deal of code space with very little effort.  Be careful however not to violate
  90. Turbo Pascal's rules against calling routines in the same overlay group either
  91. directly or indirectly.  Also note that the size of nested overlay areas is
  92. included in the size of an overlay routine.
  93.  
  94. How to compile the program
  95. --------------------------
  96.   To compile the program you need the mainline source file MAP.PAS and one of
  97. the configuration files.  For PC-DOS or MS-DOS use MAPDOS.PAS and for CP/M,
  98. CP/M Plus or MP/M use MAPCPM.PAS.  About 16 lines into the file MAP.PAS is a
  99. line consisting of an include directive and a note pointing it out.  For DOS
  100. users, use the Turbo editor to set this line to {$I MAPDOS.PAS}.  A CP/M user
  101. should set this line to {$I MAPIBM.PAS}.  Set the compiler options to generate
  102. a .COM file, and set the Main file name to MAP.PAS.  After compiling, the
  103. resulting MAP.COM is complete.
  104.  
  105. How it works
  106. ------------
  107.   MAP.PAS is essentially a very simple recursive descent parser which scans
  108. your source code looking for overlay routine definitions.  When a routine is
  109. found, the program scans the compiled overlay files and determines the size
  110. of the compiled object code.  It does this by knowing that compiled overlay
  111. routines always start on a record (256 or 128 byte) boundary and that the last
  112. record is padded out with $00 bytes.  Furthermore, overlay routines in the
  113. same overlay group are butted up against each other in the same order as
  114. defined in the source code.  The program looks at the overlay code and tries
  115. to guess what comprises each of the overlay routines.  It is possible for
  116. the overlay files to fool the program if the random bytes in the code
  117. generated happens to look like a "real" end of overlay pattern.  The program
  118. will notice that the entire overlay file was not used however and retry the
  119. analysis until it succeeds in analyzing the file.
  120.  
  121. Caveats
  122. -------
  123.   There appears to be a slight bug in the Turbo Pascal compiler (noticed in
  124. version 3.01A for PC-DOS, but possibly in others as well) which causes an
  125. extra record of all $00's to be included in the overlay file if the preceeding
  126. routine ended exactly on a record boundary.  This extra 256 bytes is added
  127. (incorrectly) to the length of the next routine.  I left MAP.PAS this way
  128. since it is hard to tell whether future or past versions of the compiler will
  129. handle have the problem.
  130.