Nicer Colors
[libfirm] / ir / ana2 / pto_util.c
1 /* -*- c -*- */
2
3 /*
4  * Project:     libFIRM
5  * File name:   ir/ana2/pto_util.c
6  * Purpose:     Pto Utilities
7  * Author:      Florian
8  * Modified by:
9  * Created:     Mon 18 Oct 2004
10  * CVS-ID:      $Id$
11  * Copyright:   (c) 1999-2004 Universität Karlsruhe
12  * Licence:     This file is protected by GPL -  GNU GENERAL PUBLIC LICENSE.
13  */
14
15
16 # ifdef HAVE_CONFIG_H
17 #  include <config.h>
18 # endif
19
20 # include "pto_util.h"
21
22 # include <malloc.h>
23
24 # include "irnode.h"
25 # include "irgwalk.h"
26 # include "xmalloc.h"
27
28 /*
29   Environment for find_irg_args
30 */
31 typedef struct find_irg_args_env {
32   ir_node **args;
33   ir_node *arg;
34 } find_irg_args_env_t;
35
36 /*
37   Helper for find_irg_args
38 */
39 static void find_irg_arg (ir_node *node, void *env)
40 {
41   find_irg_args_env_t *arg_env = (find_irg_args_env_t*) env;
42
43   if (iro_Proj == get_irn_opcode (node)) {
44     if (arg_env->arg == get_Proj_pred (node)) {
45       long n = get_Proj_proj (node);
46
47       assert (! arg_env->args [n]);
48
49       arg_env->args [n] = node;
50     }
51   }
52 }
53
54 /*
55   Find the arguments of a graph. For a method that has n args, the
56   result array has 'n+1' entries, the last of which is written NULL.
57 */
58 ir_node **find_irg_args (ir_graph *graph)
59 {
60   type *tp = get_entity_type (get_irg_entity (graph));
61   const int n_args = get_method_n_params (tp);
62   ir_node **args = (ir_node**) xmalloc (sizeof (ir_node*) * (n_args+1));
63   ir_node *arg = get_irg_args (graph);
64   find_irg_args_env_t *arg_env =
65     (find_irg_args_env_t*) xmalloc (sizeof (find_irg_args_env_t));
66
67   arg_env->args = args;
68   arg_env->arg  = arg;
69
70   /* or use get_irg_end ?!? */
71   {
72     ir_graph *save = get_current_ir_graph ();
73     set_current_ir_graph (graph);
74     irg_walk (get_irg_end (graph), find_irg_arg, NULL, arg_env);
75     set_current_ir_graph (save);
76   }
77
78   free (arg_env);
79
80   args [n_args] = NULL;
81
82   return (args);
83 }
84
85
86 \f
87 /*
88   $Log$
89   Revision 1.2  2004/10/25 11:59:45  liekweg
90   Copy Only works
91
92   Revision 1.1  2004/10/22 15:10:51  liekweg
93   moved utils to pto_util
94
95
96  */