topo layer
authoryu.dongliang <18588496441@163.com>
Thu, 27 Jul 2023 16:00:23 +0000 (00:00 +0800)
committeryu.dongliang <18588496441@163.com>
Thu, 27 Jul 2023 16:00:23 +0000 (00:00 +0800)
ses_core.h
ses_step_topo.c
ses_steps.c

index eb023c0bacf49d0208f9f5626977f6ca2c67c4c8..dba8c555e2b2872c0cbfdedc162c5f9214dfa3cb 100644 (file)
@@ -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);
index 83342565423158d3788d7411b768909424003d95..3a8910620f2db6fb1870b69e9f10aab09f0608d2 100644 (file)
@@ -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");
        }
index 72678b243126b2a404fdff8b824bcf8263ebf56b..4f2903fa6e056cd9668d23acf6362051a3b87a89 100644 (file)
@@ -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));