home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 357_01 / cstar1.exe / READ.ME < prev    next >
Text File  |  1991-06-21  |  13KB  |  314 lines

  1. The CSTAR READ.ME file
  2.  
  3. Read this documentation file first.
  4.  
  5. June 25, 1991
  6.  
  7.  
  8. OVERVIEW
  9.  
  10. The CSTAR language is an outgrowth of a language called PL/68K, which 
  11. was described in the January 1986 issue of Dr. Dobb's Journal.  CSTAR is 
  12. a cross translator:  it runs on the IBM PC and produces 68000 assembly 
  13. code in Digital Research (DRI) format.  The source code for the CSTAR 
  14. compiler can be compiled using the Microsoft C compiler v5.1 or later or 
  15. with Turbo C v1.5 or later.  There is approximately four programmer years 
  16. of work on this disk.
  17.  
  18. CSTAR produces locally optimal code in almost all circumstances.  By that I 
  19. mean that CSTAR produces code for arithmetic operations and flow of 
  20. control constructs that is at least as good as would typically be produced by 
  21. an expert assembly language programmer. As you will see when you look at 
  22. the code generator code, producing this kind of optimal code requires a 
  23. *lot* of attention to detail.  CSTAR does no global optimizations or loop 
  24. optimizations, nor does it eliminate common subexpressions, but rather 
  25. provides the ability to specify those optimizations in source code if desired.
  26.  
  27.  
  28. PUBLIC DOMAIN SOFTWARE
  29.  
  30. The CSTAR program was placed in the public domain on June 15, 1991,
  31. by its principal author and sole owner:
  32.  
  33.     Edward K. Ream
  34.     1617 Monroe Street
  35.     Madison, WI 53711
  36.     (608) 257-0802
  37.  
  38. CSTAR may be used for any commercial or non-commercial purpose.
  39.  
  40.  
  41. DISCLAIMER OF WARRANTIES
  42.  
  43. Edward K. Ream (Ream) specifically disclaims all warranties,
  44. expressed or implied, with respect to this computer software,
  45. including but not limited to implied warranties of merchantability
  46. and fitness for a particular purpose.  In no event shall Ream be
  47. liable for any loss of profit or any commercial damage, including
  48. but not limited to special, incidental consequential or other damages.
  49.  
  50. CALL ME
  51.  
  52. The CSTAR compiler is large and complicated.  Please feel free to call with 
  53. any questions or comments you may have.  If you plan to do any real work 
  54. with CSTAR I probably can save you a lot of time.  I am also available to do 
  55. commercial consulting and programming on this product.
  56.  
  57. DOCUMENTATION
  58.  
  59. The file ARITH.DOC contains a detailed discussion of the rules for 
  60. generating code for arithmetic expressions.  As you will see, this is a 
  61. complex area, and one in which many compilers generate poor code.  
  62. CSTAR does an outstanding job in this area.
  63.  
  64. The file CHANGES.DOC discusses how the coding and performance of the  
  65. CSTAR translator could be improved, perhaps by as much as a factor of 3.  
  66. The changes described are extensive so this file will be of theoretical interest 
  67. only for most people.  
  68.  
  69. The file CSTAR.DOC discusses the evolution of the original language, 
  70. PL/68Kto the CSTAR language.  As you will see, this change was not 
  71. entirely satisfactory, which was one reason why neither PL/68K nor 
  72. CSTAR were ever offered as commercial products.  Nontheless, CSTAR 
  73. would make a good basis for making a full C compiler.
  74.  
  75. The file DESIGN.DOC discusses various aspects of design of the CSTAR 
  76. translator.  (See CSTAR.DOC for a discussion of the CSTAR language.)
  77.  
  78. The file PL68K.DOC contains a slightly revised version of the original Dr. 
  79. Dobb's Journal article about PL/68K.  Alas, it does not contain the original 
  80. figures.
  81.  
  82.  
  83. FEATURES AND LIMITATIONS OF THE CSTAR COMPILER
  84.  
  85. Insofar as CSTAR is simply C, the CSTAR compiler can not produce better 
  86. code than the best C compilers.  In fact, however, the design of the CSTAR 
  87. compiler was heavily influenced by the same philosophy behind the design 
  88. of the PL/68K language .  This philosophy produced several important 
  89. benefits in the compiler:
  90.  
  91. o  You get  as much control over the code generated by arithmetic 
  92. expressions as you desire.  Most of the time, the code generators in the 
  93. CSTAR compiler produce locally optimal code.  If they do not, or if global 
  94. considerations require local code changes, you can usually improve the code 
  95. simply by using different C operators.  For example, you could replace 
  96. array operators [] with dereference operators *.  These tricks will work with 
  97. most C compilers, but CSTAR also allows you to use PL/68K-style 
  98. pseudo-functions for absolute control over the output generated.
  99.  
  100. Changing arithmetic expressions produces only local changes to the output.  
  101. The CSTAR compiler does no global optimization, so you can always 
  102. pinpoint what source code statements produced what output statements.  
  103. Output is flagged with the line number of the statements that produced the 
  104. output. 
  105.  
  106. The quality of code generated by expressions largely determines the overall 
  107. quality of a compiler.  The CSTAR compiler typically produces good-to-
  108. excellent code for all C-language constructs but the CSTAR language also 
  109. allows you to specify exact code to be produced when you need to.  Except 
  110. for constructs involving common sub-expressions and global optimizations 
  111. (which you may improve by changing the source code), the quality of the 
  112. code produced by the CSTAR compiler is as good or better than the code 
  113. produced by the Green Hills compiler.
  114.  
  115. o  The CSTAR compiler always produces best possible code for boolean 
  116. expressions and flow-of-control constructs such as if-then-else, do-while, 
  117. etc. No unnecessary jumps to jumps are ever generated.  Compare 
  118. instructions are rearranged in required to eliminate non-essential jumps. The 
  119. code produced by this part of the compiler is indistinguishable from the 
  120. code that would produced by a good assembly language programmer.
  121.  
  122. The CSTAR compiler compiler is fast, and could be made much faster.   On 
  123. a 10 Mhz CP/M 68000 system with a ram disk the CSTAR compiler 
  124. compiles more than 2000 lines per minute.  This is comparable to the speed 
  125. at which the non-optimizing Unix cc compiler compiles code on a 68000 
  126. system and about three times faster than the Green Hills compiler.  
  127.  
  128. The CSTAR compiler reads source files only once--no intermediate files are 
  129. used and all data structures are kept in main memory for maximum speed.  
  130. Thus, the size of the largest function that can be compiled is limited by the 
  131. amount of main memory available.  About 500K of main memory is 
  132. required to compile the file containing the largest function in the CSTAR 
  133. compiler itself.
  134.  
  135. The CSTAR compiler contains the following extensions to standard C:
  136.  
  137. o C language variables which have the same name as 68000 registers are 
  138. treated as if they were register variables assigned to the corresponding 
  139. register.
  140.  
  141. o Functions which have the same name as 68000 instructions are treated as 
  142. if the corresponding 68000 instruction were inserted in line.
  143.  
  144. o The #enum preprocessor directive is an abbreviation for a sequence of 
  145. #define's. 
  146.  
  147. The following features of the ANSI C are not supported by the CSTAR 
  148. compiler:
  149.  
  150. o Blocks.  All variables of a function must be declared as formal parameters 
  151. or as local variables whose scope is the entire function.
  152.  
  153. o Bit fields.
  154.  
  155. o Complex initializers involving arrays of structs or unions.
  156.  
  157. o Enum data type.
  158.  
  159. o Functions may not return structs,unions or arrays, but only pointers to 
  160. those objects.
  161.  
  162. o Function prototyping.
  163.  
  164. The data structures used by the CSTAR were designed for maximum 
  165. flexibility and speed.  The CSTAR compiler builds in main memory a full 
  166. parse tree and a complete representation of the code to be output, called the 
  167. intermediate code list or ICL.  The CSTAR compiler generates code (i.e., 
  168. adds nodes to the ICL), by making several passes over the parse tree, 
  169. sometimes rearranging the tree in the process.  The nodes of the parse tree 
  170. mostly contains links to other nodes so that traversing the parse tree is very 
  171. easy.  After the ICL is built, a peephole optimization pass deletes or reorders 
  172. nodes in the ICL.  The ICL is doubly linked so that deleting or rearranging 
  173. nodes of the ICL is also easy.
  174.  
  175. With these data structures in place, adding a global optimizer or an internal 
  176. assembler (so that the compiler would produce object code) would be 
  177. straightforward.  A global optimizer would simply rearrange the parse tree 
  178. before the code generators were applied to it.  Again, the format of the parse 
  179. tree already lends itself to these operations.  As with a stand alone 
  180. assembler, the internal assembler would simply make two passes over the 
  181. ICL, one pass to calculate location counter values and the other pass to 
  182. output object code.  The internal assembler, however, would be much easier 
  183. to write than a stand-alone assembler since the ICL is a much simpler format 
  184. to process than standard assembly language.
  185.  
  186.  
  187. STATUS OF THE COMPILER
  188.  
  189. At one time the CSTAR compiler could compile itself.  However, that is no
  190. longer true--the code now contains both function prototypes and ANSI function 
  191. definitions which the CSTAR compiler does not support.  If you are thinking
  192. of adding these new language features, you should consider getting the Sherlock
  193. debugging package.  The SPP tool, which is part of the Sherlock package, does
  194. parse full ANSI C.
  195.  
  196. Compiles with both Turbo and Microsoft without errors and without 
  197. significant  warnings.  Microsoft gives no warnings and Turbo C gives the 
  198. following warnings, all of which can be ignored:
  199.  
  200. o  Possibly invalid assignments.
  201.  
  202. o  Unreachable code:  These are the result of code that tests the compiler 
  203. environment.  These are ok.
  204.  
  205. o  Parameter xxx is not used.  These are the result of unfinished code, 
  206. mostly unfinished optimizations.
  207.  
  208. The ipt field of struct iblock is really a union, which is why casts are
  209. so often required.  This code could be buggy.
  210.  
  211. No bugs are known, but not a lot of serious testing has been done lately.
  212.  
  213.  
  214. FILES ON THE DISK
  215.  
  216. The header file cstar.h contains extensive discussion about compile-time 
  217. options to choose before compiling CSTAR.
  218.  
  219. Main line and preprocessor:  cstar.c, tok.c, dir.c, def.c.
  220.  
  221. Parser: par.c, dcl.c, exp.c.
  222.  
  223. Symbol tables:  mst.c and st.c.
  224.  
  225. Code generation: g1.c, g2.c, g3.c, reg.c, x2.c, t2.c.
  226.  
  227. Output Routines: io.c, pr.c.
  228.  
  229. Utilities: sys.c, mem.c, utl.c, str.c.
  230.  
  231. Executable files:  csdb.exe  is the debugging version of cs.exe.
  232.  
  233. Test files:  *.tst
  234.  
  235. Batch files: The file fr.sub searches all the source files of CSTAR for a 
  236. pattern using a FIND program.
  237.  
  238. Make and link files for Microsoft C:  *.mmk and *.ml
  239.  
  240. Make and link files for Turboc: *.mak and *.lnk.
  241.  
  242. Dummy version of Sherlock macros: sl.h (see next section)
  243.  
  244.  
  245. DEBUGGING NOTES
  246.  
  247. csdb.exe is instrumented with the Sherlock tracing system, available from 
  248. the C Users' Group.  If you are going to modify CSTAR I *strongly* 
  249. recommend you get a copy of Sherlock.  The file sl.h contains a dummy 
  250. version of sl.h which will allow you to recompiler CSTAR without having 
  251. Sherlock.
  252.  
  253. Almost any routine may be traced by simply enabling the Sherlock argument 
  254. with the corresponding name.  For instance, to trace is_reserved(), just do 
  255. the following on the command line:
  256.  
  257.     csdb ++is_reserved
  258.  
  259. However, the most useful tracing arguments do not correspond to the 
  260. names of routines.  These "extra" tracing arguments are as follows:
  261.  
  262. ++v         Enable tracing of numerous dumps.
  263.  
  264. ++out_list    Send output of compiler to both console and the output file.
  265.  
  266. ++g_put        Intersperse debugging output with compiler output.
  267.  
  268. ++code        Output intermediate data structures.
  269.  
  270. ++dump        Output debugging statistics at the end of the run.
  271.  
  272. You should enable all of these switches any time you are faced with a 
  273. serious bug.  As you peruse the code, you may also find some other 
  274. Sherlock trace points which would be helpful, but you should definitely be 
  275. aware of the ones above.
  276.  
  277. It is also possible to set internal compiler variables and switches using 
  278. Sherlock arguments.
  279.  
  280. ++no_out    Disable out_list() function.
  281.  
  282. ++nopeep    Disable peephole optimization
  283.  
  284. ++init_1    Use 1 temp A-register, 1 temp D register for expressions
  285.  
  286. ...
  287.  
  288. +init_6        Use 6 temp A-regs, 6 temp D regs for expressions.
  289.  
  290.  
  291. Note:  Because CSTAR does not support local variables defined in inner 
  292. blocks, you must use the MARK I version of the Sherlock macros when 
  293. compiling the CSTAR source using CSTAR compiler itself.  The normal 
  294. MARK II version of the Sherlock macros can be used when compiling 
  295. CSTAR with either Turboc C or Microsoft C or any other ANSI compiler.
  296.  
  297.  
  298. DIAGNOSTIC MESSAGES
  299.  
  300. There are three levels of diagnostic messages.  In order of severity, they are:
  301.  
  302. Errors:  an error  is present which precludes creation of usable code.  For 
  303. example, outright syntax errors.
  304.  
  305. Warnings:  usable code will be produced, but there is something going on 
  306. that probably needs fixing.  For example, dubious pointer subtraction, 
  307. constant in conditional context, etc.  Many, if not most, C warnings have 
  308. probably already become PL/68K errors.
  309.  
  310. Helps:  valid code (as far as the compiler is concerned) has been produced, 
  311. but a question is raised as to something which the programmer may well 
  312. choose to ignore, e.g. an operator which generates especially abstruse code 
  313. on the target processor.  Helps may be turned off as a command line option.
  314.