[m-rev.] update GCC back-end interface to GCC 3.3 beta

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Sep 11 06:32:04 AEST 2002


This is a change to update the GCC back-end interface to the current GCC
CVS top-of-tree.  I won't commit this to the main branch yet, for two
reasons:

(1) GCC 3.3 hasn't been released yet, and it is probably easier for
    most people if we require the use of a released version of GCC,
    rather than a CVS snapshot.

(2) It doesn't bootstrap, due to a bug which I have not yet investigated.

Obviously (2) is something I want to fix, but in the light of (1) I will
go ahead and commit this to a new branch sometime soon.

----------

Estimated hours taken: 20
Branches: gcc_3_3

Update the GCC back-end interface to the current GCC top-of-tree (2002-09-04).
Also eliminate dependencies on the C front-end.

gcc/mercury/mercury-convert.c:
	New file.  Similar to gcc/c-convert.c, but modified to use
	langhooks to get truthvalue_conversion() rather than
	using c_common_truthvalue_conversion().  This is needed to
	ensure that we don't drag in the rest of the C front-end.

gcc/mercury/mercury-tree.def:
	New file.  Holds definitions of Mercury-specific tree nodes.
	Currently empty.

gcc/mercury/mercury-gcc.h:
	Add GTY() macros, as required by GCC's new garbage collector.
	Declare mark_addressable(), for use by mercury/compiler/gcc.m,
	since this function is no longer declared in the GCC headers.

gcc/mercury/mercury-gcc.c:
	Use GCC's new language hooks.
	Define tree codes here (using tree.def and mercury-tree.def),
	since that must now be done in the front-end, rather than
	being done in libbackend.a.
	Define language-specific types needed by GCC's new garbage
	collector.
	Avoid dependencies on the C front-end.
	Delete some unnecessary baggage (c_global_trees, rid_pointers, etc.)
	that was originally copied from the C front-end.
	Don't use set_internal_error_function(), since that doesn't
	exist anymore; instead, set it manually.
	Add new "attrs" parameter to build_function(),
	to match the updated declaration in gcc/tree.h.

gcc/mercury/config-lang.in:
	Set `gtfiles' to the list of Mercury front-end files containing
	GTY() macros.  This is required to support GCC's new garbage
	collector.

gcc/mercury/lang-specs.h:
	Update the initializers to handle a new field in the structure.

gcc/mercury/Make-lang.in:
	Link in attribs.o; this is needed by the code for handling
	the attrs parameter to builtin_function().
	Link in mercury-convert.o rather than c-convert.o,
	thus eliminating dependencies on the C front-end.
	Handle new files needed with GCC's new garbage collector
	(see gcc/doc/gty.texi).
	Update dependencies.
	Add empty mercury.generated-manpages target.

XXX remember to check that this diff includes all
    the relevant files that have been changed!

Workspace: /home/mars/fjh/ws-gcc/mercury-gcc
Index: gcc/mercury/Make-lang.in
===================================================================
RCS file: /home/mercury1/repository/gcc/mercury/Make-lang.in,v
retrieving revision 1.7
diff -u -d -r1.7 Make-lang.in
--- gcc/mercury/Make-lang.in	10 Sep 2002 10:09:24 -0000	1.7
+++ gcc/mercury/Make-lang.in	10 Sep 2002 16:40:26 -0000
@@ -54,7 +54,7 @@
 	$(MERCURY_FRONT_END_SRC_DIR)/boehm_gc/libgc.a
 
 # GCC object files used for the Mercury front-end.
-MERCURY_GCC_OBJS = mercury/mercury-gcc.o c-convert.o
+MERCURY_GCC_OBJS = mercury/mercury-gcc.o mercury/mercury-convert.o attribs.o
 
 # Additional C libraries that we need to link in
 # because they are needed by the libraries listed above.
@@ -106,7 +106,7 @@
 	@# The code above uses the C compiler to do the linking.
 	@# Another alternative would be to use the Mercury linker instead:
 	@# $(ML) $(ALL_MLFLAGS) $(ALL_CFLAGS) $(LDFLAGS) \
-	@	mercury/mercury-gcc.o c-convert.o \
+	@	mercury/mercury-gcc.o mercury/mercury-convert.o \
 	@	$(OBJS) $(MERCURY_BACK_END_LIBS) -o $@ 
 
 # The mercury_gcc_backend_libs target contains a list of the
@@ -140,10 +140,23 @@
 		$(srcdir)/mercury/mercury-gcc.c \
 		$(srcdir)/mercury/mercury-gcc.h \
 		$(CONFIG_H) $(TREE_H) flags.h real.h output.h \
-		c-tree.h $(RTL_H) tm_p.h $(GGC_H) toplev.h \
-		langhooks.h langhooks-def.h
+		target.h $(GGC_H) toplev.h \
+		diagnostic.h \
+		langhooks.h langhooks-def.h \
+		$(srcdir)/mercury/mercury-tree.def \
+		gtype-mercury.h \
+		gt-mercury-mercury-gcc.h
+	$(CC) -o $@ -c $(ALL_CFLAGS) $(INCLUDES) $< 
+mercury/mercury-convert.o: \
+		$(srcdir)/mercury/mercury-convert.c \
+		$(CONFIG_H) $(TREE_H) flags.h convert.h real.h \
+		toplev.h langhooks.h
 	$(CC) -o $@ -c $(ALL_CFLAGS) $(INCLUDES) $< 
 
+# header files generated by gengtype (see doc/gty.texi)
+gt-mercury-mercury-gcc.h : s-gtype ; @true
+gttype-mercury.h : s-gtype ; @true
+
 #main to test generated program
 mercury/testmercury.o: $(srcdir)/mercury/testmercury.c  $(CONFIG_H) 
 	$(CC) -o $@ -c $(ALL_CFLAGS) $(INCLUDES) $< 
@@ -172,6 +185,7 @@
 
 mercury.info:
 mercury.dvi:
+mercury.generated-manpages:
 
 #

 # Install hooks:
Index: gcc/mercury/config-lang.in
===================================================================
RCS file: /home/mercury1/repository/gcc/mercury/config-lang.in,v
retrieving revision 1.3
diff -u -d -r1.3 config-lang.in
--- gcc/mercury/config-lang.in	9 Jul 2001 18:09:02 -0000	1.3
+++ gcc/mercury/config-lang.in	10 Sep 2002 16:42:08 -0000
@@ -39,4 +39,6 @@
 
 diff_excludes=
 
+gtfiles="\$(srcdir)/mercury/mercury-gcc.h \$(srcdir)/mercury/mercury-gcc.c"
+
 build_by_default=no
Index: gcc/mercury/lang-specs.h
===================================================================
RCS file: /home/mercury1/repository/gcc/mercury/lang-specs.h,v
retrieving revision 1.4
diff -u -d -r1.4 lang-specs.h
--- gcc/mercury/lang-specs.h	30 Jan 2001 16:55:09 -0000	1.4
+++ gcc/mercury/lang-specs.h	10 Sep 2002 12:21:42 -0000
@@ -21,8 +21,8 @@
 /* This is the contribution to the `default_compilers' array in gcc.c for
    Mercury.  */
 
