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;
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");
}
}
}
+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));