From: yu.dongliang <18588496441@163.com> Date: Tue, 26 Sep 2023 06:27:12 +0000 (+0800) Subject: ses_path_add() X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=ac3d23c762d80c400ff0a9c6725d492fccbc5f3d;p=ses.git ses_path_add() --- diff --git a/ses_core.h b/ses_core.h index 2cef386..16d873e 100644 --- a/ses_core.h +++ b/ses_core.h @@ -48,7 +48,10 @@ struct ses_path_s scf_vector_t* pins; scf_vector_t* childs; + ses_path_t* parent; + int parent_p0; + int parent_p1; double r0; double jr0; @@ -85,6 +88,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); +int ses_path_add (ses_path_t* path, ses_path_t* child); ses_flow_t* ses_flow_alloc(); void ses_flow_free (ses_flow_t* flow); diff --git a/ses_step_topo.c b/ses_step_topo.c index de871c0..8366c6a 100644 --- a/ses_step_topo.c +++ b/ses_step_topo.c @@ -164,13 +164,10 @@ int __dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_vector_t* __ static int _topo_layers(scf_vector_t* paths) { - ses_path_t* path0; - ses_path_t* path1; - ses_path_t* path2; + ses_path_t* child; + ses_path_t* parent; ScfEpin* p0; ScfEpin* p1; - ScfEpin* p2; - ScfEpin* p3; ScfEpin* p; int i; @@ -178,25 +175,25 @@ static int _topo_layers(scf_vector_t* paths) int k; for (i = 0; i < paths->size; i++) { - path0 = paths->data[i]; - path0->index = i; + child = paths->data[i]; + child->index = i; } for (i = paths->size - 1; i >= 1; i--) { - path0 = paths->data[i]; + child = paths->data[i]; - assert(path0->pins->size >= 2); + assert(child->pins->size >= 2); - p0 = path0->pins->data[0]; - p1 = path0->pins->data[path0->pins->size - 1]; + p0 = child->pins->data[0]; + p1 = child->pins->data[child->pins->size - 1]; - for (j = i - 1; j >= 0; j--) { - path1 = paths->data[j]; + for (j = i - 1; j >= 0; j--) { + parent = paths->data[j]; - int n = 0; + int n = 0; - for (k = 0; k < path1->pins->size; k++) { - p = path1->pins->data[k]; + for (k = 0; k < parent->pins->size; k++) { + p = parent->pins->data[k]; if (p->lid == p0->lid) n |= 0x1; @@ -212,37 +209,13 @@ static int _topo_layers(scf_vector_t* paths) continue; branch: - if (!path1->childs) { - path1->childs = scf_vector_alloc(); - if (!path1->childs) - return -ENOMEM; - - } else { - for (j = 0; j < path1->childs->size; j++) { - path2 = path1->childs->data[j]; - - p2 = path2->pins->data[0]; - p3 = path2->pins->data[path2->pins->size - 1]; - - if (p2->lid == p0->lid && p3->lid == p1->lid) { - path1 = path2; - break; - } - } - } - - if (scf_vector_del(paths, path0) < 0) + if (scf_vector_del(paths, child) < 0) return -1; - scf_loge("path0: %d, path1: %d\n", path0->index, path1->index); - - if (scf_vector_add(path1->childs, path0) < 0) { - ses_path_free(path0); + if (ses_path_add(parent, child) < 0) { + ses_path_free(child); return -ENOMEM; } - - path0->parent = path1; - path0->type = SES_PATH_BRANCH; } return 0; diff --git a/ses_steps.c b/ses_steps.c index 1db1066..bc221aa 100644 --- a/ses_steps.c +++ b/ses_steps.c @@ -398,6 +398,56 @@ void ses_path_print(ses_path_t* path) } } +int ses_path_add(ses_path_t* parent, ses_path_t* child) +{ + if (!parent || !child) + return -EINVAL; + + if (!parent->childs) { + parent->childs = scf_vector_alloc(); + if (!parent->childs) + return -ENOMEM; + } + + ses_path_t* path; + ScfEpin* p0; + ScfEpin* p1; + ScfEpin* cp0 = child->pins->data[0]; + ScfEpin* cp1 = child->pins->data[child->pins->size - 1]; + + int j; + + for (j = 0; j < parent->childs->size; j++) { + path = parent->childs->data[j]; + + p0 = path->pins->data[0]; + p1 = path->pins->data[path->pins->size - 1]; + + if (p0->lid == cp0->lid && p1->lid == cp1->lid) + return ses_path_add(path, child); + } + + if (scf_vector_add(parent->childs, child) < 0) + return -ENOMEM; + + for (j = 0; j < parent->pins->size; j++) { + p0 = parent->pins->data[j]; + + if (p0->lid == cp0->lid) + child->parent_p0 = j; + + if (p0->lid == cp1->lid) { + child->parent_p1 = j; + break; + } + } + assert(child->parent_p0 >= 0 && child->parent_p1 >= 0); + + child->parent = parent; + child->type = SES_PATH_BRANCH; + return 0; +} + ses_ctx_t* ses_ctx_alloc() { ses_ctx_t* ctx = calloc(1, sizeof(ses_ctx_t));