/*
- * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
*
* Simple depth first search on CFGs.
*/
-#ifdef HAVE_CONFIG_H
#include <config.h>
-#endif
#include <stdlib.h>
+#define DISABLE_STATEV
+
#include <assert.h>
#include "irtools.h"
#include "irprintf.h"
#include "statev.h"
#include "dfs_t.h"
-static const char *edge_names[] = {
- "anc",
- "fwd",
- "cross",
- "back"
-};
-
static int cmp_edge(const void *a, const void *b, size_t sz)
{
const dfs_edge_t *p = a;
static void classify_edges(dfs_t *dfs)
{
+ dfs_edge_t *edge;
stat_ev_cnt_decl(anc);
stat_ev_cnt_decl(back);
stat_ev_cnt_decl(fwd);
stat_ev_cnt_decl(cross);
- dfs_edge_t *edge;
foreach_set (dfs->edges, edge) {
dfs_node_t *src = edge->s;
dfs_t *dfs_new(const absgraph_t *graph_impl, void *graph_self)
{
- dfs_t *res = xmalloc(sizeof(res[0]));
+ dfs_t *res = XMALLOC(dfs_t);
dfs_node_t *node;
res->graph_impl = graph_impl;
obstack_init(&res->obst);
dfs_perform(res, graph_impl->get_root(graph_self), NULL, 0);
+
+ /* make sure the end node (which might not be accessible) has a number */
+ node = get_node(res, graph_impl->get_end(graph_self));
+ if (!node->visited) {
+ node->visited = 1;
+ node->node = graph_impl->get_end(graph_self);
+ node->ancestor = NULL;
+ node->pre_num = res->pre_num++;
+ node->post_num = res->post_num++;
+ node->max_pre_num = node->pre_num;
+ node->level = 0;
+ }
+
classify_edges(res);
- res->pre_order = xmalloc(res->pre_num * sizeof(res->pre_order));
- res->post_order = xmalloc(res->pre_num * sizeof(res->post_order));
+ assert(res->pre_num == res->post_num);
+ res->pre_order = XMALLOCN(dfs_node_t*, res->pre_num);
+ res->post_order = XMALLOCN(dfs_node_t*, res->post_num);
foreach_set (res->nodes, node) {
+ assert(node->pre_num < res->pre_num);
+ assert(node->post_num < res->post_num);
+
res->pre_order[node->pre_num] = node;
res->post_order[node->post_num] = node;
}
void dfs_dump(const dfs_t *dfs, FILE *file)
{
- dfs_node_t **nodes = xmalloc(dfs->pre_num * sizeof(nodes[0]));
+ dfs_node_t **nodes = XMALLOCN(dfs_node_t*, dfs->pre_num);
dfs_node_t *node;
dfs_edge_t *edge;
int i, n = 0;