From mboxrd@z Thu Jan 1 00:00:00 1970 From: Fergus Henderson To: Andi Kleen Cc: gcc@gcc.gnu.org Subject: Re: Mercury front-end Date: Mon, 01 Jan 2001 21:43:00 -0000 Message-id: <20010102164301.A2489@hg.cs.mu.oz.au> References: <20010102015053.A1955@hg.cs.mu.oz.au> X-SW-Source: 2001-01/msg00031.html On 01-Jan-2001, Andi Kleen wrote: > Fergus Henderson writes: > > > Now I'm wondering what the next step is. > > I plan to post the diff to the mercury-developers mailing list sometime > > soon, and eventually to include at least the Mercury side of the changes > > in the Mercury distribution. But I'm not quite sure what to do with > > the C side of the changes. Would it be appropriate to include them > > in the standard GCC distribution? Or would you prefer that we just > > include them in the Mercury distribution? > > How does the Mercury interface with the C ? Using Mercury's C interface, of course ;-) Mercury includes a C interface as a standard part of the language. For details about Mercury's C interface, see the "C Interface" chapter of the Mercury language reference manual, which is available on the Mercury web site, in particular at < http://www.cs.mu.oz.au/research/mercury/information/doc/reference_manual_toc.html >. Using this C interface, I've defined a Mercury module which is a wrapper around the parts of GCC's interface that we need for compiling Mercury. For example, this module declares a type `gcc__op', for GCC tree codes that represent operators, and defines functions such as `addr_expr', which return values of this type. These functions are implemented using `pragma c_code' declarations, which are a bit like inline asm in GNU C. Here's an example showing the Mercury code to implement `addr_expr': /* declare `addr_expr' as a function with no arguments returning a value of type `gcc__op' */ :- func addr_expr = gcc__op. /* define `addr_expr' to return the value of the C enumeration constant `ADDR_EXPR' */ :- pragma c_code(addr_expr = (Code::out), "Code = ADDR_EXPR;"). With the existing Mercury compiler, these get compiled in as inline C in the generated C code. With the new Mercury compiler based on the gcc back-end, the Mercury compiler handles `pragma c_code' declarations by generating a separate C file containing the code from `pragma c_code' declarations, wrapped up inside suitable functions, and calls to Mercury functions such as `addr_expr' get compiled into calls to these automatically generated C functions. -- Fergus Henderson | "I have always known that the pursuit | of excellence is a lethal habit" WWW: < http://www.cs.mu.oz.au/~fjh > | -- the last words of T. S. Garp.