From 6aefa6ac6a2f39363fb1b09632e5965db89b44af Mon Sep 17 00:00:00 2001 From: Florian Liekweg Date: Fri, 22 Oct 2004 15:10:51 +0000 Subject: [PATCH] moved utils to pto_util [r4197] --- ir/ana2/pto_util.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++ ir/ana2/pto_util.h | 35 +++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 ir/ana2/pto_util.c create mode 100644 ir/ana2/pto_util.h diff --git a/ir/ana2/pto_util.c b/ir/ana2/pto_util.c new file mode 100644 index 000000000..47fbf2976 --- /dev/null +++ b/ir/ana2/pto_util.c @@ -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 +# endif + +# include "pto_util.h" + +# include + +# 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); +} + + + +/* + $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 index 000000000..0a868cf17 --- /dev/null +++ b/ir/ana2/pto_util.h @@ -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_ */ + + +/* + $Log$ + Revision 1.1 2004/10/22 15:10:51 liekweg + moved utils to pto_util + + + */ -- 2.20.1