-  {".mer",    "@mercury" },
-  {".m",      "@mercury" },
+  {".mer",    "@mercury", 0 },
+  {".m",      "@mercury", 0 },
   {"@mercury",
    "%{!E:mercury1 %i %(mercury1) %(cc1_options) %{I*}\
-             %{!fsyntax-only:%(invoke_as)}}"},
+             %{!fsyntax-only:%(invoke_as)}}", 0 },
Index: gcc/mercury/mercury-convert.c
===================================================================
RCS file: gcc/mercury/mercury-convert.c
diff -N gcc/mercury/mercury-convert.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/mercury/mercury-convert.c	10 Sep 2002 16:17:20 -0000
@@ -0,0 +1,115 @@
+/* Language-level data type conversion for Mercury.
+   This is a very slightly modified copy of c-convert.c.
+   Copyright (C) 1987, 1988, 1991, 1998, 2002 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
+
+
+/* This file contains the functions for converting C expressions
+   to different data types.  The only entry point is `convert'.
+   Every language front end must have a `convert' function
+   but what kind of conversions it does will depend on the language.  */
+
+#include "config.h"
+#include "system.h"
+#include "tree.h"
+#include "flags.h"
+#include "convert.h"
+#include "toplev.h"
+#include "langhooks.h"
+
+/* Change of width--truncation and extension of integers or reals--
+   is represented with NOP_EXPR.  Proper functioning of many things
+   assumes that no other conversions can be NOP_EXPRs.
+
+   Conversion between integer and pointer is represented with CONVERT_EXPR.
+   Converting integer to real uses FLOAT_EXPR
+   and real to integer uses FIX_TRUNC_EXPR.
+
+   Here is a list of all the functions that assume that widening and
+   narrowing is always done with a NOP_EXPR:
+     In convert.c, convert_to_integer.
+     In c-typeck.c, build_binary_op (boolean ops), and
+	c_common_truthvalue_conversion.
+     In expr.c: expand_expr, for operands of a MULT_EXPR.
+     In fold-const.c: fold.
+     In tree.c: get_narrower and get_unwidened.  */
+

+/* Subroutines of `convert'.  */
+
+
+

