This commit is contained in:
fiplox 2022-01-04 01:59:00 +01:00
parent 68e2c51142
commit 4cf06046ab
7 changed files with 47 additions and 10 deletions

View File

@ -59,6 +59,7 @@ void find_funcs(const char *path, graph_vec *gv, graph_mco *gmc)
reallocarray(gv->node[cur_node]->succ, (gv->node[cur_node]->cap += 5), sizeof(nodept));
gv->node[cur_node]->succ[gv->node[cur_node]->nbs] = gv->node[index];
gv->node[cur_node]->nbs++;
gv->node[index]->call = true;
mcinsert_edge(gmc, cur_node, index);
} else {
@ -68,6 +69,7 @@ void find_funcs(const char *path, graph_vec *gv, graph_mco *gmc)
reallocarray(gv->node[cur_node]->succ, (gv->node[cur_node]->cap += 5), sizeof(nodept));
gv->node[cur_node]->succ[gv->node[cur_node]->nbs] = gv->node[gv->n];
gv->node[cur_node]->nbs++;
gv->node[gv->n]->call = true;
mcinsert_func(gmc, token);
mcinsert_edge(gmc, cur_node, -1);

View File

@ -33,11 +33,24 @@ int main(int argc, char *argv[])
// printf("%d.%s -> %d.%s\n", gmc.vec[i].i, gmc.func[gmc.vec[i].i], gmc.vec[i].j, gmc.func[gmc.vec[i].j]);
// }
// puts("\n");
vprint(gv.node[8], &gv);
mcprint(gmc, 8);
vfind_cycles(&gv);
mcfind_cycles(&gmc);
for (int i = 0; i <= gmc.nbs; ++i) {
if (!gmc.call[i]) {
mcprint(gmc, i);
puts("\n");
}
}
for (int i = 0; i <= gv.n; ++i) {
if (!gv.node[i]->call) {
vprint(gv.node[i], &gv);
puts("\n");
}
}
// vprint(gv.node[8], &gv);
// mcprint(gmc, 8);
//
// vfind_cycles(&gv);
// mcfind_cycles(&gmc);
vdot_graph(gv, true);
mcdot_graph(gmc, true);

View File

@ -14,9 +14,11 @@ graph_mco mcgragh(void)
g.nba = -1;
g.func = malloc((g.fcap = 10) * sizeof(fix_str));
assert(g.func);
g.call = malloc((g.fcap = 10) * sizeof(bool));
assert(g.call);
g.vec = malloc((g.vcap = 10) * sizeof(struct edge));
g.vu = NULL;
assert(g.vec);
g.vu = NULL;
return g;
}
@ -26,6 +28,8 @@ void mcinsert_func(graph_mco *g, fix_str i)
if (g->nbs == g->fcap) {
g->func = reallocarray(g->func, (g->fcap += 128), sizeof(fix_str));
assert(g->func);
g->call = reallocarray(g->call, g->fcap, sizeof(bool));
assert(g->call);
}
strcpy(g->func[g->nbs], i);
}
@ -39,10 +43,13 @@ void mcinsert_edge(graph_mco *g, int dep, int arr)
assert(g->vec);
}
e.i = dep;
if (arr == -1)
if (arr == -1) {
e.j = g->nbs;
else
g->call[g->nbs] = true;
} else {
e.j = arr;
g->call[arr] = true;
}
g->vec[g->nba] = e;
}
@ -80,20 +87,27 @@ static void mcprint_succ(graph_mco g, int succ)
static void mcprint_edges(graph_mco g, int n)
{
int i;
int i, j = 0;
if (g.vu[n])
return;
g.vu[n] = 1;
printf("NODE: %s\n", g.func[n]);
for (i = 0; i <= g.nba; ++i) {
if (g.vec[i].i == n) {
j++;
mcprint_succ(g, g.vec[i].j);
}
}
// HACK
if (j == 0) {
printf("\033[A\033[2K");
rewind(stdout);
}
for (i = 0; i <= g.nba; ++i) {
if (g.vec[i].i == n) {
if (g.vec[g.vec[i].j].i != -1)
mcprint_edges(g, g.vec[g.vec[i].j].i);
mcprint_edges(g, g.vec[i].j);
}
}
}

View File

@ -17,6 +17,7 @@ struct graph_mco {
int nba; // nombre d'aretes
int vcap; // capacité de vec
int fcap; // capacité de func
bool *call; // si la fontion a ete appele
int *vu; // status de sommets
fix_str *func; // noms de fonctions
struct edge *vec; // vecteur d'aretes

View File

@ -29,6 +29,7 @@ void vinsert_node(graph_vec *g, fix_str str)
n->nbs = 0;
n->vu = 0;
n->cap = 5;
n->call = false;
n->succ = malloc(5 * sizeof(nodept));
strcpy(n->func, str);
g->node[g->n] = n;

View File

@ -15,6 +15,7 @@ struct nodes {
};
struct node {
bool call; // fonction a ete appele ou pas
int vu; // status de noeud (`vu/en traitement/fini` pour dfs ou `vu/non vu` pour affichage)
int num; // le numero de noeud
int nbs; // nombre de successeurs

5
test.c
View File

@ -9,6 +9,11 @@ void bar(void);
int foo(void);
int toto(int a, int b);
void bobo(void)
{
aurevoir();
}
int aurevoir(void)
{
return 42;