This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Mercury front-end


On 01-Jan-2001, Andi Kleen <ak@suse.de> wrote:
> Fergus Henderson <fjh@cs.mu.oz.au> 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 <fjh@cs.mu.oz.au>  |  "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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]