typo removed
[libfirm] / ir / ir / irgraph.c
index 1c8a741..c8d9024 100644 (file)
@@ -1,12 +1,14 @@
-/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
-* All rights reserved.
-*
-* Authors: Martin Trapp, Christian Schaefer
-*
-*
-*/
-
-/* $Id$ */
+/*
+ * Project:     libFIRM
+ * File name:   ir/ir/irgraph.c
+ * Purpose:     Entry point to the representation of procedure code.
+ * Author:      Martin Trapp, Christian Schaefer
+ * Modified by: Goetz Lindenmaier
+ * Created:
+ * CVS-ID:      $Id$
+ * Copyright:   (c) 1998-2003 Universität Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
@@ -95,6 +97,7 @@ new_ir_graph (entity *ent, int n_loc)
   res->Phi_in_stack = new_Phi_in_stack();  /* A stack needed for automatic Phi
                                 generation */
 #endif
+  res->kind = k_ir_graph;
   res->obst      = (struct obstack *) xmalloc (sizeof (struct obstack));
   obstack_init (res->obst);
   res->value_table = new_identities (); /* value table for global value
@@ -106,6 +109,7 @@ new_ir_graph (entity *ent, int n_loc)
   res->pinned = pinned;
   res->outs_state = no_outs;
   res->dom_state = no_dom;
+  res->typeinfo_state = irg_typeinfo_none;
 
   /** Type information for the procedure of the graph **/
   res->ent = ent;
@@ -155,11 +159,13 @@ new_ir_graph (entity *ent, int n_loc)
 
 /* Make a rudimentary ir graph for the constant code.
    Must look like a correct irg, spare everything else. */
-ir_graph *new_const_code_irg() {
+ir_graph *new_const_code_irg(void) {
   ir_graph *res;
   ir_node *projX;
 
-  res = (ir_graph *) malloc (sizeof (ir_graph));
+  res = (ir_graph *) malloc (sizeof(*res));
+  memset(res, 0, sizeof(*res));
+
   current_ir_graph = res;
   res->n_loc = 1;      /* Only the memory. */
   res->visited = 0;     /* visited flag, for the ir walker */
@@ -167,6 +173,7 @@ ir_graph *new_const_code_irg() {
 #if USE_EXPLICIT_PHI_IN_STACK
   res->Phi_in_stack = NULL;
 #endif
+  res->kind = k_ir_graph;
   res->obst      = (struct obstack *) xmalloc (sizeof (struct obstack));
   obstack_init (res->obst);
   res->phase_state = phase_building;
@@ -183,6 +190,7 @@ ir_graph *new_const_code_irg() {
   res->bad = new_ir_node (NULL, res, res->start_block, op_Bad, mode_T, 0, NULL);
   res->unknown = new_ir_node (NULL, res, res->start_block, op_Unknown, mode_T, 0, NULL);
   res->start   = new_Start ();
+
   /* Proj results of start node */
   projX        = new_Proj (res->start, mode_X, pns_initial_exec);
   set_store (new_Proj (res->start, mode_M, pns_global_store));
@@ -206,6 +214,7 @@ ir_graph *new_const_code_irg() {
    graph, nor the entity standing for this graph. */
 void free_ir_graph (ir_graph *irg) {
   set_entity_irg(irg->ent, NULL);
+  irg->kind = k_BAD;
   free(irg->obst);
 #if USE_EXPLICIT_PHI_IN_STACK
   free_Phi_in_stack(irg->Phi_in_stack);
@@ -218,6 +227,15 @@ void free_ir_graph (ir_graph *irg) {
    {attr type} get_irg_{attribute name} (ir_graph *irg);
    void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */
 
+int
+is_ir_graph(void *thing) {
+  assert(thing);
+  if (get_kind(thing) == k_ir_graph)
+    return 1;
+  else
+    return 0;
+}
+
 /* Outputs a unique number for this node */
 
 INLINE long
@@ -385,6 +403,7 @@ get_irg_frame_type (ir_graph *irg)
 void
 set_irg_frame_type (ir_graph *irg, type *ftp)
 {
+  assert(is_class_type(ftp));
   irg->frame_type = ftp;
 }
 
@@ -392,9 +411,14 @@ set_irg_frame_type (ir_graph *irg, type *ftp)
 /* To test for a frame type */
 int
 is_frame_type(type *ftp) {
-  return ((is_class_type(ftp) || is_struct_type(ftp)) &&
-         id_is_suffix(id_from_str(FRAME_TP_SUFFIX, strlen(FRAME_TP_SUFFIX)),
-                      get_type_ident(ftp)));
+  int i;
+  if (is_class_type(ftp)) {
+    for (i = 0; i < get_irp_n_irgs(); i++) {
+      type *frame_tp = get_irg_frame_type(get_irp_irg(i));
+      if (ftp == frame_tp) return true;
+    }
+  }
+  return false;
 }
 
 int