Every node has now a pinned attribute that is inherited from the op.
[libfirm] / ir / st / exc.c
index 4dc924b..6fc1efd 100644 (file)
@@ -1,27 +1,36 @@
-/* Copyright (c) 2002 by Universität Karlsruhe (TH).  All Rights Reserved */
-//
-// Time-stamp: <02/03/04 17:24:07 liekweg>
-//
-
-/***
+/*
+ * Project:     libFIRM
+ * File name:   ir/st/exc.c
+ * Purpose:     Helper functions for jack exceptions.
+ * Author:      Florian Liekweg
+ * Modified by:
+ * Created:     4.3.2002
+ * CVS-ID:      $Id$
+ * Copyright:   (c) 2002-2003 Universität Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
+
+/**
    NAME
      exc
    PURPOSE
      Helper functions for exceptions
-   NOTES
+   S
      not quite complete
-   HISTORY
-     liekweg - Mar 4, 2002: Created.
-   CVS:
-     $Id$
 ***/
 
-# include "exc.h"
-# include "st.h"
-# include "irop.h"
-# include "irouts.h"
+#include <assert.h>
+#include "exc.h"
+
+static char* exc_strings [] = {
+  "Invalid",                                   /* invalid */
+  "Normal",                                            /* normal */
+  "Entry",                                             /* entry to region */
+  "Exit",                                              /* exit of region */
+  "Handler",                                   /* entry to handler */
+  "Cont"
+};
 
-# include <bool.h>
 
 /*
   Return true iff (block b is a handler entry AND a dominates b) OR
@@ -35,7 +44,7 @@ static bool has_handler (ir_graph *graph, ir_node *b, ir_node *a)
   ir_node *succ = 0;
 
   assert (0 && "Wrongly implemented");
-  // must check for _immediate_ dominance !!!
+  /* must check for _immediate_ dominance !!! */
 
   if (is_handler_entry (graph, b) && dominates (graph, a, b))
        return (true);
