Commit 2822b67e authored by Sebastian Hack's avatar Sebastian Hack
Browse files

Changes API a little bit :-)

parent c0919d78
......@@ -25,12 +25,6 @@
#include "irprintf.h"
#include "beifg_t.h"
size_t (be_ifg_iter_size)(const void *self)
{
const be_ifg_t *ifg = self;
return ifg->impl->iter_size;
}
void (be_ifg_free)(void *self)
{
be_ifg_t *ifg = self;
......@@ -55,6 +49,12 @@ ir_node *(be_ifg_neighbours_next)(const void *self, void *iter)
return ifg->impl->neighbours_next(self, iter);
}
void (be_ifg_neighbours_break)(const void *self, void *iter)
{
const be_ifg_t *ifg = self;
ifg->impl->neighbours_break(self, iter);
}
ir_node *(be_ifg_nodes_begin)(const void *self, void *iter)
{
const be_ifg_t *ifg = self;
......@@ -67,6 +67,12 @@ ir_node *(be_ifg_nodes_next)(const void *self, void *iter)
return ifg->impl->nodes_next(self, iter);
}
void (be_ifg_nodes_break)(const void *self, void *iter)
{
const be_ifg_t *ifg = self;
ifg->impl->nodes_break(self, iter);
}
int (be_ifg_degree)(const void *self, const ir_node *irn)
{
const be_ifg_t *ifg = self;
......@@ -77,7 +83,7 @@ int (be_ifg_degree)(const void *self, const ir_node *irn)
int be_ifg_is_simplicial(const be_ifg_t *ifg, const ir_node *irn)
{
int degree = be_ifg_degree(ifg, irn);
void *iter = be_ifg_iter_alloca(ifg);
void *iter = be_ifg_neighbours_iter_alloca(ifg);
ir_node **neighbours = malloc(degree * sizeof(neighbours[0]));
......@@ -100,10 +106,10 @@ int be_ifg_is_simplicial(const be_ifg_t *ifg, const ir_node *irn)
return 1;
}
void be_fg_check(const be_ifg_t *ifg)
void be_ifg_check(const be_ifg_t *ifg)
{
void *iter1 = be_ifg_iter_alloca(ifg);
void *iter2 = be_ifg_iter_alloca(ifg);
void *iter1 = be_ifg_neighbours_iter_alloca(ifg);
void *iter2 = be_ifg_neighbours_iter_alloca(ifg);
ir_node *n, *m;
......
......@@ -15,16 +15,21 @@
typedef struct _be_ifg_impl_t be_ifg_impl_t;
typedef struct _be_ifg_t be_ifg_t;
#define be_ifg_iter_alloca(self) (alloca(be_ifg_iter_size(self)))
size_t be_ifg_iter_size(const void *self);
void be_ifg_free(void *self);
int be_ifg_connected(const void *self, const ir_node *a, const ir_node *b);
ir_node *be_ifg_neighbours_begin(const void *self, void *iter, const ir_node *irn);
ir_node *be_ifg_neighbours_next(const void *self, void *iter);
ir_node *be_ifg_nodes_begin(const void *self, void *iter);
ir_node *be_ifg_nodes_next(const void *self, void *iter);
int be_ifg_degree(const void *self, const ir_node *irn);
#define be_ifg_nodes_iter_size(self) ((self)->impl->nodes_iter_size)
#define be_ifg_neighbours_iter_size(self) ((self)->impl->neighbours_iter_size)
#define be_ifg_neighbours_iter_alloca(self) (alloca(be_ifg_neighbours_iter_size(self)))
#define be_ifg_nodes_iter_alloca(self) (alloca(be_ifg_nodes_iter_size(self)))
void (be_ifg_free)(void *self);
int (be_ifg_connected)(const void *self, const ir_node *a, const ir_node *b);
ir_node *(be_ifg_neighbours_begin)(const void *self, void *iter, const ir_node *irn);
ir_node *(be_ifg_neighbours_next)(const void *self, void *iter);
void (be_ifg_neighbours_break)(const void *self, void *iter);
ir_node *(be_ifg_nodes_begin)(const void *self, void *iter);
ir_node *(be_ifg_nodes_next)(const void *self, void *iter);
void (be_ifg_nodes_break)(const void *self, void *iter);
int (be_ifg_degree)(const void *self, const ir_node *irn);
#define be_ifg_foreach_neighbour(self, iter, irn, pos) \
for(pos = be_ifg_neighbours_begin(self, iter, irn); (pos); pos = be_ifg_neighbours_next(self, iter))
......
......@@ -6,6 +6,7 @@
* Copyright (C) 2005 Universitaet Karlsruhe
* Released under the GPL
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
......@@ -77,6 +78,14 @@ static void find_nodes(const void *self, void *iter) {
it->nodes = obstack_finish(&it->obst);
}
static INLINE void node_break(nodes_iter_t *it, int force)
{
if((it->curr >= it->n || force) && it->nodes) {
obstack_free(&it->obst, NULL);
it->nodes = NULL;
}
}
static ir_node *get_next_node(void *iter)
{
nodes_iter_t *it = iter;
......@@ -85,10 +94,7 @@ static ir_node *get_next_node(void *iter)
if(it->curr < it->n)
res = it->nodes[it->curr++];
if(it->curr >= it-> n && it->nodes) {
obstack_free(&it->obst, NULL);
it->nodes = NULL;
}
node_break(it, 0);
return res;
}
......@@ -104,6 +110,11 @@ static ir_node *ifg_std_nodes_next(const void *self, void *iter)
return get_next_node(iter);
}
static void ifg_std_nodes_end(const void *self, void *iter)
{
node_break(iter, 1);
}
typedef struct _adj_iter_t {
const be_chordal_env_t *env;
const ir_node *irn;
......@@ -167,16 +178,21 @@ static void find_neighbours(const ifg_std_t *ifg, adj_iter_t *it, const ir_node
it->neighbours = obstack_finish(&it->obst);
}
static INLINE void neighbours_break(adj_iter_t *it, int force)
{
if((it->curr >= it->degree || force) && it->neighbours) {
obstack_free(&it->obst, NULL);
it->neighbours = NULL;
}
}
static ir_node *get_next_neighbour(adj_iter_t *it) {
ir_node *res = NULL;
if(it->curr < it->degree)
res = it->neighbours[it->curr++];
if(it->curr >= it->degree && it->neighbours) {
obstack_free(&it->obst, NULL);
it->neighbours = NULL;
}
neighbours_break(it, 0);
return res;
}
......@@ -192,6 +208,11 @@ static ir_node *ifg_std_neighbours_next(const void *self, void *iter)
return get_next_neighbour(iter);
}
static void ifg_std_neighbours_end(const void *self, void *iter)
{
neighbours_break(iter, 1);
}
static int ifg_std_degree(const void *self, const ir_node *irn)
{
adj_iter_t it;
......@@ -200,13 +221,17 @@ static int ifg_std_degree(const void *self, const ir_node *irn)
}
static const be_ifg_impl_t ifg_std_impl = {
MAX(sizeof(adj_iter_t), sizeof(nodes_iter_t)),
sizeof(nodes_iter_t),
sizeof(adj_iter_t),
ifg_std_free,
ifg_std_connected,
ifg_std_neighbours_begin,
ifg_std_neighbours_next,
ifg_std_neighbours_break,
ifg_std_nodes_begin,
ifg_std_nodes_next,
ifg_std_nodes_break,
ifg_std_degree
};
......
......@@ -11,16 +11,19 @@
#include "beifg.h"
struct _be_ifg_impl_t {
size_t iter_size;
size_t nodes_iter_size;
size_t neighbours_iter_size;
void (*free)(void *self);
int (*connected)(const void *self, const ir_node *a, const ir_node *b);
ir_node *(*neighbours_begin)(const void *self, void *iter, const ir_node *irn);
ir_node *(*neighbours_next)(const void *self, void *iter);
void (*neighbours_break)(const void *self, void *iter);
ir_node *(*nodes_begin)(const void *self, void *iter);
ir_node *(*nodes_next)(const void *self, void *iter);
void (*nodes_break)(const void *self, void *iter);
int (*degree)(const void *self, const ir_node *irn);
};
......@@ -31,13 +34,14 @@ struct _be_ifg_t {
#ifdef _BE_IFG_USE_MACROS
#define be_ifg_iter_size(self) ((self)->impl->iter_size)
#define be_ifg_free(self) ((self)->impl->free(self))
#define be_ifg_connected(self,a,b) ((self)->impl->connected(self, a, b))
#define be_ifg_neighbours_begin(self, iter, irn) ((self)->impl->neighbours_begin(self, iter, irn))
#define be_ifg_neighbours_next(self, iter) ((self)->impl->neighbours_next(self, iter))
#define be_ifg_neighbours_break(self, iter) ((self)->impl->neighbours_break(self, iter))
#define be_ifg_nodes_begin(self, iter) ((self)->impl->nodes_begin(self, iter))
#define be_ifg_nodes_next(self, iter) ((self)->impl->nodes_next(self, iter))
#define be_ifg_nodes_break(self, iter) ((self)->impl->nodes_break(self, iter))
#define be_ifg_degree(self,irn) ((self)->impl->degree(self, irn))
#endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment