--- /dev/null
+#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;
+}