+/* Create an expression whose value is that of EXPR,
+   converted to type TYPE.  The TREE_TYPE of the value
+   is always TYPE.  This function implements all reasonable
+   conversions; callers should filter out those that are
+   not permitted by the language being compiled.  */
+
+tree
+convert (type, expr)
+     tree type, expr;
+{
+  tree e = expr;
+  enum tree_code code = TREE_CODE (type);
+
+  if (type == TREE_TYPE (expr)
+      || TREE_CODE (expr) == ERROR_MARK
+      || code == ERROR_MARK || TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
+    return expr;
+
+  if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr)))
+    return fold (build1 (NOP_EXPR, type, expr));
+  if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
+    return error_mark_node;
+  if (TREE_CODE (TREE_TYPE (expr)) == VOID_TYPE)
+    {
+      error ("void value not ignored as it ought to be");
+      return error_mark_node;
+    }
+  if (code == VOID_TYPE)
+    return build1 (CONVERT_EXPR, type, e);
+#if 0
+  /* This is incorrect.  A truncation can't be stripped this way.
+     Extensions will be stripped by the use of get_unwidened.  */
+  if (TREE_CODE (expr) == NOP_EXPR)
+    return convert (type, TREE_OPERAND (expr, 0));
+#endif
+  if (code == INTEGER_TYPE || code == ENUMERAL_TYPE)
+    return fold (convert_to_integer (type, e));
+  if (code == BOOLEAN_TYPE)
+    {
+      tree t = (*lang_hooks.truthvalue_conversion) (expr);
+      /* If it returns a NOP_EXPR, we must fold it here to avoid
+	 infinite recursion between fold () and convert ().  */
+      if (TREE_CODE (t) == NOP_EXPR)
+	return fold (build1 (NOP_EXPR, type, TREE_OPERAND (t, 0)));
+      else
+	return fold (build1 (NOP_EXPR, type, t));
+    }
+  if (code == POINTER_TYPE || code == REFERENCE_TYPE)
+    return fold (convert_to_pointer (type, e));
+  if (code == REAL_TYPE)
+    return fold (convert_to_real (type, e));
+  if (code == COMPLEX_TYPE)
+    return fold (convert_to_complex (type, e));
+  if (code == VECTOR_TYPE)
+    return fold (convert_to_vector (type, e));
+
+  error ("conversion to non-scalar type requested");
+  return error_mark_node;
+}
Index: gcc/mercury/mercury-gcc.c
===================================================================
RCS file: /home/mercury1/repository/gcc/mercury/mercury-gcc.c,v
retrieving revision 1.31
diff -u -d -r1.31 mercury-gcc.c
--- gcc/mercury/mercury-gcc.c	10 Sep 2002 10:09:25 -0000	1.31
+++ gcc/mercury/mercury-gcc.c	10 Sep 2002 19:57:02 -0000
@@ -40,10 +40,7 @@
 #include "tree.h"
 #include "flags.h"
 #include "real.h"		/* For build_real().  */
-/* XXX we should avoid the dependency on `c-*.h'. */
-#include "c-tree.h"
-#include "rtl.h"		/* For MD_INIT_BUILTINS.  */
-#include "tm_p.h"		/* For MD_INIT_BUILTINS.  */
+#include "target.h"		/* For the init_builtins() target hook. */
 #include "ggc.h"
 #include "toplev.h"
 #include "diagnostic.h"
@@ -81,9 +78,9 @@
 static void merc_lang_finish PARAMS((void));
 static void merc_lang_init_options PARAMS((void));
 static int merc_lang_decode_option PARAMS((int argc, char **argv));
+void merc_lang_parse_file PARAMS ((int set_yydebug));
 
