Added generic Depth First Search facility
[libfirm] / ir / ana / absgraph.c
1 /**
2  * @file   absgraph.c
3  * @date   20.04.2007
4  * @author Sebastian Hack
5  *
6  * Abstract graph implementations for the CFG of a ir_graph.
7  *
8  * Copyright (C) 2007 Universitaet Karlsruhe
9  * Released under the GPL
10  */
11
12 #include "irgraph_t.h"
13 #include "iredges_t.h"
14 #include "absgraph.h"
15
16 static void *irg_cfg_succ_get_root(void *self)
17 {
18         ir_graph *irg = self;
19         edges_activate_kind(irg, EDGE_KIND_BLOCK);
20         return get_irg_start_block(irg);
21 }
22
23 static void irg_cfg_succ_grow_succs(void *self, void *node, struct obstack *obst)
24 {
25         ir_node *bl = node;
26         const ir_edge_t *edge;
27         foreach_block_succ(bl, edge)
28                 obstack_ptr_grow(obst, get_edge_src_irn(edge));
29 }
30
31 const absgraph_t absgraph_irg_cfg_succ = {
32         irg_cfg_succ_get_root,
33         irg_cfg_succ_grow_succs
34 };
35
36 static void *irg_cfg_pred_get_root(void *self)
37 {
38         return get_irg_end_block(self);
39 }
40
41 static void irg_cfg_pred_grow_succs(void *self, void *node, struct obstack *obst)
42 {
43         int i, n;
44         for (i = 0, n = get_irn_arity(node); i < n; ++i)
45                 obstack_ptr_grow(obst, get_irn_n(node, i));
46 }
47
48 const absgraph_t absgraph_irg_cfg_pred = {
49         irg_cfg_pred_get_root,
50         irg_cfg_pred_grow_succs
51 };