Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!snorkelwacker!spdcc!ima!esegue!compilers-sender From: muller@procope.pa.dec.com (Eric Muller) Newsgroups: comp.compilers Subject: Re: Intermediate Representation Keywords: C, modula, code, translator Message-ID: <1990Aug14.163803.2238@esegue.segue.boston.ma.us> Date: 14 Aug 90 16:38:03 GMT Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: Eric Muller Organization: DEC Systems Research Center Lines: 46 Approved: compilers@esegue.segue.boston.ma.us In article <1990Aug13.214614.16644@esegue.segue.boston.ma.us>, marti@antares.inf.ethz.ch writes: |> Many language designers/implementors have turned to using C as an |> intermediate representation language, for example in the following |> research projects and/or products: |> ... |> - Modula-3 compilers developed at DEC SRC and the (now defunct?) Olivetti |> Research Center |> |> Compilation speed using C as an IRL may not be overwhelming, but this |> solution is certainly portable. Of course, the quality of the generated |> machine code depends substantially on on the C compiler used as a backend. I am working on the SRC Modula-3 system. Bill Kalsow wrote most of the compiler before I joined and he chose C to achieve portability. This certainly works: our system runs on VAX/Ultrix, DECstation/Ultrix, SPARC/SunOs, Apollo DN 4500/DomainOs, IBM R6000/AIX 3.1, AIX/PS2, IBM RT/IBM 4.3, HP 9000/300/HP-UX, without too much pain. However, we do not view C as an intermediate language, but rather as a portable assembler. The compiler maintains a private AST as the intermediate representation. The speed of compilation is not too bad: the Modula-3 to C compilation time is of the same order as the C to .o compilation. The quality of generated code depends a lot on the quality of the C compiler. This should not be very surprising, as we are trying to have a simple compiler: many intermediate expressions become separate assignments in C, for example. I have compared the assembly generated for equivalent Modula-3 and C programs, using the -O2 optimizations of /bin/cc on a DECstation; in many cases, the same assembly is generated. We may spend some time to further improve that aspect. One of the advantages of generating C is that we can assume some runtime support. Modula-3 has exceptions and requires the presence of a Thread module (lightweight processes). setjmp/longjmp are enough to implement that. My own conclusion is that generating C or using a native back-end does not influence that much the quality of the generated code. Choosing one way or the other is a compromise between compilation speed and portability. Eric Muller. ------------------------------------------------------------------------------ System Research Center - 130 Lytton Av. - Palo Alto, CA 94301 - (415) 853 2193 -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.