Generate the names of the builtins automatically.
authorGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Wed, 1 Sep 1993 22:09:26 +0000 (22:09 +0000)
committerGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Wed, 1 Sep 1993 22:09:26 +0000 (22:09 +0000)
v7/src/microcode/cmpint.c
v7/src/microcode/comutl.c
v8/src/microcode/cmpint.c

index 08f81268ea21830569b66edfb4ddfb68937bb0d2..d63f2b22e5448981b0ba97aae9cac0cbae3404ce 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: cmpint.c,v 1.64 1993/08/26 05:38:29 gjr Exp $
+$Id: cmpint.c,v 1.65 1993/09/01 22:09:17 gjr Exp $
 
 Copyright (c) 1989-1993 Massachusetts Institute of Technology
 
@@ -2981,6 +2981,7 @@ DEFUN (pc_to_utility_index, (pc), unsigned long pc)
   }
 }
 \f
+extern char * EXFUN (builtin_index_to_name, (int));
 extern void EXFUN (declare_builtin, (unsigned long));
 extern int EXFUN (pc_to_builtin_index, (unsigned long));
 extern unsigned long * builtins;
@@ -2988,9 +2989,11 @@ extern unsigned long * builtins;
 static int n_builtins = 0;
 static int s_builtins = 0;
 unsigned long * builtins = ((unsigned long *) NULL);
+char ** builtin_names = ((char **) NULL);
 
 void
-DEFUN (declare_builtin, (builtin), unsigned long builtin)
+DEFUN (declare_builtin, (builtin, name),
+       unsigned long builtin AND char * name)
 {
   if (n_builtins == s_builtins)
   {
@@ -2999,6 +3002,7 @@ DEFUN (declare_builtin, (builtin), unsigned long builtin)
       s_builtins = 30;
       builtins = ((unsigned long *)
                  (malloc (s_builtins * (sizeof (unsigned long)))));
+      builtin_names = ((char **) (malloc (s_builtins * (sizeof (char *)))));
     }
     else
     {
@@ -3006,17 +3010,31 @@ DEFUN (declare_builtin, (builtin), unsigned long builtin)
       builtins = ((unsigned long *)
                  (realloc (builtins,
                            (s_builtins * (sizeof (unsigned long))))));
+      builtin_names = ((char **)
+                      (realloc (builtin_names,
+                                (s_builtins * (sizeof (char *))))));
     }
-    if (builtins == ((unsigned long *) NULL))
+    if ((builtins == ((unsigned long *) NULL))
+       || (builtin_names == ((char **) NULL)))
     {
       outf_fatal ("declare_builtin: malloc/realloc failed (size = %d).\n",
-                 (s_builtins * (sizeof (unsigned long))));
+                 s_builtins);
       termination_init_error ();
     }
   }
-  builtins[n_builtins++] = builtin;
+  builtins[n_builtins] = builtin;
+  bulitin_names[n_builtins++] = name;
   return;
 }
+\f
+char *
+DEFUN (builtin_index_to_name, (index), int index)
+{
+  if ((index < 0) || (index >= n_builtins))
+    return ((char *) NULL);
+  else
+    return (builtin_names[index]);
+}
 
 int
 DEFUN (pc_to_builtin_index, (pc), unsigned long pc)
index 9efa12cd42791c5d175fe41ebece263fd65841e3..01d078de281e79aa1cf0c92ae3a5f48df86a0a7b 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: comutl.c,v 1.24 1993/08/22 20:25:32 gjr Exp $
+$Id: comutl.c,v 1.25 1993/09/01 22:09:26 gjr Exp $
 
 Copyright (c) 1987-1993 Massachusetts Institute of Technology
 
@@ -154,6 +154,20 @@ DEFINE_PRIMITIVE ("UTILITY-INDEX->NAME", Prim_utility_index_to_name, 1, 1,
     PRIMITIVE_RETURN (char_pointer_to_string ((unsigned char *) result));
 }
 
+DEFINE_PRIMITIVE ("BUILTIN-INDEX->NAME", Prim_builtin_index_to_name, 1, 1,
+  "Given an integer, return the name of the corresponding compiled code utility.")
+{
+  extern char * EXFUN (builtin_index_to_name, (int));
+  char * result;
+  PRIMITIVE_HEADER (1);
+
+  result = (builtin_index_to_name (arg_integer (1)));
+  if (result == ((char *) NULL))
+    PRIMITIVE_RETURN (SHARP_F);
+  else
+    PRIMITIVE_RETURN (char_pointer_to_string ((unsigned char *) result));
+}
+
 /* This is only meaningful for the C back end. */
 
 DEFINE_PRIMITIVE ("INITIALIZE-C-COMPILED-BLOCK", Prim_initialize_C_compiled_block, 1, 1,
index 08f81268ea21830569b66edfb4ddfb68937bb0d2..d63f2b22e5448981b0ba97aae9cac0cbae3404ce 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: cmpint.c,v 1.64 1993/08/26 05:38:29 gjr Exp $
+$Id: cmpint.c,v 1.65 1993/09/01 22:09:17 gjr Exp $
 
 Copyright (c) 1989-1993 Massachusetts Institute of Technology
 
@@ -2981,6 +2981,7 @@ DEFUN (pc_to_utility_index, (pc), unsigned long pc)
   }
 }
 \f
+extern char * EXFUN (builtin_index_to_name, (int));
 extern void EXFUN (declare_builtin, (unsigned long));
 extern int EXFUN (pc_to_builtin_index, (unsigned long));
 extern unsigned long * builtins;
@@ -2988,9 +2989,11 @@ extern unsigned long * builtins;
 static int n_builtins = 0;
 static int s_builtins = 0;
 unsigned long * builtins = ((unsigned long *) NULL);
+char ** builtin_names = ((char **) NULL);
 
 void
-DEFUN (declare_builtin, (builtin), unsigned long builtin)
+DEFUN (declare_builtin, (builtin, name),
+       unsigned long builtin AND char * name)
 {
   if (n_builtins == s_builtins)
   {
@@ -2999,6 +3002,7 @@ DEFUN (declare_builtin, (builtin), unsigned long builtin)
       s_builtins = 30;
       builtins = ((unsigned long *)
                  (malloc (s_builtins * (sizeof (unsigned long)))));
+      builtin_names = ((char **) (malloc (s_builtins * (sizeof (char *)))));
     }
     else
     {
@@ -3006,17 +3010,31 @@ DEFUN (declare_builtin, (builtin), unsigned long builtin)
       builtins = ((unsigned long *)
                  (realloc (builtins,
                            (s_builtins * (sizeof (unsigned long))))));
+      builtin_names = ((char **)
+                      (realloc (builtin_names,
+                                (s_builtins * (sizeof (char *))))));
     }
-    if (builtins == ((unsigned long *) NULL))
+    if ((builtins == ((unsigned long *) NULL))
+       || (builtin_names == ((char **) NULL)))
     {
       outf_fatal ("declare_builtin: malloc/realloc failed (size = %d).\n",
-                 (s_builtins * (sizeof (unsigned long))));
+                 s_builtins);
       termination_init_error ();
     }
   }
-  builtins[n_builtins++] = builtin;
+  builtins[n_builtins] = builtin;
+  bulitin_names[n_builtins++] = name;
   return;
 }
+\f
+char *
+DEFUN (builtin_index_to_name, (index), int index)
+{
+  if ((index < 0) || (index >= n_builtins))
+    return ((char *) NULL);
+  else
+    return (builtin_names[index]);
+}
 
 int
 DEFUN (pc_to_builtin_index, (pc), unsigned long pc)