-#if 0 /* for gcc 3.3 and later */
-static int merc_lang_mark_addressable PARAMS((tree exp));
+static tree merc_lang_truthvalue_conversion PARAMS((tree expr));
 static tree merc_lang_type_for_size PARAMS((unsigned precision,
 					    int unsignedp));
 static tree merc_lang_type_for_mode PARAMS((enum machine_mode mode,
@@ -92,7 +89,16 @@
 static tree merc_lang_signed_type PARAMS((tree type_node));
 static tree merc_lang_signed_or_unsigned_type PARAMS((int unsignedp,
 						      tree type));
-#endif
+
+/* XXX should these be static? */
+void pushlevel PARAMS((int ignore));
+tree poplevel PARAMS((int keep, int reverse, int functionbody));
+int global_bindings_p PARAMS((void));
+void insert_block PARAMS((tree block));
+void set_block PARAMS((tree block));
+tree pushdecl PARAMS((tree decl));
+tree getdecls PARAMS((void));
+int kept_level_p PARAMS((void));
 
 /*---------------------------------------------------------------------------*/
 
@@ -120,6 +126,16 @@
 tree merc_intptr_type_node;		/* intptr_t */
 tree merc_jmpbuf_type_node;		/* __builtin_jmpbuf i.e. void *[5] */
 
+tree wchar_type_node;
+tree string_type_node;
+tree const_string_type_node;
+tree widest_integer_literal_type_node;
+tree widest_unsigned_literal_type_node;
+tree boolean_type_node;
+tree boolean_false_node;
+tree boolean_true_node;
+tree char_array_type_node;
+
 /* The filename of the source file that we're going to parse.  */
 static const char *merc_filename;
 
@@ -137,6 +153,53 @@
 
 /*---------------------------------------------------------------------------*/
 
+/* Types expected by gcc's garbage collector.
+   These types exist to allow language front-ends to
+   add extra information in gcc's parse tree data structure.
+   But the Mercury front end doesn't use them -- it has
+   its own parse tree data structure.
+   We define them here only to satisfy gcc's garbage collector.  */
+
+/* Language-specific identifier information.  */
+
+struct lang_identifier GTY(())
+{
+  struct tree_identifier common;
+};
+
+/* Language-specific tree node information.  */
+
+union lang_tree_node 
+  GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE")))
+{
+  union tree_node GTY ((tag ("0"), 
+			desc ("tree_node_structure (&%h)"))) 
+    generic;
+  struct lang_identifier GTY ((tag ("1"))) identifier;
+};
+
+/* Language-specific type information.  */
+
+struct lang_type GTY(())
+{
+  char junk; /* dummy field to ensure struct is not empty */
+};
+
+/* Language-specific declaration information.  */
+
+struct lang_decl GTY(())
+{
+  char junk; /* dummy field to ensure struct is not empty */
+};
+
+
+struct language_function GTY(())
+{
+  char junk; /* dummy field to ensure struct is not empty */
+};
+
+/*---------------------------------------------------------------------------*/
+
 /* Hooks expected by gcc: */
 
 /* The `lang_hooks' struct is a table of function pointers.
@@ -154,9 +217,13 @@
 #define LANG_HOOKS_INIT_OPTIONS merc_lang_init_options
 #undef LANG_HOOKS_DECODE_OPTION
 #define LANG_HOOKS_DECODE_OPTION merc_lang_decode_option
+#undef LANG_HOOKS_PARSE_FILE
+#define LANG_HOOKS_PARSE_FILE merc_lang_parse_file
 
+#undef LANG_HOOKS_TRUTHVALUE_CONVERSION
+#define LANG_HOOKS_TRUTHVALUE_CONVERSION merc_lang_truthvalue_conversion
 #undef LANG_HOOKS_MARK_ADDRESSABLE
-#define LANG_HOOKS_MARK_ADDRESSABLE merc_lang_mark_addressable
+#define LANG_HOOKS_MARK_ADDRESSABLE mark_addressable
 #undef LANG_HOOKS_TYPE_FOR_MODE
 #define LANG_HOOKS_TYPE_FOR_MODE merc_lang_type_for_mode
 #undef LANG_HOOKS_TYPE_FOR_SIZE
@@ -172,21 +239,50 @@
 
 /*---------------------------------------------------------------------------*/
 
+/* Tree code classes.  */
+
+#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
+
+const char tree_code_type[] = {
+#include "tree.def"
+  'x',
+#include "mercury/mercury-tree.def"
+};
+#undef DEFTREECODE
+
+/* Table indexed by tree code giving number of expression
+   operands beyond the fixed part of the node structure.
+   Not used for types or decls.  */
+
+#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
+
+const unsigned char tree_code_length[] = {
+#include "tree.def"
+  0,
+#include "mercury/mercury-tree.def"
+};
+#undef DEFTREECODE
+
+/* Names of tree components.
+   Used for printing out the tree and error messages.  */
+#define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
+
+const char *const tree_code_name[] = {
+#include "tree.def"
+  "@@dummy",
+#include "mercury/mercury-tree.def"
+};
+#undef DEFTREECODE
+
+
+/*---------------------------------------------------------------------------*/
+
 /* Global variables expected by gcc: */
 
 int flag_traditional;		/* Used by dwarfout.c.  */
 
 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
   
-/* The elements of `ridpointers' are identifier nodes
-   for the reserved type names and storage classes.
-   It is indexed by a RID_... value.  */
-tree *ridpointers = NULL;
-
-tree global_trees[TI_MAX];
-tree c_global_trees[CTI_MAX];
-tree current_function_decl;
-
 /*---------------------------------------------------------------------------*/
 /*---------------------------------------------------------------------------*/
 
@@ -362,8 +458,7 @@
   TREE_STATIC (fndecl) = 1;
   DECL_ARGUMENTS (fndecl) = param_list;
   DECL_RESULT (fndecl)
-    = build_decl (RESULT_DECL, NULL_TREE,
-		  merc_promote_type (return_type));
+    = build_decl (RESULT_DECL, NULL_TREE, merc_promote_type (return_type));
   DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
 
   rest_of_decl_compilation (fndecl, NULL, 1, 0);
@@ -723,7 +818,7 @@
 merc_lang_init (filename)
      const char *filename;
 {
-  set_internal_error_function (merc_handle_internal_error);
+  global_dc->internal_error = merc_handle_internal_error;
 
   merc_init_decl_processing();
 
@@ -739,8 +834,9 @@
 }
 
 /* This is the main entry point.  */
-int
-yyparse (void)
+void
+merc_lang_parse_file (set_yydebug)
+    int set_yydebug ATTRIBUTE_UNUSED;
 {
   if (merc_continue_frontend != NULL)
     {
@@ -749,13 +845,12 @@
          source code and built the MLDS.  All we need to do now
          is to generate the GCC tree and expand it to RTL.  */
       (*merc_continue_frontend) ();
-      return 0;
     }
   else
     {
       /* We're using the gcc main(), and we haven't run
          the Mercury compiler yet.  Do so.  */
-      return merc_call_mercury_compiler ();
+      (void) merc_call_mercury_compiler ();
     }
 }
 
@@ -892,14 +987,14 @@
 
 /* This variable keeps a table for types for each precision so that we only 
    allocate each of them once. Signed and unsigned types are kept separate.  */
-static tree signed_and_unsigned_types[MAX_BITS_PER_WORD + 1][2];
+static GTY(()) tree signed_and_unsigned_types[MAX_BITS_PER_WORD + 1][2];
 
 /* Return an integer type with the number of bits of precision given by  
    PRECISION.  UNSIGNEDP is nonzero if the type is unsigned; otherwise
    it is a signed type.  */
 
-tree
-type_for_size (precision, unsignedp)
+static tree
+merc_lang_type_for_size (precision, unsignedp)
      unsigned precision;
      int unsignedp;
 {
@@ -937,44 +1032,44 @@
 /* Return a data type that has machine mode MODE.  UNSIGNEDP selects
    an unsigned type; otherwise a signed type is returned.  */
 
-tree
-type_for_mode (mode, unsignedp)
+static tree
+merc_lang_type_for_mode (mode, unsignedp)
      enum machine_mode mode;
      int unsignedp;
 {
-  return type_for_size (GET_MODE_BITSIZE (mode), unsignedp);
+  return merc_lang_type_for_size (GET_MODE_BITSIZE (mode), unsignedp);
 }
 
 /* Return the unsigned version of a TYPE_NODE, a scalar type.  */
 
-tree
-unsigned_type (type_node)
+static tree
+merc_lang_unsigned_type (type_node)
      tree type_node;
 {
-  return type_for_size (TYPE_PRECISION (type_node), 1);
+  return merc_lang_type_for_size (TYPE_PRECISION (type_node), 1);
 }
 
 /* Return the signed version of a TYPE_NODE, a scalar type.  */
 
-tree
-signed_type (type_node)
+static tree
+merc_lang_signed_type (type_node)
      tree type_node;
 {
-  return type_for_size (TYPE_PRECISION (type_node), 0);
+  return merc_lang_type_for_size (TYPE_PRECISION (type_node), 0);
 }
 
 /* Return a type the same as TYPE except unsigned or signed according to
    UNSIGNEDP.  */
 
-tree
-signed_or_unsigned_type (unsignedp, type)
+static tree
+merc_lang_signed_or_unsigned_type (unsignedp, type)
      int unsignedp;
      tree type;
 {
   if (! INTEGRAL_TYPE_P (type) || TREE_UNSIGNED (type) == unsignedp)
     return type;
   else
-    return type_for_size (TYPE_PRECISION (type), unsignedp);
+    return merc_lang_type_for_size (TYPE_PRECISION (type), unsignedp);
 }
 

 /* These functions and variables deal with binding contours.  We only
@@ -1272,42 +1367,10 @@
   build_common_tree_nodes (flag_signed_char);
 
   /* set standard type names */
-  /* XXX should we modify this for Mercury? */
-
-  ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree));
-  ridpointers[(int) RID_INT] = get_identifier ("int");
-  ridpointers[(int) RID_CHAR] = get_identifier ("char");
-  ridpointers[(int) RID_VOID] = get_identifier ("void");
-  ridpointers[(int) RID_FLOAT] = get_identifier ("float");
-  ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
-  ridpointers[(int) RID_SHORT] = get_identifier ("short");
-  ridpointers[(int) RID_LONG] = get_identifier ("long");
-  ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
-  ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
-  ridpointers[(int) RID_INLINE] = get_identifier ("inline");
-  ridpointers[(int) RID_CONST] = get_identifier ("const");
-  ridpointers[(int) RID_RESTRICT] = get_identifier ("restrict");
-  ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
-  ridpointers[(int) RID_BOUNDED] = get_identifier ("__bounded");
-  ridpointers[(int) RID_UNBOUNDED] = get_identifier ("__unbounded");
-  ridpointers[(int) RID_AUTO] = get_identifier ("auto");
-  ridpointers[(int) RID_STATIC] = get_identifier ("static");
-  ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
-  ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
-  ridpointers[(int) RID_REGISTER] = get_identifier ("register");
-  /*  ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator"); */
-  ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
-  ridpointers[(int) RID_ID] = get_identifier ("id");
-  ridpointers[(int) RID_IN] = get_identifier ("in");
-  ridpointers[(int) RID_OUT] = get_identifier ("out");
-  ridpointers[(int) RID_INOUT] = get_identifier ("inout");
-  ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
-  ridpointers[(int) RID_BYREF] = get_identifier ("byref");
-  ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
 
   /* Define `int' and `char' first so that dbx will output them first.  */
 
-  merc_push_atomic_type_decl (ridpointers[(int) RID_INT], integer_type_node);
+  merc_push_atomic_type_decl (get_identifier ("int"), integer_type_node);
   merc_push_atomic_type_decl (get_identifier ("char"), char_type_node);
   merc_push_atomic_type_decl (get_identifier ("long int"),
 			      long_integer_type_node);
@@ -1363,14 +1426,13 @@
 
   build_common_tree_nodes_2 (merc_flag_short_double);
 
-  merc_push_atomic_type_decl (ridpointers[(int) RID_FLOAT], float_type_node);
-  merc_push_atomic_type_decl (ridpointers[(int) RID_DOUBLE], double_type_node);
+  merc_push_atomic_type_decl (get_identifier ("float"), float_type_node);
+  merc_push_atomic_type_decl (get_identifier ("double"), double_type_node);
   merc_push_atomic_type_decl (get_identifier ("long double"), long_double_type_node);
-  merc_push_atomic_type_decl (ridpointers[(int) RID_VOID], void_type_node);
+  merc_push_atomic_type_decl (get_identifier ("void"), void_type_node);
 
-#ifdef MD_INIT_BUILTINS
-  MD_INIT_BUILTINS;
-#endif
+  /* Add any target-specific builtin functions.  */
+  (*targetm.init_builtins) ();
 
   wchar_type_node = get_identifier (merc_flag_short_wchar
   				    ? "short unsigned int"
@@ -1426,11 +1488,12 @@
   const char *msg;
   va_list *args;
 {
-  diagnostic_context dc;
+  diagnostic_info diagnostic;
 
-  set_diagnostic_context
-    (&dc, msg, args, input_filename, lineno, /* warn = */0);
-  report_diagnostic (&dc);
+  diagnostic_set_info (&diagnostic, msg, args, input_filename, lineno,
+                       DK_ICE);
+
+  report_diagnostic (&diagnostic);
 
   fprintf (stderr,
   	   "Please submit a full bug report to <mercury-bugs at cs.mu.oz.au>.\n");
@@ -1465,7 +1528,7 @@
     = build_function_type (ptr_type_node, alloc_function_param_types);
   merc_alloc_function_node
     = builtin_function ("GC_malloc", alloc_function_type,
-			0, NOT_BUILT_IN, NULL);
+			0, NOT_BUILT_IN, NULL, NULL);
   DECL_IS_MALLOC (merc_alloc_function_node) = 1;
 
   /* Declare `int strcmp(const char *, const char *);'.  */
@@ -1476,7 +1539,7 @@
     = build_function_type (integer_type_node, strcmp_function_param_types);
   merc_strcmp_function_node
     = builtin_function ("__builtin_strcmp", strcmp_function_type,
-		        BUILT_IN_STRCMP, BUILT_IN_NORMAL, "strcmp");
+		        BUILT_IN_STRCMP, BUILT_IN_NORMAL, "strcmp", NULL);
 
   /* Declare `int MR_hash_string(const char *, const char *);'.  */
   hash_string_function_param_types
@@ -1487,7 +1550,7 @@
     = build_function_type (integer_type_node, hash_string_function_param_types);
   merc_hash_string_function_node
     = builtin_function ("MR_hash_string", hash_string_function_type,
-			0, NOT_BUILT_IN, NULL);
+			0, NOT_BUILT_IN, NULL, NULL);
 
   /* Declare `MR_Box MR_asm_box_float(MR_Float);'.  */
   box_float_function_param_types
