Errors and Features of type_id stuff
[libfirm] / ir / ir / irprog.c
index f8054bc..963ae93 100644 (file)
@@ -6,17 +6,27 @@
 ** irprog.c: ir representation of a program
 */
 
-# include "irprog.h"
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+# include "irprog_t.h"
 # include "array.h"
+# include "obst.h"
+# include "typegmod.h"
 
 #define GLOBAL_TYPE_NAME "GlobalType"
 
+/* A variable from where everything in the ir can be accessed. */
+ir_prog *irp;
+
 /* initializes ir_prog. Calles the constructor for an ir_prog. */
 void init_irprog(void) {
   new_ir_prog ();
 }
 
-/* Create a new ir prog. Automatically called by init_firm through init_irprog. */
+/* Create a new ir prog. Automatically called by init_firm through
+   init_irprog. */
 ir_prog *new_ir_prog (void) {
   ir_prog *res;
 
@@ -30,32 +40,89 @@ ir_prog *new_ir_prog (void) {
                                               strlen(GLOBAL_TYPE_NAME)));
   add_irp_type((type *)res->glob_type);
 
+#ifdef DEBUG_libfirm
+  res->max_node_nr = 1;
+#endif
+
   return res;
 }
 
-
 /** Functions to access the fields of ir_prog **/
-type_class *get_glob_type(void) {
+
+
+/* Access the main routine of the compiled program. */
+ir_graph *get_irp_main_irg() {
+  assert (irp);
+  return irp->main_irg;
+}
+
+void set_irp_main_irg(ir_graph *main_irg) {
+  assert (irp);
+  irp->main_irg = main_irg;
+}
+
+type *get_glob_type(void) {
   assert(irp);
-  return irp->glob_type;
+  return irp->glob_type = skip_tid(irp->glob_type);
 }
 
 /* Adds irg to the list of ir graphs in irp. */
 void      add_irp_irg(ir_graph *irg) {
   assert (irg != NULL);
-  assert(irp);
+  assert(irp && irp->graphs);
   ARR_APP1 (ir_graph *, irp->graphs, irg);
 }
 
+int get_irp_n_irgs() {
+  assert (irp && irp->graphs);
+  /* Strangely the first element of the array is NULL.  Why??  */
+  return (ARR_LEN((irp)->graphs) - 1);
+}
+
+ir_graph *get_irp_irg(int pos){
+  assert (irp && irp->graphs);
+  /* Strangely the first element of the array is NULL.  Why??  */
+  return irp->graphs[pos+1];
+}
+
+void set_irp_irg(int pos, ir_graph *irg) {
+  assert (irp && irg);
+  assert (pos < (ARR_LEN((irp)->graphs) - 1));
+  /* Strangely the first element of the array is NULL.  Why??  */
+  irp->graphs[pos+1] = irg;
+}
+
 /* Adds type to the list of types in irp. */
-void      add_irp_type(type *typ) {
+void add_irp_type(type *typ) {
   assert (typ != NULL);
   assert(irp);
   ARR_APP1 (type *, irp->types, typ);
 }
 
-int       get_irp_new_node_nr() {
+int get_irp_n_types (void) {
+  assert (irp && irp->types);
+  /* Strangely the first element of the array is NULL.  Why??  */
+  return (ARR_LEN((irp)->types) - 1);
+}
+
+type *get_irp_type(int pos) {
+  assert (irp && irp->types);
+  /* Strangely the first element of the array is NULL.  Why??  */
+  /* Don't set the skip_tid result so that no double entries are generated. */
+  return skip_tid(irp->types[pos+1]);
+}
+
+void  set_irp_type(int pos, type *typ) {
+  assert (irp && typ);
+  assert (pos < (ARR_LEN((irp)->types) - 1));
+  /* Strangely the first element of the array is NULL.  Why??  */
+  irp->types[pos+1] = typ;
+}
+
+#ifdef DEBUG_libfirm
+int get_irp_new_node_nr() {
   assert(irp);
   irp->max_node_nr = irp->max_node_nr + 1;
   return irp->max_node_nr - 1;
 }
+#endif