@@ -58,17 +67,16 @@ static bool is_exc_jmp (ir_node *node)
 {
   ir_op *op = get_irn_op (node);
 
-  // Proj_X (Load), Proj_X (Sto), Proj_X (Div_Int),
-  // Proj_X (Raise), Proj_X (Call), Proj_X (Alloc)
+  /* Proj_X (Load), Proj_X (Sto), Proj_X (Div_Int),
+     Proj_X (Raise), Proj_X (Call), Proj_X (Alloc) */
   if (op == op_Proj)
        {
          op = get_irn_op (get_Proj_pred (node));
 
-         // ToDo: Check for proper Proj attr?!?
-         if ((op == op_Load) || (op == op_Store)  ||
-                 (op == op_Div ) || (op == op_Raise)  ||
-                 (op == op_Call) || (op == op_Alloc))
-               return (true);
+         assert ((is_fragile_op(get_Proj_pred(node))) &&
+                 (op != op_Bad) /*&& (op != op_Unknown)*/ &&
+                 (get_irn_mode(node) == mode_X));/* Check for proper Proj attr */
+         return (true);
        }
   else
        {
@@ -79,21 +87,56 @@ static bool is_exc_jmp (ir_node *node)
 /*
 Return true iff the given node represents a normal cfg jump
 */
+#if 0
 static bool is_cfg_jmp (ir_node *node)
 {
   ir_op *op = get_irn_op (node);
 
   if (op == op_Proj)
-       {
-         op = get_irn_op (get_Proj_pred (node));
+    {
+      op = get_irn_op (get_Proj_pred (node));
 
-         // Proj_X (Proj_Cmp (Cond))
-         if (op_Proj == op)
-               return (true);                  /* check for op == op_Cmp and op == op_Cond */
-       }
+      /* Proj_X (Proj_Cmp (Cond)) */
+      if (op_Proj == op)
+       return (true);  /* check for op == op_Cmp and op == op_Cond */
+    }
 
   return (false);
 }
+#endif
+
+void set_Block_exc(ir_node *n, exc_t exc) {
+}
+
+exc_t get_Block_exc(ir_node *n) {
+  return 0;
+}
+
+
+/* handler handling for Blocks */
+void
+set_Block_handler (ir_node *block, ir_node *handler)  {
+  assert (is_Block(block));
+  assert (is_Block(handler));
+}
+
+ir_node *
+get_Block_handler (ir_node *block) {
+  assert (is_Block(block));
+  return (NULL);
+}
+
+/* handler handling for Nodes */
+void
+set_Node_handler (ir_node *node, ir_node *handler) {
+
+}
+
+ir_node *
+get_Node_handler (ir_node *node) {
+  return (NULL);
+}
+
 
 /*
  Return true iff a new exception region must be left upon entry of this block.
@@ -106,22 +149,20 @@ bool is_handler_entry (ir_graph *graph, ir_node *block)
   bool is_entry = true;
   int  i        = 0;
   int  n        = get_irn_arity (block);
-  ir_node *node = 0;
-  ir_op* op     = op_Bad;
 
   if (exc_invalid == get_Block_exc (block))
        {
-         for (i = 0; (i < n) && is_entry; i ++)
+         for (i = 0; (i < n) && (is_entry == true); i ++)
                if (is_exc_jmp (get_irn_n (block, i)))
                  continue;
                else
                  is_entry = false;
 
          if (true == is_entry)
-               set_Block_exc (block, exc_entry);
+               set_Block_exc (block, exc_handler);
        }
 
-  return (exc_entry == get_Block_exc (block));
+  return (exc_handler == get_Block_exc (block));
 }
 
 /*
@@ -141,7 +182,7 @@ bool is_region_entry  (ir_graph *graph, ir_node *block)
 
          bool no_handler = true;
 
-         for (i = 0; (i < n) && no_handler; i ++)
+         for (i = 0; (i < n) && (no_handler == true); i ++)
                {
                  succ = get_irn_out (block, i);
 
@@ -155,7 +196,7 @@ bool is_region_entry  (ir_graph *graph, ir_node *block)
 
   return (exc_region == get_Block_exc (block));
 
-  return (TRUE);
+  return (true);
 }
 
 /*
@@ -177,7 +218,7 @@ bool is_handler_block (ir_graph *graph, ir_node *block)
          int n_blocks    = env->dt->n_blocks;
          int i           = 0;
 
-         for (i = 0; (i < n_blocks) && no_handler; i ++)
+         for (i = 0; (i < n_blocks) && (no_handler == true); i ++)
                if (0 != (env->dt->masks [i] & block_mask)) /* if dominator */
                  if (is_handler_entry (graph, env->dt->blocks [i])) /* is handler entry */
                        no_handler = false;
@@ -192,39 +233,15 @@ bool is_handler_block (ir_graph *graph, ir_node *block)
 }
 
 /*
- Return true iff a new exception region must be left upon exit of the
- non-exception blocks among the CFG predecessors of this block.
-
- If this block has CFG predecessors that are partly handler blocks and
- partly normal blocks, then we must return true.
+  Convert a value of type exc_t to a descriptive string.
+  Returns a reference to a statically allocated, constant string.
 */
-bool is_cont_entry    (ir_graph *graph, ir_node *block)
-{
-  assert (0 && "Not implemented");
-
-  if (exc_invalid == get_Block_exc (block))
-       {
-         bool has_exc = false;         /* wether we have exception cfg predecessors */
-         bool has_cfg = false;         /* wether we have normal cfg predecessors */
-
-         int i = 0;
-         int n = get_irn_arity (block);
 
-         ir_node *pred = 0;
-
-         for (i = 0; (i < n) && (!has_exc && !has_cfg); i ++)
-               {
-                 pred = get_irn_n (block, i);
-
-                 if (is_exc_jmp (pred))
-                       has_exc = true;
-                 else if (is_cfg_jmp (pred))
-                       has_cfg = true;
-               }
+const char *exc_to_string (exc_t exc)
+{
+  int exc_val = (int) exc;
 
-         if (has_cfg && has_exc)
-               set_Block_exc (block, exc_cont);
-       }
+  assert ((0 <= (int) exc_val) && (exc_val < (int) exc_max));
 
-  return (exc_cont == get_Block_exc (block));
+  return (exc_strings [exc_val]);
 }