@@ -1496,7 +1559,7 @@
     = build_function_type (ptr_type_node, box_float_function_param_types);
   merc_box_float_function_node
     = builtin_function ("MR_asm_box_float", box_float_function_type,
-			0, NOT_BUILT_IN, NULL);
+			0, NOT_BUILT_IN, NULL, NULL);
 
   /* Declare `int __builtin_setjmp(void *);'.  */
   setjmp_function_param_types
@@ -1505,7 +1568,7 @@
     = build_function_type (integer_type_node, setjmp_function_param_types);
   merc_setjmp_function_node
     = builtin_function ("__builtin_setjmp", setjmp_function_type,
-			BUILT_IN_SETJMP, BUILT_IN_NORMAL, NULL);
+			BUILT_IN_SETJMP, BUILT_IN_NORMAL, NULL, NULL);
 
   /* Declare `void __builtin_longjmp(void *, int);'.  */
   longjmp_function_param_types
@@ -1516,56 +1579,22 @@
     = build_function_type (void_type_node, longjmp_function_param_types);
   merc_longjmp_function_node
     = builtin_function ("__builtin_longjmp", longjmp_function_type,
-			BUILT_IN_LONGJMP, BUILT_IN_NORMAL, NULL);
+			BUILT_IN_LONGJMP, BUILT_IN_NORMAL, NULL, NULL);
 
