return tj.head;
}
-struct list *edges_expr(int ndecls, struct decl **decls, void *parent,
- struct expr *expr, struct list *l)
+struct array edges_expr(int ndecls, struct decl **decls, void *parent,
+ struct expr *expr, struct array l)
{
if (expr == NULL)
return l;
struct edge *edge = xalloc(1, struct edge);
edge->from = parent;
edge->to = (void *)decls[i];
- l = list_cons(edge, l);
+ l = array_append(l, edge);
found = true;
}
}
return l;
}
-struct list *edges_stmt(int ndecls, struct decl **decls, void *parent,
- struct stmt *stmt, struct list *l)
+struct array edges_stmt(int ndecls, struct decl **decls, void *parent,
+ struct stmt *stmt, struct array l)
{
switch(stmt->type) {
case sassign:
//Calculate the edges
struct decl **fundecls = ast->decls+ffun;
- struct list *edges = NULL;
+ struct array edges;
+ array_init(&edges, nfun*2);
for (size_t i = 0; i<nfun; i++) {
ARRAY_ITER(struct stmt *, s, j, fundecls[i]->data.dfun->body)
edges = edges_stmt(nfun, fundecls, fundecls[i], s, edges);
AIEND
}
- int nedges;
- struct edge **edata = (struct edge **)
- list_to_array(edges, &nedges, false, 0);
// Do tarjan's and convert back into the declaration list
- struct components *cs = tarjans(nfun, (void **)fundecls, nedges, edata);
+ struct components *cs = tarjans(nfun, (void **)fundecls,
+ ARRAY_SIZE(edges), ARRAY_ELS(struct edge *, edges));
int i = ffun;
for (struct components *c = cs; c != NULL; c = c->next) {
ast->ndecls = i;
//Cleanup
- for (int i = 0; i<nedges; i++)
- free(edata[i]);
- free(edata);
+ array_free(edges, free);
struct components *t;
while (cs != NULL) {