Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!gatech!bloom-beacon!think!ames!ucbcad!ucbvax!doc.ic.ac.UK!lmjm
From: lmjm@doc.ic.ac.UK
Newsgroups: comp.lang.modula2
Subject: Translating M2 -> C
Message-ID: <8707171903.a009483@ivax.doc.ic.ac.uk>
Date: Fri, 17-Jul-87 14:03:28 EDT
Article-I.D.: ivax.8707171903.a009483
Posted: Fri Jul 17 14:03:28 1987
Date-Received: Sat, 18-Jul-87 19:12:47 EDT
References: <482@ivax.doc.ic.ac.uk>
Sender: daemon@ucbvax.BERKELEY.EDU
Distribution: world
Organization: The ARPA Internet
Lines: 57


   Date: 16 Jul 87 16:31:05 GMT
   From: Duncan C White 
   Organization: Dept. of Computing, Imperial College, London, UK.

   1).	every system worth talking about has a C compiler.
True, true.

   2).	often, the C compiler is heavily optimised.
Not quite so true - but getting better - eg: GCC.

   3).	C is often referred to as a high-level assembler.
	   What people omit is the important word 'portable'.
Hmmmmmmmm

   4).	Compilers conventionally produce assembler code.
Most Unix compilers do anyway.

   5).	Why not bring all these together, and write a portable M2 compiler
	   which generates C as it's intermediate code.  This would imply no
	   tedious mucking around with new backends for different processors.
	   This is the approach used by C++...

When I last had to port a M2 compiler to a new machine I thought about
this.  The recent messge from Chuck Bilbe covers the problems I was
able to think of.  I instead chose a slightly different route.

Most Unix machines (not all) support a two pass C compiler commonly
called PCC (Portable C Compiler).  The second pass is the code
generator and is also used by a pascal and fortran compiler.  I took
the ETH 4 pass compiler and converted its 4th pass to output a file
suitable for PCC's code generator to use.  This means the M2 compiler is
pretty portable - so long as you have PCC on your target machine - but
dodges many of the problems going to C.  Since the machine it was
targeted for was blindingly fast I never bothered with optimisation
but I get some for free by using the standard C optimiser (which works
on the code generated by PCC).  Given the structure of the ETH
compiler adding in simple lifetime analysis is relatively straight
forward.

This is a simplified description but should give you the gist of it.
Obviously this approach is not as generally useful as Duncan's.  But
lets face it, there are a lot of Unix boxes out there now.

A idea I was toying with would be to do something similar to the above
scheme except going to the GNU optimising C compiler as this is likely
to become available on a wide range of machines.

	Lee.

--
UKUUCP SUPPORT  Lee McLoughlin
	"What you once thought was only a nightmare is now a reality!"

Janet: lmjm@uk.ac.ic.doc, lmcl@uk.ac.ukc
DARPA: lmjm@doc.ic.ac.uk (or lmjm%uk.ac.ic.doc@cs.ucl.ac.uk)
Uucp:  lmjm@icdoc.UUCP, ukc!icdoc!lmjm