-  /* Register our global tree nodes as roots for the garbage collector.  */
-  ggc_add_tree_root (&merc_alloc_function_node, 1);
-  ggc_add_tree_root (&merc_strcmp_function_node, 1);
-  ggc_add_tree_root (&merc_hash_string_function_node, 1);
-  ggc_add_tree_root (&merc_box_float_function_node, 1);
-  ggc_add_tree_root (&merc_setjmp_function_node, 1);
-  ggc_add_tree_root (&merc_longjmp_function_node, 1);
-  ggc_add_tree_root (&merc_int8_type_node, 1);
-  ggc_add_tree_root (&merc_int16_type_node, 1);
-  ggc_add_tree_root (&merc_int32_type_node, 1);
-  ggc_add_tree_root (&merc_int64_type_node, 1);
-  ggc_add_tree_root (&merc_intptr_type_node, 1);
-  ggc_add_tree_root (&merc_jmpbuf_type_node, 1);
-  ggc_add_tree_root (&signed_and_unsigned_types[0][0],
-		     (MAX_BITS_PER_WORD + 1) * 2);
-  ggc_add_tree_root (c_global_trees, CTI_MAX);
-  ggc_add_tree_root (ridpointers, RID_MAX);
 }
 
-/* If DECL has a cleanup, build and return that cleanup here.
-   This is a callback called by expand_expr.  */
-
-tree
-maybe_build_cleanup (decl)
-     tree decl ATTRIBUTE_UNUSED;
-{ return NULL_TREE; }
-
-/* Print an error message for invalid use of an incomplete type.  */
-
-void
-incomplete_type_error (dont_care_1, dont_care_2)
-     tree dont_care_1 ATTRIBUTE_UNUSED;
-     tree dont_care_2 ATTRIBUTE_UNUSED;
-{ abort (); }
-
-tree
-truthvalue_conversion (expr)
+static tree
+merc_lang_truthvalue_conversion (expr)
      tree expr;
 { return expr; }
 
