2007-06-19 Markus Deuling <deuling@de.ibm.com>
[deliverable/binutils-gdb.git] / gdb / m2-lang.c
index 7bf8fa3b10b7bfc08a57cc1e9d3b00adf68428ed..acb2de6d6c12e206b16d685992763135e0f02387 100644 (file)
@@ -1,7 +1,7 @@
 /* Modula 2 language support routines for GDB, the GNU debugger.
 
-   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2002, 2003,
-   2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2002, 2003, 2004,
+   2005, 2007 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -206,7 +206,7 @@ m2_create_fundamental_type (struct objfile *objfile, int typeid)
          name "<?type?>".  When all the dust settles from the type
          reconstruction work, this should probably become an error. */
       type = init_type (TYPE_CODE_INT,
-                       TARGET_INT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "<?type?>", objfile);
       warning (_("internal error: no Modula fundamental type %d"), typeid);
       break;
@@ -242,106 +242,113 @@ m2_create_fundamental_type (struct objfile *objfile, int typeid)
       break;
     case FT_SHORT:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_SHORT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "short", objfile);
       break;
     case FT_SIGNED_SHORT:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_SHORT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "short", objfile);   /* FIXME-fnf */
       break;
     case FT_UNSIGNED_SHORT:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_SHORT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
       break;
     case FT_INTEGER:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_INT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "int", objfile);
       break;
     case FT_SIGNED_INTEGER:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_INT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "int", objfile);     /* FIXME -fnf */
       break;
     case FT_UNSIGNED_INTEGER:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_INT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
       break;
     case FT_FIXED_DECIMAL:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_INT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "fixed decimal", objfile);
       break;
     case FT_LONG:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_LONG_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "long", objfile);
       break;
     case FT_SIGNED_LONG:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_LONG_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "long", objfile);    /* FIXME -fnf */
       break;
     case FT_UNSIGNED_LONG:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_LONG_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
       break;
     case FT_LONG_LONG:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_long_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        0, "long long", objfile);
       break;
     case FT_SIGNED_LONG_LONG:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_long_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        0, "signed long long", objfile);
       break;
     case FT_UNSIGNED_LONG_LONG:
       type = init_type (TYPE_CODE_INT,
-                       TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_long_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
       break;
     case FT_FLOAT:
       type = init_type (TYPE_CODE_FLT,
-                       TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
+                       gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "float", objfile);
       break;
     case FT_DBL_PREC_FLOAT:
       type = init_type (TYPE_CODE_FLT,
-                       TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
+                       gdbarch_double_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "double", objfile);
       break;
     case FT_FLOAT_DECIMAL:
       type = init_type (TYPE_CODE_FLT,
-                       TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
+                       gdbarch_double_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        0, "floating decimal", objfile);
       break;
     case FT_EXT_PREC_FLOAT:
       type = init_type (TYPE_CODE_FLT,
-                       TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
+                       gdbarch_long_double_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        0, "long double", objfile);
       break;
     case FT_COMPLEX:
       type = init_type (TYPE_CODE_COMPLEX,
-                       2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
+                       2 * gdbarch_float_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        0, "complex", objfile);
       TYPE_TARGET_TYPE (type)
        = m2_create_fundamental_type (objfile, FT_FLOAT);
       break;
     case FT_DBL_PREC_COMPLEX:
       type = init_type (TYPE_CODE_COMPLEX,
-                       2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
+                       2 * gdbarch_double_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        0, "double complex", objfile);
       TYPE_TARGET_TYPE (type)
        = m2_create_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
       break;
     case FT_EXT_PREC_COMPLEX:
       type = init_type (TYPE_CODE_COMPLEX,
-                       2 * TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
+                       2 * gdbarch_long_double_bit (current_gdbarch)
+                         / TARGET_CHAR_BIT,
                        0, "long double complex", objfile);
       TYPE_TARGET_TYPE (type)
        = m2_create_fundamental_type (objfile, FT_EXT_PREC_FLOAT);
@@ -389,27 +396,43 @@ static const struct op_print m2_op_print_tab[] =
 \f
 /* The built-in types of Modula-2.  */
 
-struct type *builtin_type_m2_char;
-struct type *builtin_type_m2_int;
-struct type *builtin_type_m2_card;
-struct type *builtin_type_m2_real;
-struct type *builtin_type_m2_bool;
+enum m2_primitive_types {
+  m2_primitive_type_char,
+  m2_primitive_type_int,
+  m2_primitive_type_card,
+  m2_primitive_type_real,
+  m2_primitive_type_bool,
+  nr_m2_primitive_types
+};
 
-struct type **const (m2_builtin_types[]) =
+static void
+m2_language_arch_info (struct gdbarch *gdbarch,
+                      struct language_arch_info *lai)
 {
-  &builtin_type_m2_char,
-    &builtin_type_m2_int,
-    &builtin_type_m2_card,
-    &builtin_type_m2_real,
-    &builtin_type_m2_bool,
-    0
-};
+  const struct builtin_m2_type *builtin = builtin_m2_type (gdbarch);
+
+  lai->string_char_type = builtin->builtin_char;
+  lai->primitive_type_vector
+    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_m2_primitive_types + 1,
+                              struct type *);
+
+  lai->primitive_type_vector [m2_primitive_type_char]
+    = builtin->builtin_char;
+  lai->primitive_type_vector [m2_primitive_type_int]
+    = builtin->builtin_int;
+  lai->primitive_type_vector [m2_primitive_type_card]
+    = builtin->builtin_card;
+  lai->primitive_type_vector [m2_primitive_type_real]
+    = builtin->builtin_real;
+  lai->primitive_type_vector [m2_primitive_type_bool]
+    = builtin->builtin_bool;
+}
 
 const struct language_defn m2_language_defn =
 {
   "modula-2",
   language_m2,
-  m2_builtin_types,
+  NULL,
   range_check_on,
   type_check_on,
   case_sensitive_on,
@@ -434,39 +457,62 @@ const struct language_defn m2_language_defn =
   m2_op_print_tab,             /* expression operators for printing */
   0,                           /* arrays are first-class (not c-style) */
   0,                           /* String lower bound */
-  &builtin_type_m2_char,       /* Type of string elements */
+  NULL,
   default_word_break_characters,
-  NULL, /* FIXME: la_language_arch_info.  */
+  m2_language_arch_info,
   default_print_array_index,
   LANG_MAGIC
 };
 
