ses_loop.c
authoryu.dongliang <18588496441@163.com>
Tue, 18 Jul 2023 08:52:39 +0000 (16:52 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 18 Jul 2023 08:52:39 +0000 (16:52 +0800)
ses_loop.c [new file with mode: 0644]

diff --git a/ses_loop.c b/ses_loop.c
new file mode 100644 (file)
index 0000000..607af4d
--- /dev/null
@@ -0,0 +1,96 @@
+#include"ses_core.h"
+
+static int __ses_dfs_tree(ScfEfunction* f, ScfEcomponent* root, scf_vector_t* edges, int64_t* total)
+{
+    ScfEcomponent* c;
+    ScfEpin*       p;
+    ScfEpin*       rp;
+
+       ses_edge_t*    e;
+
+    size_t i;
+    size_t j;
+
+       root->vflag = 1;
+
+       for (i = 0; i < root->n_pins; i++) {
+               rp =        root->pins[i];
+
+               if (rp->vflag)
+                       continue;
+               rp->vflag = 1;
+
+               for (j = 0; j + 1 < rp->n_tos; j += 2) {
+
+                       c  = f->components[rp->tos[j]];
+                       p  = c->pins      [rp->tos[j + 1]];
+
+                       if (c->vflag || p->vflag)
+                               continue;
+
+                       e = malloc(sizeof(ses_edge_t));
+                       if (!e)
+                               return -ENOMEM;
+
+                       e->c0 = root;
+                       e->p0 = rp;
+
+                       e->c1 = c;
+                       e->p1 = p;
+
+                       c->vflag = 1;
+                       p->vflag = 1;
+
+                       scf_loge("c%ld_p%ld --> c%ld_p%ld\n", root->id, rp->id, c->id, p->id);
+
+                       int ret = scf_vector_add(edges, e);
+                       if ( ret < 0)
+                               return ret;
+
+                       ret = __ses_dfs_tree(f, c, edges, total);
+                       if ( ret < 0)
+                               return ret;
+               }
+       }
+
+    root->dfo = --*total;
+
+       scf_logw("root->id: %ld, root->dfo: %ld\n", root->id, root->dfo);
+    return 0;
+}
+
+int ses_loop_function(ScfEfunction* f, scf_vector_t* loops)
+{
+       if (!f || !loops || f->n_components < 2)
+               return -EINVAL;
+
+       ScfEcomponent* c;
+       ScfEpin*       p;
+
+       scf_vector_t*  edges = scf_vector_alloc();
+       if (!edges)
+               return -ENOMEM;
+
+       size_t i;
+       size_t j;
+       size_t k;
+
+       int64_t total = f->n_components;
+
+       for (i = 0; i < f->n_components; i++) {
+               c         = f->components[i];
+               c->vflag  = 0;
+
+               for (j = 0; j < c->n_pins; j++) {
+                       p         = c->pins[j];
+                       p->vflag  = 0;
+               }
+       }
+
+       c = f->components[0];
+
+       c->pins[SCF_EDA_Battery_NEG]->vflag = 1;
+
+       __ses_dfs_tree(f, c, edges, &total);
+       return 0;
+}