(ProtobufCMessageInit) scf_ecomponent__init,
NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor scf_efunction__field_descriptors[2] =
+static const ProtobufCFieldDescriptor scf_efunction__field_descriptors[3] =
{
{
"name",
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
+ {
+ "elines",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ offsetof(ScfEfunction, n_elines),
+ offsetof(ScfEfunction, elines),
+ &scf_eline__descriptor,
+ NULL,
+ 0, /* flags */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned scf_efunction__field_indices_by_name[] = {
1, /* field[1] = components */
+ 2, /* field[2] = elines */
0, /* field[0] = name */
};
static const ProtobufCIntRange scf_efunction__number_ranges[1 + 1] =
{
{ 1, 0 },
- { 0, 2 }
+ { 0, 3 }
};
const ProtobufCMessageDescriptor scf_efunction__descriptor =
{
"ScfEfunction",
"",
sizeof(ScfEfunction),
- 2,
+ 3,
scf_efunction__field_descriptors,
scf_efunction__field_indices_by_name,
1, scf_efunction__number_ranges,
return 0;
}
-int line_pair_cmp(const void* v0, const void* v1)
+int eline_cmp(const void* v0, const void* v1)
{
- const ses_line_pair_t* lp0 = v0;
- const ses_line_pair_t* lp1 = v1;
+ const ScfEline* el0 = v0;
+ const ScfEline* el1 = v1;
- if (lp0->n_components < lp1->n_components)
+ if (el0->n_conns < el1->n_conns)
return 1;
- if (lp0->n_components > lp1->n_components)
+ if (el0->n_conns > el1->n_conns)
return -1;
- if (lp0 < lp1)
- return -1;
-
- if (lp0 > lp1)
+ if (el0->n_pins < el1->n_pins)
return 1;
+ if (el0->n_pins > el1->n_pins)
+ return -1;
+
return 0;
}
-int ses_pins_same_line(ScfEfunction* f, scf_vector_t* lines)
+int ses_pins_same_line(ScfEfunction* f)
{
ScfEcomponent* c;
+ ScfEline* el;
ScfEpin* p;
ScfEpin* p2;
- scf_vector_t* lv;
-
size_t i;
size_t j;
size_t k;
qsort(p->tos, p->n_tos / 2, sizeof(uint64_t) * 2, epin_cmp);
- for (k = 0; k < lines->size; k++) {
- lv = lines->data[k];
+ for (k = 0; k < f->n_elines; k++) {
+ el = f->elines[k];
- for (m = 0; m < lv->size; m++) {
- p2 = lv->data[m];
+ for (m = 0; m + 1 < el->n_pins; m += 2) {
- if (p2->cid == p->cid && p2->id == p->id) {
- assert(p2 == p);
+ if (el->pins[m] == p->cid && el->pins[m + 1] == p->id)
goto next;
- }
}
m = 0;
n = 0;
- while (m < lv->size && n + 1 < p->n_tos) {
- p2 = lv->data[m];
+ while (m + 1 < el->n_pins && n + 1 < p->n_tos) {
- if (p2->cid < p->tos[n])
- m++;
- else if (p2->cid > p->tos[n])
+ if (el->pins[m] < p->tos[n])
+ m += 2;
+ else if (el->pins[m] > p->tos[n])
n += 2;
- else if (p2->id < p->tos[n + 1])
- m++;
- else if (p2->id > p->tos[n + 1])
+
+ else if (el->pins[m + 1] < p->tos[n + 1])
+ m += 2;
+ else if (el->pins[m + 1] > p->tos[n + 1])
n += 2;
else {
- if (scf_vector_add(lv, p) < 0)
+ if (scf_eline__add_pin(el, p->cid, p->id) < 0)
return -ENOMEM;
goto next;
}
}
- lv = scf_vector_alloc();
- if (!lv)
+ el = scf_eline__alloc();
+ if (!el)
return -ENOMEM;
+ el->id = f->n_elines;
- if (scf_vector_add(lines, lv) < 0) {
- scf_vector_free(lv);
+ if (scf_efunction__add_eline(f, el) < 0) {
+ scf_eline__free(el);
return -ENOMEM;
}
- if (scf_vector_add(lv, p) < 0)
+ if (scf_eline__add_pin(el, p->cid, p->id) < 0)
return -ENOMEM;
next:
p = NULL;
}
#if 1
- for (i = 0; i < lines->size; i++) {
- lv = lines->data[i];
+ for (i = 0; i < f->n_elines; i++) {
+ el = f->elines[i];
- scf_logw("line i: %ld, %p\n", i, lv);
+ scf_logw("line i: %ld, %p\n", i, el);
- for (j = 0; j < lv->size; j++) {
- p = lv->data[j];
+ for (j = 0; j + 1 < el->n_pins; j += 2)
- scf_logi("pin j: %ld, cid: %ld, pid: %ld\n", j, p->cid, p->id);
- }
+ scf_logi("pin j: %ld, cid: %ld, pid: %ld\n", j, el->pins[j], el->pins[j + 1]);
printf("\n");
}
return 0;
}
-int ses_lines_same_components(scf_vector_t* lines, scf_vector_t* pairs)
+int ses_lines_same_components(ScfEfunction* f)
{
- ses_line_pair_t* lp;
- scf_vector_t* lv0;
- scf_vector_t* lv1;
-
- ScfEpin* p0;
- ScfEpin* p1;
+ ScfEline* el0;
+ ScfEline* el1;
+ ScfEconn* ec;
size_t i;
size_t j;
size_t k0;
size_t k1;
- size_t n;
- for (i = 0; i < lines->size - 1; i++) {
- lv0 = lines->data[i];
+ ec = NULL;
- for (j = i + 1; j < lines->size; j++) {
- lv1 = lines->data[j];
+ for (i = 0; i < f->n_elines - 1; i++) {
+ el0 = f->elines[i];
+
+ for (j = i + 1; j < f->n_elines; j++) {
+ el1 = f->elines[j];
- n = 0;
k0 = 0;
k1 = 0;
- while (k0 < lv0->size && k1 < lv1->size) {
- p0 = lv0->data[k0];
- p1 = lv1->data[k1];
+ if (!ec) {
+ ec = scf_econn__alloc();
+ if (!ec)
+ return -ENOMEM;
+ }
+
+ assert(0 == ec->n_cids);
+
+ while (k0 + 1 < el0->n_pins && k1 + 1 < el1->n_pins) {
- if (p0->cid < p1->cid)
- k0++;
- else if (p0->cid > p1->cid)
- k1++;
+ uint64_t c0 = el0->pins[k0];
+ uint64_t c1 = el1->pins[k1];
+
+ if (c0 < c1)
+ k0 += 2;
+ else if (c0 > c1)
+ k1 += 2;
else {
- k0++;
- k1++;
- n++;
+ k0 += 2;
+ k1 += 2;
+
+ if (scf_econn__add_cid(ec, c0) < 0) {
+ scf_econn__free(ec);
+ return -ENOMEM;
+ }
}
}
- if (0 == n)
+ if (0 == ec->n_cids)
continue;
- lp = malloc(sizeof(ses_line_pair_t));
- if (!lp)
- return -ENOMEM;
+ ec->lid = el1->id;
- if (scf_vector_add(pairs, lp) < 0) {
- free(lp);
+ if (scf_eline__add_conn(el0, ec) < 0) {
+ scf_econn__free(ec);
return -ENOMEM;
}
-
- lp->lines[0] = lv0;
- lp->lines[1] = lv1;
- lp->n_components = n;
}
}
- scf_vector_qsort(pairs, line_pair_cmp);
+ if (ec) {
+ scf_econn__free(ec);
+ ec = NULL;
+ }
+
+ qsort(f->elines, f->n_elines, sizeof(ScfEline*), eline_cmp);
#if 1
- for (i = 0; i < pairs->size; i++) {
- lp = pairs->data[i];
+ for (i = 0; i < f->n_elines; i++) {
+ el0 = f->elines[i];
+
+ scf_logi("i: %ld, el0: %ld, n_pins: %ld\n", i, el0->id, el0->n_pins);
+
+ for (j = 0; j < el0->n_conns; j++) {
+ ec = el0->conns[j];
+
+ scf_logi("j: %ld, lid: %ld, n_cids: %ld\n", j, ec->lid, ec->n_cids);
+ }
- scf_logi("i: %ld, lv0: %p, lv1: %p, n_components: %ld\n",
- i, lp->lines[0], lp->lines[1], lp->n_components);
+ printf("\n");
}
#endif
+
+ return 0;
}
int ses_layout_board(ScfEboard* b, int x, int y, int w, int h)
ScfEline* l;
ScfEpin* p;
- scf_vector_t* lines;
- scf_vector_t* pairs;
-
size_t i;
size_t j;
size_t k;
printf("f: %s\n", f->name);
- lines = scf_vector_alloc();
- if (!lines)
- return -ENOMEM;
-
- pairs = scf_vector_alloc();
- if (!pairs) {
- scf_vector_free(lines);
- return -ENOMEM;
- }
-
- ses_pins_same_line(f, lines);
+ ses_pins_same_line(f);
- ses_lines_same_components(lines, pairs);
+ ses_lines_same_components(f);
}
return 0;