-
 /* Mark EXP saying that we need to be able to take the
    address of it; it should not be allocated in a register.
    Value is 1 if successful.  
    
    This implementation was copied from c-decl.c. */
 
-int
+bool
 mark_addressable (exp)
      tree exp;
 {
@@ -1621,6 +1650,7 @@
 		return 0;
 	      }
 
+#if 0 /* C specific */
 	    /* If we are making this addressable due to its having
 	       volatile components, give a different error message.  Also
 	       handle the case of an unnamed parameter by not trying
@@ -1631,6 +1661,7 @@
 		error ("cannot put object with volatile field into register");
 		return 0;
 	      }
+#endif
 
 	    pedwarn ("address of register variable `%s' requested",
 		     IDENTIFIER_POINTER (DECL_NAME (x)));
@@ -1650,39 +1681,26 @@
     }
 }
 
-void
-copy_lang_decl (node)
-     tree node ATTRIBUTE_UNUSED;
-{}
-
-/* mark any data hanging of a tree node as used, for garbage collection  */
-void 
-lang_mark_tree (t)
-     union tree_node *t ATTRIBUTE_UNUSED;
-{
-/* we have no extras in the tree - nothing to do so return */
-  return;
-}
-
 /* Return a definition for a builtin function named NAME and whose data type
    is TYPE.  TYPE should be a function type with argument types.
    FUNCTION_CODE tells later passes how to compile calls to this function.
    See tree.h for its possible values.
 
    If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
-   the name to be called if we can't opencode the function.  
-
-   copied from gcc/c-decl.c by tim josling
+   the name to be called if we can't opencode the function.  If
+   ATTRS is nonzero, use that for the function's attribute list.
 
+   copied from gcc/c-decl.c
 */
 
 tree
