return 0;
}
+static int __ses_branch_exist(ses_path_t* path, int i)
+{
+ if (!path->childs)
+ return 0;
+
+ ses_path_t* child;
+ ScfEpin* cp;
+ ScfEpin* p = path->pins->data[i];
+
+ int j;
+ int k;
+
+ for (j = 0; j < path->childs->size; j++) {
+ child = path->childs->data[j];
+
+ for (k = 0; k < child->pins->size; k++) {
+ cp = child->pins->data[k];
+
+ if (cp->lid == p->lid)
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static int __topo_path_diodes(ScfEfunction* f, ses_path_t* path)
+{
+ ses_info_t* info = NULL;
+ ScfEcomponent* c;
+ ScfEpin* p;
+
+ int i;
+ int j;
+
+ for (i = 0; i < path->pins->size; i++) {
+ p = path->pins->data[i];
+
+ c = f->components[p->cid];
+
+ if (SCF_EDA_Diode == c->type) {
+
+ if (!info) {
+ info = calloc(1, sizeof(ses_info_t));
+ if (!info)
+ return -ENOMEM;
+
+ info->i = i;
+ }
+
+ if (SCF_EDA_Diode_NEG == p->id) {
+ info->n_diodes++;
+
+ if (__ses_branch_exist(path, i))
+ goto _add;
+ }
+ continue;
+ }
+
+ if (SCF_EDA_NPN == c->type) {
+
+ if (SCF_EDA_NPN_B == p->id) {
+ if (!info) {
+ info = calloc(1, sizeof(ses_info_t));
+ if (!info)
+ return -ENOMEM;
+
+ info->i = i;
+ }
+
+ info->n_NPNs++;
+ continue;
+
+ } else if (SCF_EDA_NPN_E == p->id) {
+
+ if (__ses_branch_exist(path, i))
+ goto _add;
+
+ continue;
+ }
+ }
+
+_add:
+ if (info) {
+ info->j = i - 1;
+
+ if (scf_vector_add(path->diodes, info) < 0) {
+ free(info);
+ return -ENOMEM;
+ }
+
+ info = NULL;
+ }
+ }
+
+ if (info) {
+ info->j = i - 1;
+
+ if (scf_vector_add(path->diodes, info) < 0) {
+ free(info);
+ return -ENOMEM;
+ }
+
+ info = NULL;
+ }
+
+ return 0;
+}
+
+static int _topo_path_diodes(ScfEfunction* f, ses_path_t* path)
+{
+ ses_path_t* child;
+
+ int ret;
+ int i;
+
+ ret = __topo_path_diodes(f, path);
+ if (ret < 0)
+ return ret;
+
+ if (path->childs) {
+ for (i = 0; i < path->childs->size; i++) {
+ child = path->childs->data[i];
+
+ ret = _topo_path_diodes(f, child);
+ if (ret < 0)
+ return ret;
+ }
+ }
+
+ if (path->bridges) {
+ for (i = 0; i < path->bridges->size; i++) {
+ child = path->bridges->data[i];
+
+ ret = _topo_path_diodes(f, child);
+ if (ret < 0)
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
static int _topo_layers(ScfEfunction* f, scf_vector_t* paths)
{
ScfEcomponent* B;
_topo_path_sort(child);
- _topo_path_bridges(f, child);
+ int ret = _topo_path_bridges(f, child);
+ if (ret < 0)
+ return ret;
+
+ ret = _topo_path_diodes(f, child);
+ if (ret < 0)
+ return ret;
}
return 0;
static int _topo_diodes(ScfEfunction* f, ses_path_t* path)
{
- ses_info_t* info = NULL;
ScfEcomponent* c;
ScfEpin* p;
if (SCF_EDA_Diode == c->type) {
- if (!info) {
- info = calloc(1, sizeof(ses_info_t));
- if (!info)
- return -ENOMEM;
-
- info->i = i;
- }
-
- if (SCF_EDA_Diode_NEG == p->id) {
- info->n_diodes++;
+ if (SCF_EDA_Diode_NEG == p->id)
path->n_diodes++;
- }
- continue;
- }
- if (SCF_EDA_NPN == c->type) {
+ } else if (SCF_EDA_NPN == c->type) {
- if (SCF_EDA_NPN_B == p->id) {
- if (!info) {
- info = calloc(1, sizeof(ses_info_t));
- if (!info)
- return -ENOMEM;
-
- info->i = i;
- }
-
- info->n_NPNs++;
+ if (SCF_EDA_NPN_B == p->id)
path->n_diodes++;
- continue;
- } else if (SCF_EDA_NPN_E == p->id)
- continue;
- }
-
- if (info) {
- info->j = i - 1;
-
- if (scf_vector_add(path->diodes, info) < 0) {
- free(info);
- return -ENOMEM;
- }
-
- info = NULL;
}
}
- if (info) {
- info->j = i - 1;
-
- if (scf_vector_add(path->diodes, info) < 0) {
- free(info);
- return -ENOMEM;
- }
-
- info = NULL;
- }
-
return 0;
}