From: yu.dongliang <18588496441@163.com> Date: Thu, 27 Jul 2023 16:00:23 +0000 (+0800) Subject: topo layer X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=5b33cff4c19ec7b965c76e43ce805e3492264cc8;p=ses.git topo layer --- diff --git a/ses_core.h b/ses_core.h index eb023c0..dba8c55 100644 --- a/ses_core.h +++ b/ses_core.h @@ -31,6 +31,7 @@ struct ses_path_s ses_path_t* parent; int type; + int index; }; struct ses_ctx_s @@ -49,6 +50,7 @@ struct ses_step_s ses_path_t* ses_path_alloc(); void ses_path_free (ses_path_t* path); +void ses_path_print(ses_path_t* path); ses_ctx_t* ses_ctx_alloc(); void ses_ctx_free (ses_ctx_t* ctx); diff --git a/ses_step_topo.c b/ses_step_topo.c index 8334256..3a89106 100644 --- a/ses_step_topo.c +++ b/ses_step_topo.c @@ -160,6 +160,73 @@ end: return ret; } +static int _topo_layers(ses_ctx_t* ctx) +{ + ses_path_t* path0; + ses_path_t* path1; + ScfEpin* p0; + ScfEpin* p1; + ScfEpin* p; + + int i; + int j; + int k; + + for (i = 0; i < ctx->paths->size; i++) { + path0 = ctx->paths->data[i]; + path0->index = i; + } + + for (i = ctx->paths->size - 1; i >= 1; i--) { + path0 = ctx->paths->data[i]; + + assert(path0->pins->size >= 2); + + p0 = path0->pins->data[0]; + p1 = path0->pins->data[path0->pins->size - 1]; + + for (j = i - 1; j >= 0; j--) { + path1 = ctx->paths->data[j]; + + int n = 0; + + for (k = 0; k < path1->pins->size; k++) { + p = path1->pins->data[k]; + + if (p->lid == p0->lid || p->lid == p1->lid) { + n++; + if (2 == n) + goto branch; + } + } + } + + continue; + +branch: + if (!path1->childs) { + path1->childs = scf_vector_alloc(); + if (!path1->childs) + return -ENOMEM; + } + + if (scf_vector_del(ctx->paths, path0) < 0) { + scf_loge("i: %d, ctx->paths->size: %d\n", i, ctx->paths->size); + return -1; + } + + if (scf_vector_add(path1->childs, path0) < 0) { + ses_path_free(path0); + return -ENOMEM; + } + + path0->parent = path1; + path0->type = SES_PATH_BRANCH; + } + + return 0; +} + static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) { ses_path_t* path; @@ -231,17 +298,17 @@ static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* scf_vector_qsort(ctx->paths, _ses_path_cmp); + int ret = _topo_layers(ctx); + if (ret < 0) + return ret; + #if 1 for (i = 0; i < ctx->paths->size; i++) { path = ctx->paths->data[i]; scf_logi("i: %ld, path->type: %d\n", i, path->type); - for (j = 0; j < path->pins->size; j++) { - p = path->pins->data[j]; - - scf_logi("i: %ld, j: %ld, c%ldp%ld\n", i, j, p->cid, p->id); - } + ses_path_print(path); printf("\n"); } diff --git a/ses_steps.c b/ses_steps.c index 72678b2..4f2903f 100644 --- a/ses_steps.c +++ b/ses_steps.c @@ -65,6 +65,38 @@ void ses_path_free(ses_path_t* path) } } +void ses_path_print(ses_path_t* path) +{ + if (!path) + return; + + ses_path_t* path2; + ScfEpin* p; + + int i; + + if (!path->parent) + printf("\033[31mpath: %d, \033[0m", path->index); + + for (i = 0; i < path->pins->size; i++) { + p = path->pins->data[i]; + + printf("c%ldp%ld ", p->cid, p->id); + } + printf("\n"); + + if (!path->childs) + return; + + for (i = 0; i < path->childs->size; i++) { + path2 = path->childs->data[i]; + + printf("\033[32mchild: %d, parent: %d, \033[0m", path2->index, path->index); + + ses_path_print(path2); + } +} + ses_ctx_t* ses_ctx_alloc() { ses_ctx_t* ctx = calloc(1, sizeof(ses_ctx_t));