-builtin_function (name, type, function_code, class, library_name)
+builtin_function (name, type, function_code, class, library_name, attrs)
      const char *name;
      tree type;
      int function_code;
      enum built_in_class class;
      const char *library_name;
+     tree attrs;
 {
   tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
   DECL_EXTERNAL (decl) = 1;
@@ -1706,5 +1724,16 @@
     C_DECL_ANTICIPATED (decl) = 1;
 #endif
 
+  /* Possibly apply some default attributes to this built-in function.  */
+  if (attrs)
+    decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
+  else
+    decl_attributes (&decl, NULL_TREE, 0);
+
   return decl;
 }
+
+/* see doc/gty.texi for documentation on this */
+#include "debug.h" /* for debug_hooks, needed by gt-mercury-mercury-gcc.h */
+#include "gt-mercury-mercury-gcc.h"
+#include "gtype-mercury.h"
Index: gcc/mercury/mercury-gcc.h
===================================================================
RCS file: /home/mercury1/repository/gcc/mercury/mercury-gcc.h,v
retrieving revision 1.17
diff -u -d -r1.17 mercury-gcc.h
--- gcc/mercury/mercury-gcc.h	30 Jan 2001 16:55:09 -0000	1.17
+++ gcc/mercury/mercury-gcc.h	10 Sep 2002 20:06:38 -0000
@@ -30,19 +30,41 @@
 
 extern void (*merc_continue_frontend) PARAMS((void));
 
-extern tree merc_alloc_function_node;
-extern tree merc_strcmp_function_node;
-extern tree merc_hash_string_function_node;
-extern tree merc_box_float_function_node;
-extern tree merc_setjmp_function_node;
-extern tree merc_longjmp_function_node;
+extern GTY(()) tree merc_alloc_function_node;
+extern GTY(()) tree merc_strcmp_function_node;
+extern GTY(()) tree merc_hash_string_function_node;
+extern GTY(()) tree merc_box_float_function_node;
+extern GTY(()) tree merc_setjmp_function_node;
+extern GTY(()) tree merc_longjmp_function_node;
 
-extern tree merc_int8_type_node;
-extern tree merc_int16_type_node;
-extern tree merc_int32_type_node;
-extern tree merc_int64_type_node;
-extern tree merc_intptr_type_node;
-extern tree merc_jmpbuf_type_node;
+extern GTY(()) tree merc_int8_type_node;
+extern GTY(()) tree merc_int16_type_node;
+extern GTY(()) tree merc_int32_type_node;
+extern GTY(()) tree merc_int64_type_node;
+extern GTY(()) tree merc_intptr_type_node;
+extern GTY(()) tree merc_jmpbuf_type_node;
+
+/* This avoids problems if c-tree.h got dragged in somehow
+   (e.g. by mercury/compiler/gcc.m).  */
+#undef wchar_type_node
+#undef string_type_node
+#undef const_string_type_node
+#undef widest_integer_literal_type_node
+#undef widest_unsigned_literal_type_node
+#undef boolean_type_node
+#undef boolean_false_node
+#undef boolean_true_node
+#undef char_array_type_node
+
+extern GTY(()) tree wchar_type_node;
+extern GTY(()) tree string_type_node;
+extern GTY(()) tree const_string_type_node;
+extern GTY(()) tree widest_integer_literal_type_node;
+extern GTY(()) tree widest_unsigned_literal_type_node;
+extern GTY(()) tree boolean_type_node;
+extern GTY(()) tree boolean_false_node;
+extern GTY(()) tree boolean_true_node;
+extern GTY(()) tree char_array_type_node;
 
 /* functions for processing declarations */
 
@@ -115,6 +137,15 @@
 
 extern tree
 merc_cons_init_list		PARAMS((tree elem, tree expr, tree init_list));
+
+/* XXX Ideally, this should have a `merc_' prefix.
+   However, that would require modifying compiler/gcc.m in the
+   Mercury distribution, which would make it more complicated
+   to obtain correctly synchronized version of the mercury and
+   mercury-gcc distributions.  */
+
+extern bool
+mark_addressable		PARAMS((tree exp));
 
 /* functions for processing functions */
 
Index: gcc/mercury/mercury-tree.def
===================================================================
RCS file: gcc/mercury/mercury-tree.def
diff -N gcc/mercury/mercury-tree.def
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/mercury/mercury-tree.def	10 Sep 2002 12:55:47 -0000
@@ -0,0 +1,23 @@
+/* mercury-tree.def: definitions of Mercury-specific tree codes for
+   the Mercury language front-end to GCC.
+   Copyright (C) 2002 Fergus Henderson.
+
+This file is part of GNU CC.
+
+GNU CC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU CC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU CC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+/* This file defines Mercury-specific tree codes.
+   Currently there are none of these.  */

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list