static void freeDerivedGraph(graph_t * g, graph_t ** cc) { graph_t *cg; node_t *dn; node_t *dnxt; edge_t *e; while ((cg = *cc++)) { freeGData(cg); agdelrec(cg, "Agraphinfo_t"); } if (PORTS(g)) free(PORTS(g)); freeGData(g); agdelrec(g, "Agraphinfo_t"); for (dn = agfstnode(g); dn; dn = dnxt) { dnxt = agnxtnode(g, dn); for (e = agfstout(g, dn); e; e = agnxtout(g, e)) { free (ED_to_virt(e)); agdelrec(e, "Agedgeinfo_t"); } freeDeriveNode(dn); } agclose(g); }
static bool port_append_res (struct list_res *res, const struct rule *r, const struct tf *tf, const struct res *in, int32_t ports, bool append, const struct hs *hs, bool inv_remove_deps) { /* Create new result containing headerspace `hs` for each port in `ports`. */ bool used_hs = false; struct hs *new_hs; uint32_t n, x; const uint32_t *a; if (ports > 0) { n = 1; x = ports; a = &x; } else { const struct ports *p = PORTS (tf, ports); n = p->n; a = p->arr; } for (int i = 0; i < n; i++) { if (a[i] == in->port) continue; if (inv_remove_deps) { /* For inversion, also remove dependencies for each input port of the inverted rule. */ new_hs = hs_create (hs->len); hs_copy (new_hs, hs); if (r->deps) deps_diff_inv (new_hs, a[i], DEPS (tf, r->deps), tf); if (!hs_compact_m (new_hs, r->mask ? DATA_ARR (r->mask) : NULL)) { hs_destroy(new_hs); continue; } } else new_hs = (struct hs*) hs; // now *new_hs has the latest hs at this port struct res *tmp; if (! inv_remove_deps) { if (used_hs) tmp = res_extend (in, hs, a[i], append); else { tmp = res_extend (in, NULL, a[i], append); tmp->hs = *hs; used_hs = true; } } else { tmp = res_extend (in, NULL, a[i], append); tmp->hs = *new_hs; } res_rule_add (tmp, tf, r->idx, r); list_append (res, tmp); } return used_hs; }
static void print_ports (int32_t p, const struct tf *tf) { if (p >= 0) { if (p > 0) printf ("%" PRId32, p); printf ("\n"); return; } const struct ports *ports = PORTS (tf, p); for (int i = 0; i < ports->n; i++) { if (i) printf (", "); printf ("%" PRIu32, ports->arr[i]); } printf ("\n"); }
/* dumpE: */ void dumpE(graph_t * g, int derived) { Agnode_t *n; Agedge_t *e; Agedge_t **ep; Agedge_t *el; int i; int deg; prIndent(); fprintf(stderr, "Graph %s : %d nodes %d edges\n", g->name, agnnodes(g), agnedges(g)); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { deg = 0; for (e = agfstout(g, n); e; e = agnxtout(g, e)) { deg++; prIndent(); fprintf(stderr, " %s -- %s\n", e->tail->name, e->head->name); if (derived) { for (i = 0, ep = (Agedge_t **) ED_to_virt(e); i < ED_count(e); i++, ep++) { el = *ep; prIndent(); fprintf(stderr, " %s -- %s\n", el->tail->name, el->head->name); } } } if (deg == 0) { /* no out edges */ if (!agfstin(g, n)) /* no in edges */ fprintf(stderr, " %s\n", n->name); } } if (!derived) { bport_t *pp; if ((pp = PORTS(g))) { int sz = NPORTS(g); fprintf(stderr, " %d ports\n", sz); while (pp->e) { fprintf(stderr, " %s : %s -- %s\n", pp->n->name, pp->e->tail->name, pp->e->head->name); pp++; } } } }
static struct list_res rule_apply (const struct rule *r, const struct tf *tf, const struct res *in, bool append, uint32_t *app, int *napp) { struct list_res res = {0}; if (!r->out) app_add (r->idx, app, napp); if (!r->out || r->out == in->port) return res; struct hs hs; if (!r->match) hs_copy (&hs, &in->hs); else { if (!hs_isect_arr (&hs, &in->hs, DATA_ARR (r->match))) return res; if (r->deps) deps_diff (&hs, in->port, DEPS (tf, r->deps), tf, app, *napp); if (!hs_compact_m (&hs, r->mask ? DATA_ARR (r->mask) : NULL)) { hs_destroy (&hs); return res; } if (r->mask) hs_rewrite (&hs, DATA_ARR (r->mask), DATA_ARR (r->rewrite)); } bool used_hs = false; uint32_t n, x; const uint32_t *a; if (r->out > 0) { n = 1; x = r->out; a = &x; } else { const struct ports *p = PORTS (tf, r->out); n = p->n; a = p->arr; } for (int i = 0; i < n; i++) { if (a[i] == in->port) continue; struct res *tmp; if (used_hs) tmp = res_extend (in, &hs, a[i], append); else { tmp = res_extend (in, NULL, a[i], append); tmp->hs = hs; used_hs = true; } res_rule_add (tmp, tf, r->idx); list_append (&res, tmp); } if (res.head) app_add (r->idx, app, napp); if (!used_hs) hs_destroy (&hs); return res; }
static void cleanup_subgs(graph_t * g) { graph_t *mg; edge_t *me; node_t *mn; graph_t *subg; mg = g->meta_node->graph; for (me = agfstout(mg, g->meta_node); me; me = agnxtout(mg, me)) { mn = me->head; subg = agusergraph(mn); free_label(GD_label(subg)); if (GD_alg(subg)) { free(PORTS(subg)); free(GD_alg(subg)); } cleanup_subgs(subg); } }
/* fdp_tLayout: * Given graph g with ports nodes, layout g respecting ports. * If some node have position information, it may be useful to * reset temperature and other parameters to reflect this. */ void fdp_tLayout (graph_t* g, xparams* xpms) { int i; int reset; bport_t* pp = PORTS(g); double temp; Grid* grid; pointf ctr; Agnode_t* n; reset = init_params(g, xpms); temp = T0; ctr = initPositions (g, pp); if (T_useGrid) { grid = mkGrid (agnnodes (g)); adjustGrid (grid, agnnodes (g)); for (i = 0; i < loopcnt; i++) { temp = cool (temp, i); gAdjust (g, temp, pp, grid); } delGrid (grid); } else { for (i = 0; i < loopcnt; i++) { temp = cool (temp, i); adjust (g, temp, pp); } } if ((ctr.x != 0.0) || (ctr.y != 0.0)) { for (n = agfstnode(g); n; n = agnxtnode(g,n)) { ND_pos(n)[0] += ctr.x; ND_pos(n)[1] += ctr.y; } } dumpstat (g); if (reset) reset_params (); }
static bool port_match (uint32_t port, int32_t ofs, const struct tf *tf) { const struct ports *p = PORTS (tf, ofs); return int_find (port, p->arr, p->n); }