moved utils to pto_util
authorFlorian Liekweg <liekweg@ipd.info.uni-karlsruhe.de>
Fri, 22 Oct 2004 15:10:51 +0000 (15:10 +0000)
committerFlorian Liekweg <liekweg@ipd.info.uni-karlsruhe.de>
Fri, 22 Oct 2004 15:10:51 +0000 (15:10 +0000)
[r4197]

ir/ana2/pto_util.c [new file with mode: 0644]
ir/ana2/pto_util.h [new file with mode: 0644]

diff --git a/ir/ana2/pto_util.c b/ir/ana2/pto_util.c
new file mode 100644 (file)
index 0000000..47fbf29
--- /dev/null
@@ -0,0 +1,94 @@
+/* -*- c -*- */
+
+/*
+ * Project:     libFIRM
+ * File name:   ir/ana2/pto_util.c
+ * Purpose:     Pto Utilities
+ * Author:      Florian
+ * Modified by:
+ * Created:     Mon 18 Oct 2004
+ * CVS-ID:      $Id$
+ * Copyright:   (c) 1999-2004 Universität Karlsruhe
+ * Licence:     This file is protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
+
+
+# ifdef HAVE_CONFIG_H
+#  include <config.h>
+# endif
+
+# include "pto_util.h"
+
+# include <malloc.h>
+
+# include "irnode.h"
+# include "irgwalk.h"
+# include "xmalloc.h"
+
+/*
+  Environment for find_irg_args
+*/
+typedef struct find_irg_args_env {
+  ir_node **args;
+  ir_node *arg;
+} find_irg_args_env_t;
+
+/*
+  Helper for find_irg_args
+*/
+static void find_irg_arg (ir_node *node, void *env)
+{
+  find_irg_args_env_t *arg_env = (find_irg_args_env_t*) env;
+
+  if (iro_Proj == get_irn_opcode (node)) {
+    if (arg_env->arg == get_Proj_pred (node)) {
+      long n = get_Proj_proj (node);
+
+      assert (! arg_env->args [n]);
+
+      arg_env->args [n] = node;
+    }
+  }
+}
+
+/*
+  Find the arguments of a graph. For a method that has n args, the
+  result array has 'n+1' entries, the last of which is written NULL.
+*/
+ir_node **find_irg_args (ir_graph *graph)
+{
+  type *tp = get_entity_type (get_irg_entity (graph));
+  const int n_args = get_method_n_params (tp);
+  ir_node **args = (ir_node**) xmalloc (sizeof (ir_node*) * (n_args+1));
+  ir_node *arg = get_irg_args (graph);
+  find_irg_args_env_t *arg_env =
+    (find_irg_args_env_t*) xmalloc (sizeof (find_irg_args_env_t));
+  /* int i; */
+
+  arg_env->args = args;
+  arg_env->arg  = arg;
+
+  /* or use get_irg_end ?!? */
+  {
+    ir_graph *save = get_current_ir_graph ();
+    set_current_ir_graph (graph);
+    irg_walk (get_irg_end (graph), find_irg_arg, NULL, arg_env);
+    set_current_ir_graph (save);
+  }
+
+  free (arg_env);
+
+  args [n_args] = NULL;
+
+  return (args);
+}
+
+
+\f
+/*
+  $Log$
+  Revision 1.1  2004/10/22 15:10:51  liekweg
+  moved utils to pto_util
+
+
+ */
diff --git a/ir/ana2/pto_util.h b/ir/ana2/pto_util.h
new file mode 100644 (file)
index 0000000..0a868cf
--- /dev/null
@@ -0,0 +1,35 @@
+/* -*- c -*- */
+
+/*
+ * Project:     libFIRM
+ * File name:   ir/ana2/pto_util.c
+ * Purpose:     Pto Utilities
+ * Author:      Florian
+ * Modified by:
+ * Created:     Mon 18 Oct 2004
+ * CVS-ID:      $Id$
+ * Copyright:   (c) 1999-2004 Universität Karlsruhe
+ * Licence:     This file is protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
+
+# ifndef _PTO_UTIL_H_
+# define _PTO_UTIL_H_
+
+# include "irgraph.h"
+
+/*
+  Find the arguments of a graph. For a method that has n args, the
+  result array has 'n+1' entries, the last of which is written NULL.
+*/
+ir_node **find_irg_args (ir_graph*);
+
+# endif /* not defined _PTO_UTIL_H_ */
+
+\f
+/*
+  $Log$
+  Revision 1.1  2004/10/22 15:10:51  liekweg
+  moved utils to pto_util
+
+
+ */