home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / compiler / 1249 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  3.4 KB

  1. Path: sparky!uunet!usc!sdd.hp.com!hp-cv!ogicse!das-news.harvard.edu!spdcc!iecc!compilers-sender
  2. From: bbx!bbx.basis.com!scott@unmvax.cs.unm.edu (Scott Amspoker)
  3. Newsgroups: comp.compilers
  4. Subject: Re: Pros and cons of high-level intermediate languages
  5. Keywords: translator, design
  6. Message-ID: <92-07-070@comp.compilers>
  7. Date: 22 Jul 92 15:54:48 GMT
  8. Article-I.D.: comp.92-07-070
  9. References: <92-07-064@comp.compilers> <92-07-068@comp.compilers>
  10. Sender: compilers-sender@iecc.cambridge.ma.us
  11. Reply-To: bbx!bbx.basis.com!scott@unmvax.cs.unm.edu (Scott Amspoker)
  12. Organization: BASIS International, Ltd., Albuquerque NM USA
  13. Lines: 59
  14. Approved: compilers@iecc.cambridge.ma.us
  15.  
  16. ssp@csl36h.csl.ncsu.edu (Santosh Pande) writes:
  17. >    I am interested in knowing the pros and cons of using an
  18. >intermediate language (IL) in general. In particular I find 'C' has been
  19. >used extensively as the IL in many situations: Modula, SISAL, AT&T Cfront
  20. >for C++ etc.
  21.  
  22. We've been using C as an IL for an object-oriented data processing
  23. language which includes Mesa-style exception handling (quite elegant but
  24. tricky to implement).  Here are a few odds and ends we have discovered
  25. about using C as an IL:
  26.  
  27.    * Generating C code can sometimes be more tedious than generating
  28.      assembler.  Identifiers generally must be preserved and properly
  29.      used and scoped in the C code.  Structures have field names - not 
  30.      merely a list of offsets.  Also, you must either second guess the 
  31.      host C implementation (i.e. alignment and sizeof() stuff) or 
  32.      generate 100% symbolic code - either approach has its problems.
  33.      Local identifiers (especially typedefs) sometimes have to be moved 
  34.      outside a procedure so they can be accessed by additional 
  35.      compiler-generated procedures (or re-created locally within those
  36.      procedures).
  37.  
  38.    * Never approach such a project thinking that all you're doing is
  39.      creating a "front end".  Treat it as you would any native code
  40.      compiler.
  41.  
  42.    * I quickly developed a deep appreciation for the C comma operator.
  43.  
  44.    * The ANSI spec which renders stack variables unpredictable after
  45.      a longjump() sucks.  This is solved by declaring them 'volatile'
  46.      but then you might lose bigtime in the optimizer.
  47.  
  48.    * The lack of a global 'goto' makes certain things a little less
  49.      efficient.  This is especially true for generating glue routines
  50.      to fix the "this" pointer enroute to a virtual method.
  51.  
  52.    * Some C compilers can certainly improve the way they pass small
  53.      structures to and from functions.
  54.  
  55.  
  56. All in all I think using C as an IL is a smart way to go for many, if not
  57. most, applications.  We have better things to do than to re-invent a
  58. native code generator and its associated optimizer for each new platform.
  59. It's true that there can be some performance penalties.  Some of these
  60. penalties can be blamed on C itself.  However, most of them come from
  61. using some of the high-level features provided by the "front end language"
  62. which generates the C code.  Such performance degradation can be minimized
  63. by using a little common sense and is (IMHO) more than offset by the
  64. productivity gains reaped from using high-level features.  As usual, the
  65. secret to success is to know where most of the work is being done and
  66. concentrate on those areas.
  67.  
  68. -- 
  69. Scott Amspoker
  70. Basis International, Albuquerque, NM
  71. scott@bbx.basis.com
  72. -- 
  73. Send compilers articles to compilers@iecc.cambridge.ma.us or
  74. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  75.