-/* Initialization for Modula-2 */
-
-void
-_initialize_m2_language (void)
+static void *
+build_m2_types (struct gdbarch *gdbarch)
 {
+  struct builtin_m2_type *builtin_m2_type
+    = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_m2_type);
+
   /* Modula-2 "pervasive" types.  NOTE:  these can be redefined!!! */
-  builtin_type_m2_int =
-    init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
-              0,
-              "INTEGER", (struct objfile *) NULL);
-  builtin_type_m2_card =
-    init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
+  builtin_m2_type->builtin_int =
+    init_type (TYPE_CODE_INT, 
+              gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
+              0, "INTEGER", (struct objfile *) NULL);
+  builtin_m2_type->builtin_card =
+    init_type (TYPE_CODE_INT, 
+              gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
               TYPE_FLAG_UNSIGNED,
               "CARDINAL", (struct objfile *) NULL);
-  builtin_type_m2_real =
-    init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
+  builtin_m2_type->builtin_real =
+    init_type (TYPE_CODE_FLT,
+              gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT,
               0,
               "REAL", (struct objfile *) NULL);
-  builtin_type_m2_char =
+  builtin_m2_type->builtin_char =
     init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
               TYPE_FLAG_UNSIGNED,
               "CHAR", (struct objfile *) NULL);
-  builtin_type_m2_bool =
-    init_type (TYPE_CODE_BOOL, TARGET_INT_BIT / TARGET_CHAR_BIT,
+  builtin_m2_type->builtin_bool =
+    init_type (TYPE_CODE_BOOL, 
+              gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
               TYPE_FLAG_UNSIGNED,
               "BOOLEAN", (struct objfile *) NULL);
 
+  return builtin_m2_type;
+}
+
+static struct gdbarch_data *m2_type_data;
+
+const struct builtin_m2_type *
+builtin_m2_type (struct gdbarch *gdbarch)
+{
+  return gdbarch_data (gdbarch, m2_type_data);
+}
+
+
+/* Initialization for Modula-2 */
+
+void
+_initialize_m2_language (void)
+{
+  m2_type_data = gdbarch_data_register_post_init (build_m2_types);
+
   add_language (&m2_language_defn);
 }
This page took 0.02787 seconds and 4 git commands to generate.