From 26e171bd21fd189112eb74ef8c272c2525a8c8e5 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Fri, 7 Jul 2023 14:49:34 +0800 Subject: [PATCH] tmp --- Makefile | 1 + main.c | 8 +- scf_eda.c | 148 ------------ scf_eda.h | 66 ------ scf_eda_inst.c | 625 ------------------------------------------------- ses_layout.c | 63 ++++- ses_layout.h | 1 + 7 files changed, 65 insertions(+), 847 deletions(-) delete mode 100644 scf_eda.c delete mode 100644 scf_eda.h delete mode 100644 scf_eda_inst.c diff --git a/Makefile b/Makefile index 4300770..adc38c4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ CFILES += main.c CFILES += scf_eda.pb-c.c CFILES += scf_eda_pb.c +CFILES += ses_layout.c CFLAGS += -g CFLAGS += -I./ diff --git a/main.c b/main.c index f68fb56..6baa21c 100644 --- a/main.c +++ b/main.c @@ -1,10 +1,7 @@ #include #include #include -#include"scf_eda_pb.h" -#include"scf_def.h" - - +#include"ses_layout.h" int main(int argc, char* argv[]) { @@ -49,6 +46,8 @@ int main(int argc, char* argv[]) ScfEboard* b = scf_eboard__unpack(NULL, len, pb); + ses_layout_board(b, 0, 0, 100, 100); +#if 0 size_t i; size_t j; size_t k; @@ -72,6 +71,7 @@ int main(int argc, char* argv[]) } printf("\n\n"); } +#endif scf_eboard__free_unpacked(b, NULL); return 0; diff --git a/scf_eda.c b/scf_eda.c deleted file mode 100644 index fec807a..0000000 --- a/scf_eda.c +++ /dev/null @@ -1,148 +0,0 @@ -#include"scf_eda.h" -#include"scf_basic_block.h" -#include"scf_3ac.h" - -int scf_eda_open(scf_native_t* ctx, const char* arch) -{ - scf_eda_context_t* eda = calloc(1, sizeof(scf_eda_context_t)); - if (!eda) - return -ENOMEM; - - ctx->priv = eda; - return 0; -} - -int scf_eda_close(scf_native_t* ctx) -{ - scf_eda_context_t* eda = ctx->priv; - - if (eda) { - free(eda); - eda = NULL; - } - return 0; -} - -static int _eda_make_insts_for_list(scf_native_t* ctx, scf_list_t* h, int bb_offset) -{ - scf_list_t* l; - int ret; - - for (l = scf_list_head(h); l != scf_list_sentinel(h); l = scf_list_next(l)) { - - scf_3ac_code_t* c = scf_list_data(l, scf_3ac_code_t, list); - - eda_inst_handler_t* h = scf_eda_find_inst_handler(c->op->type); - if (!h) { - scf_loge("3ac operator '%s' not supported\n", c->op->name); - return -EINVAL; - } - - ret = h->func(ctx, c); - if (ret < 0) { - scf_3ac_code_print(c, NULL); - scf_loge("3ac op '%s' make inst failed\n", c->op->name); - return ret; - } - - if (!c->instructions) - continue; - - scf_3ac_code_print(c, NULL); - } - - return bb_offset; -} - -int _scf_eda_select_inst(scf_native_t* ctx) -{ - scf_eda_context_t* eda = ctx->priv; - scf_function_t* f = eda->f; - scf_basic_block_t* bb; - scf_bb_group_t* bbg; - - int i; - int j; - int ret = 0; - - for (i = 0; i < f->bb_groups->size; i++) { - bbg = f->bb_groups->data[i]; - - for (j = 0; j < bbg->body->size; j++) { - bb = bbg->body->data[j]; - - assert(!bb->native_flag); - - scf_loge("************ bb: %d\n", bb->index); - ret = _eda_make_insts_for_list(ctx, &bb->code_list_head, 0); - if (ret < 0) - return ret; - bb->native_flag = 1; - scf_loge("************ bb: %d\n", bb->index); - } - } - - for (i = 0; i < f->bb_loops->size; i++) { - bbg = f->bb_loops->data[i]; - - for (j = 0; j < bbg->body->size; j++) { - bb = bbg->body->data[j]; - - assert(!bb->native_flag); - - ret = _eda_make_insts_for_list(ctx, &bb->code_list_head, 0); - if (ret < 0) - return ret; - bb->native_flag = 1; - } - } - - return 0; -} - -int scf_eda_select_inst(scf_native_t* ctx, scf_function_t* f) -{ - scf_eda_context_t* eda = ctx->priv; - ScfEcomponent* B = NULL; - - scf_dag_node_t* dn; - scf_list_t* l; - - eda->f = f; - - assert(!f->ef); - - f->ef = scf_efunction__alloc(f->node.w->text->data); - if (!f->ef) - return -ENOMEM; - - EDA_INST_ADD_COMPONENT(f, B, SCF_EDA_Battery); - - int ret = _scf_eda_select_inst(ctx); - if (ret < 0) - return ret; - - for (l = scf_list_head(&f->dag_list_head); l != scf_list_sentinel(&f->dag_list_head); l = scf_list_next(l)) { - - dn = scf_list_data(l, scf_dag_node_t, list); - - if (dn->var && dn->var->arg_flag) { - - int i; - for (i = 0; i < dn->n_pins; i++) - dn->pins[i]->flags |= SCF_EDA_PIN_IN; - } - } - - return 0; -} - -scf_native_ops_t native_ops_eda = { - .name = "eda", - - .open = scf_eda_open, - .close = scf_eda_close, - - .select_inst = scf_eda_select_inst, -}; - diff --git a/scf_eda.h b/scf_eda.h deleted file mode 100644 index 5dafe64..0000000 --- a/scf_eda.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef SCF_EDA_H -#define SCF_EDA_H - -#include"scf_native.h" -#include"scf_eda_pb.h" - -#define EDA_INST_ADD_COMPONENT(_f, _c, _type) \ - do { \ - _c = scf_ecomponent__alloc(_type); \ - if (!_c) \ - return -ENOMEM; \ - \ - (_c)->id = (_f)->ef->n_components; \ - \ - int ret = scf_efunction__add_component((_f)->ef, _c); \ - if (ret < 0) { \ - scf_ecomponent__free(_c); \ - _c = NULL; \ - return ret; \ - } \ - \ - for (size_t i = 0; i < (_c)->n_pins; i++) \ - (_c)->pins[i]->cid = (_c)->id; \ - } while (0) - - -#define EDA_PIN_ADD_COMPONENT(_pin, _cid, _pid) \ - do { \ - int ret = scf_epin__add_component((_pin), (_cid), (_pid)); \ - if (ret < 0) \ - return ret; \ - \ - } while (0) - -typedef struct { - - scf_function_t* f; - -} scf_eda_context_t; - -typedef struct { - int type; - int (*func)(scf_native_t* ctx, scf_3ac_code_t* c); -} eda_inst_handler_t; - -eda_inst_handler_t* scf_eda_find_inst_handler(const int op_type); - -int scf_eda_open (scf_native_t* ctx, const char* arch); -int scf_eda_close (scf_native_t* ctx); -int scf_eda_select(scf_native_t* ctx); - -static inline int eda_variable_size(scf_variable_t* v) -{ - if (v->nb_dimentions + v->nb_pointers > 0) - return 64; - - if (v->type >= SCF_STRUCT) - return 64; - - if (SCF_VAR_BIT == v->type) - return 1; - - return v->size << 3; -} - -#endif diff --git a/scf_eda_inst.c b/scf_eda_inst.c deleted file mode 100644 index bf7b376..0000000 --- a/scf_eda_inst.c +++ /dev/null @@ -1,625 +0,0 @@ -#include"scf_eda.h" - -#define EDA_INST_OP2_CHECK() \ - if (!c->dsts || c->dsts->size != 1) \ - return -EINVAL; \ - \ - if (!c->srcs || c->srcs->size != 1) \ - return -EINVAL; \ - \ - scf_eda_context_t* eda = ctx->priv; \ - scf_function_t* f = eda->f; \ - \ - scf_3ac_operand_t* dst = c->dsts->data[0]; \ - scf_3ac_operand_t* src = c->srcs->data[0]; \ - \ - if (!src || !src->dag_node) \ - return -EINVAL; \ - \ - if (!dst || !dst->dag_node) \ - return -EINVAL; \ - \ - if (src->dag_node->var->size != dst->dag_node->var->size) {\ - scf_loge("size: %d, %d\n", src->dag_node->var->size, dst->dag_node->var->size); \ - return -EINVAL; \ - } - -#define EDA_INST_OP3_CHECK() \ - if (!c->dsts || c->dsts->size != 1) \ - return -EINVAL; \ - \ - if (!c->srcs || c->srcs->size != 2) \ - return -EINVAL; \ - \ - scf_eda_context_t* eda = ctx->priv; \ - scf_function_t* f = eda->f; \ - \ - scf_3ac_operand_t* dst = c->dsts->data[0]; \ - scf_3ac_operand_t* src0 = c->srcs->data[0]; \ - scf_3ac_operand_t* src1 = c->srcs->data[1]; \ - \ - if (!src0 || !src0->dag_node) \ - return -EINVAL; \ - \ - if (!src1 || !src1->dag_node) \ - return -EINVAL; \ - \ - if (!dst || !dst->dag_node) \ - return -EINVAL; \ - \ - if (src0->dag_node->var->size != src1->dag_node->var->size) {\ - scf_loge("size: %d, %d\n", src0->dag_node->var->size, src1->dag_node->var->size); \ - return -EINVAL; \ - } - -#define EDA_INST_IN_CHECK(_in, _N) \ - do { \ - int i; \ - if (!(_in)->var->arg_flag) { \ - if ((_in)->n_pins != _N) \ - return -EINVAL; \ - \ - for (i = 0; i < N; i++) { \ - if (!(_in)->pins[i]) \ - return -EINVAL; \ - } \ - } \ - } while (0) - -static int _eda_inst_bit_not_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - EDA_INST_OP2_CHECK() - - scf_dag_node_t* in = src->dag_node; - scf_dag_node_t* out = dst->dag_node; - - ScfEcomponent* T = NULL; - ScfEcomponent* R = NULL; - ScfEcomponent* B = f->ef->components[0]; - - int i; - int N = eda_variable_size(in->var); - - EDA_INST_IN_CHECK(in, N); - - in ->n_pins = N; - out->n_pins = N; - - for (i = 0; i < N; i++) { - - EDA_INST_ADD_COMPONENT(f, T, SCF_EDA_Transistor); - EDA_INST_ADD_COMPONENT(f, R, SCF_EDA_Resistor); - - in->pins[i] = T->pins[SCF_EDA_Transistor_B]; - - EDA_PIN_ADD_COMPONENT(T->pins[SCF_EDA_Transistor_C], R->id, 1); - EDA_PIN_ADD_COMPONENT(T->pins[SCF_EDA_Transistor_E], B->id, SCF_EDA_Battery_NEG); - - EDA_PIN_ADD_COMPONENT(R->pins[0], B->id, SCF_EDA_Battery_POS); - EDA_PIN_ADD_COMPONENT(R->pins[1], T->id, SCF_EDA_Transistor_C); - - out->pins[i] = T->pins[SCF_EDA_Transistor_C]; - } - - return 0; -} - -static int _eda_inst_bit_and_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - EDA_INST_OP3_CHECK() - - scf_dag_node_t* in0 = src0->dag_node; - scf_dag_node_t* in1 = src1->dag_node; - scf_dag_node_t* out = dst ->dag_node; - - ScfEcomponent* D0 = NULL; - ScfEcomponent* D1 = NULL; - ScfEcomponent* R = NULL; - ScfEcomponent* B = f->ef->components[0]; - - int i; - int N = eda_variable_size(in0->var); - - EDA_INST_IN_CHECK(in0, N); - EDA_INST_IN_CHECK(in1, N); - - in0->n_pins = N; - in1->n_pins = N; - out->n_pins = N; - - for (i = 0; i < N; i++) { - - EDA_INST_ADD_COMPONENT(f, D0, SCF_EDA_Diode); - EDA_INST_ADD_COMPONENT(f, D1, SCF_EDA_Diode); - EDA_INST_ADD_COMPONENT(f, R, SCF_EDA_Resistor); - - in0->pins[i] = D0->pins[SCF_EDA_Diode_NEG]; - in1->pins[i] = D1->pins[SCF_EDA_Diode_NEG]; - - EDA_PIN_ADD_COMPONENT(D0->pins[SCF_EDA_Diode_POS], D1->id, SCF_EDA_Diode_POS); - EDA_PIN_ADD_COMPONENT(D0->pins[SCF_EDA_Diode_POS], R ->id, 1); - - EDA_PIN_ADD_COMPONENT(D1->pins[SCF_EDA_Diode_POS], D0->id, SCF_EDA_Diode_POS); - EDA_PIN_ADD_COMPONENT(D1->pins[SCF_EDA_Diode_POS], R ->id, 1); - - EDA_PIN_ADD_COMPONENT(R->pins[1], D0->id, SCF_EDA_Diode_POS); - EDA_PIN_ADD_COMPONENT(R->pins[1], D1->id, SCF_EDA_Diode_POS); - EDA_PIN_ADD_COMPONENT(R->pins[0], B ->id, SCF_EDA_Battery_POS); - - out->pins[i] = R ->pins[1]; - } - - return 0; -} - -static int _eda_inst_bit_or_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - EDA_INST_OP3_CHECK() - - scf_dag_node_t* in0 = src0->dag_node; - scf_dag_node_t* in1 = src1->dag_node; - scf_dag_node_t* out = dst ->dag_node; - - ScfEcomponent* D0 = NULL; - ScfEcomponent* D1 = NULL; - ScfEcomponent* R = NULL; - ScfEcomponent* B = f->ef->components[0]; - - int i; - int N = eda_variable_size(in0->var); - - EDA_INST_IN_CHECK(in0, N); - EDA_INST_IN_CHECK(in1, N); - - in0->n_pins = N; - in1->n_pins = N; - out->n_pins = N; - - for (i = 0; i < N; i++) { - - EDA_INST_ADD_COMPONENT(f, D0, SCF_EDA_Diode); - EDA_INST_ADD_COMPONENT(f, D1, SCF_EDA_Diode); - EDA_INST_ADD_COMPONENT(f, R, SCF_EDA_Resistor); - - in0->pins[i] = D0->pins[SCF_EDA_Diode_POS]; - in1->pins[i] = D1->pins[SCF_EDA_Diode_POS]; - - EDA_PIN_ADD_COMPONENT(D0->pins[SCF_EDA_Diode_NEG], D1->id, SCF_EDA_Diode_NEG); - EDA_PIN_ADD_COMPONENT(D0->pins[SCF_EDA_Diode_NEG], R ->id, 0); - - EDA_PIN_ADD_COMPONENT(D1->pins[SCF_EDA_Diode_NEG], D0->id, SCF_EDA_Diode_NEG); - EDA_PIN_ADD_COMPONENT(D1->pins[SCF_EDA_Diode_NEG], R ->id, 0); - - EDA_PIN_ADD_COMPONENT(R->pins[0], D0->id, SCF_EDA_Diode_NEG); - EDA_PIN_ADD_COMPONENT(R->pins[0], D1->id, SCF_EDA_Diode_NEG); - EDA_PIN_ADD_COMPONENT(R->pins[1], B ->id, SCF_EDA_Battery_NEG); - - out->pins[i] = R ->pins[0]; - } - - return 0; -} - -static int _eda_inst_inc_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_inc_post_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_dec_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_dec_post_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_assign_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - if (!c->srcs || c->srcs->size != 4) - return -EINVAL; - - scf_eda_context_t* eda = ctx->priv; - scf_function_t* f = eda->f; - - scf_3ac_operand_t* base = c->srcs->data[0]; - scf_3ac_operand_t* index = c->srcs->data[1]; - scf_3ac_operand_t* scale = c->srcs->data[2]; - scf_3ac_operand_t* src = c->srcs->data[3]; - - if (!base || !base->dag_node) - return -EINVAL; - - if (!index || !index->dag_node) - return -EINVAL; - - if (!scale || !scale->dag_node) - return -EINVAL; - - if (!src || !src->dag_node) - return -EINVAL; - - return -EINVAL; -} - -static int _eda_inst_and_assign_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - if (!c->srcs || c->srcs->size != 4) - return -EINVAL; - - scf_eda_context_t* eda = ctx->priv; - scf_function_t* f = eda->f; - - scf_3ac_operand_t* base = c->srcs->data[0]; - scf_3ac_operand_t* index = c->srcs->data[1]; - scf_3ac_operand_t* scale = c->srcs->data[2]; - scf_3ac_operand_t* src = c->srcs->data[3]; - - if (!base || !base->dag_node) - return -EINVAL; - - if (!index || !index->dag_node) - return -EINVAL; - - if (!scale || !scale->dag_node) - return -EINVAL; - - if (!src || !src->dag_node) - return -EINVAL; - - return -EINVAL; -} - -static int _eda_inst_or_assign_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - if (!c->srcs || c->srcs->size != 4) - return -EINVAL; - - scf_eda_context_t* eda = ctx->priv; - scf_function_t* f = eda->f; - - scf_3ac_operand_t* base = c->srcs->data[0]; - scf_3ac_operand_t* index = c->srcs->data[1]; - scf_3ac_operand_t* scale = c->srcs->data[2]; - scf_3ac_operand_t* src = c->srcs->data[3]; - - if (!base || !base->dag_node) - return -EINVAL; - - if (!index || !index->dag_node) - return -EINVAL; - - if (!scale || !scale->dag_node) - return -EINVAL; - - if (!src || !src->dag_node) - return -EINVAL; - - return -EINVAL; -} - -static int _eda_inst_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - if (!c->dsts || c->dsts->size != 1) - return -EINVAL; - - if (!c->srcs || c->srcs->size != 3) - return -EINVAL; - - scf_eda_context_t* eda = ctx->priv; - scf_function_t* f = eda->f; - - scf_3ac_operand_t* dst = c->dsts->data[0]; - scf_3ac_operand_t* base = c->srcs->data[0]; - scf_3ac_operand_t* index = c->srcs->data[1]; - scf_3ac_operand_t* scale = c->srcs->data[2]; - - if (!base || !base->dag_node) - return -EINVAL; - - if (!index || !index->dag_node) - return -EINVAL; - - if (!scale || !scale->dag_node) - return -EINVAL; - - if (!c->instructions) { - c->instructions = scf_vector_alloc(); - if (!c->instructions) - return -ENOMEM; - } - - scf_variable_t* vd = dst ->dag_node->var; - scf_variable_t* vb = base ->dag_node->var; - scf_variable_t* vi = index->dag_node->var; - scf_variable_t* vs = scale->dag_node->var; - - return -EINVAL; -} - -static int _eda_inst_teq_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_logic_not_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_cmp_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_setz_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_setnz_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_setgt_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_setge_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_setlt_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_setle_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_eq_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_ne_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_gt_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_ge_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_lt_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_le_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_cast_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - if (!c->dsts || c->dsts->size != 1) - return -EINVAL; - - if (!c->srcs || c->srcs->size != 1) - return -EINVAL; - - scf_eda_context_t* eda = ctx->priv; - scf_function_t* f = eda->f; - scf_3ac_operand_t* src = c->srcs->data[0]; - scf_3ac_operand_t* dst = c->dsts->data[0]; - - if (!src || !src->dag_node) - return -EINVAL; - - if (!dst || !dst->dag_node) - return -EINVAL; - - if (0 == dst->dag_node->color) - return -EINVAL; - - return -EINVAL; -} - -static int _eda_inst_return_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - if (!c->srcs || c->srcs->size < 1) - return -EINVAL; - - scf_eda_context_t* eda = ctx->priv; - scf_function_t* f = eda->f; - scf_3ac_operand_t* src = NULL; - scf_dag_node_t* out = NULL; - - int i; - int j; - - for (i = 0; i < c->srcs->size; i++) { - src = c->srcs->data[i]; - - out = src->dag_node; - - if (out->n_pins <= 0) { - scf_loge("\n"); - return -EINVAL; - } - - for (j = 0; j < out->n_pins; j++) - out->pins[j]->flags |= SCF_EDA_PIN_OUT; - } - - return 0; -} - -static int _eda_inst_nop_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return 0; -} - -static int _eda_inst_end_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return 0; -} - -static int _eda_inst_goto_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_jz_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_jnz_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_jgt_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_jge_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_jlt_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_jle_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return -EINVAL; -} - -static int _eda_inst_load_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return 0; -} - -static int _eda_inst_reload_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return 0; -} - -static int _eda_inst_save_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return 0; -} - -static int _eda_inst_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return 0; -} - -static int _eda_inst_and_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return 0; -} - -static int _eda_inst_or_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) -{ - return 0; -} - -static eda_inst_handler_t eda_inst_handlers[] = -{ - {SCF_OP_ARRAY_INDEX, _eda_inst_array_index_handler}, - - {SCF_OP_TYPE_CAST, _eda_inst_cast_handler}, - {SCF_OP_LOGIC_NOT, _eda_inst_logic_not_handler}, - {SCF_OP_BIT_NOT, _eda_inst_bit_not_handler}, - - {SCF_OP_INC, _eda_inst_inc_handler}, - {SCF_OP_DEC, _eda_inst_dec_handler}, - - {SCF_OP_INC_POST, _eda_inst_inc_post_handler}, - {SCF_OP_DEC_POST, _eda_inst_dec_post_handler}, - - {SCF_OP_BIT_AND, _eda_inst_bit_and_handler}, - {SCF_OP_BIT_OR, _eda_inst_bit_or_handler}, - - {SCF_OP_3AC_TEQ, _eda_inst_teq_handler}, - {SCF_OP_3AC_CMP, _eda_inst_cmp_handler}, - - {SCF_OP_3AC_SETZ, _eda_inst_setz_handler}, - {SCF_OP_3AC_SETNZ, _eda_inst_setnz_handler}, - {SCF_OP_3AC_SETGT, _eda_inst_setgt_handler}, - {SCF_OP_3AC_SETGE, _eda_inst_setge_handler}, - {SCF_OP_3AC_SETLT, _eda_inst_setlt_handler}, - {SCF_OP_3AC_SETLE, _eda_inst_setle_handler}, - - {SCF_OP_EQ, _eda_inst_eq_handler}, - {SCF_OP_NE, _eda_inst_ne_handler}, - {SCF_OP_GT, _eda_inst_gt_handler}, - {SCF_OP_GE, _eda_inst_ge_handler}, - {SCF_OP_LT, _eda_inst_lt_handler}, - {SCF_OP_LE, _eda_inst_le_handler}, - - {SCF_OP_ASSIGN, _eda_inst_assign_handler}, - - {SCF_OP_AND_ASSIGN, _eda_inst_and_assign_handler}, - {SCF_OP_OR_ASSIGN, _eda_inst_or_assign_handler}, - - {SCF_OP_RETURN, _eda_inst_return_handler}, - {SCF_OP_GOTO, _eda_inst_goto_handler}, - - {SCF_OP_3AC_JZ, _eda_inst_jz_handler}, - {SCF_OP_3AC_JNZ, _eda_inst_jnz_handler}, - {SCF_OP_3AC_JGT, _eda_inst_jgt_handler}, - {SCF_OP_3AC_JGE, _eda_inst_jge_handler}, - {SCF_OP_3AC_JLT, _eda_inst_jlt_handler}, - {SCF_OP_3AC_JLE, _eda_inst_jle_handler}, - - {SCF_OP_3AC_NOP, _eda_inst_nop_handler}, - {SCF_OP_3AC_END, _eda_inst_end_handler}, - - {SCF_OP_3AC_SAVE, _eda_inst_save_handler}, - {SCF_OP_3AC_LOAD, _eda_inst_load_handler}, - - {SCF_OP_3AC_RESAVE, _eda_inst_save_handler}, - {SCF_OP_3AC_RELOAD, _eda_inst_reload_handler}, - - {SCF_OP_3AC_ASSIGN_ARRAY_INDEX, _eda_inst_assign_array_index_handler}, - {SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX, _eda_inst_and_assign_array_index_handler}, - {SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX, _eda_inst_or_assign_array_index_handler}, -}; - -eda_inst_handler_t* scf_eda_find_inst_handler(const int op_type) -{ - int i; - for (i = 0; i < sizeof(eda_inst_handlers) / sizeof(eda_inst_handlers[0]); i++) { - - eda_inst_handler_t* h = &(eda_inst_handlers[i]); - - if (op_type == h->type) - return h; - } - return NULL; -} diff --git a/ses_layout.c b/ses_layout.c index a802c5f..a762a21 100644 --- a/ses_layout.c +++ b/ses_layout.c @@ -33,6 +33,7 @@ int ses_pins_same_line(ScfEfunction* f, scf_vector_t* lines) size_t j; size_t k; size_t m; + size_t n; for (i = 0; i < f->n_components; i++) { c = f->components[i]; @@ -48,13 +49,66 @@ int ses_pins_same_line(ScfEfunction* f, scf_vector_t* lines) for (m = 0; m < vec->size; m++) { p2 = vec->data[m]; - if (p2->i) + if (p2->cid == p->cid && p2->id == p->id) { + assert(p2 == p); + goto next; + } + } + m = 0; + n = 0; + while (m < vec->size && n < p->n_tos - 1) { + p2 = vec->data[m]; + + if (p2->cid < p->tos[n]) + m++; + else if (p2->cid > p->tos[n]) + n += 2; + else if (p2->id < p->tos[n + 1]) + m++; + else if (p2->id > p->tos[n + 1]) + n += 2; + + else { + if (scf_vector_add(vec, p) < 0) + return -ENOMEM; + + goto next; + } } } + + vec = scf_vector_alloc(); + if (!vec) + return -ENOMEM; + + if (scf_vector_add(lines, vec) < 0) { + scf_vector_free(vec); + return -ENOMEM; + } + + if (scf_vector_add(vec, p) < 0) + return -ENOMEM; +next: + p = NULL; } } +#if 1 + for (i = 0; i < lines->size; i++) { + vec = lines->data[i]; + + scf_logw("line i: %ld\n", i); + + for (j = 0; j < vec->size; j++) { + p = vec->data[j]; + + scf_logi("pin j: %ld, cid: %ld, pid: %ld\n", j, p->cid, p->id); + } + + printf("\n"); + } +#endif return 0; } @@ -71,16 +125,17 @@ int ses_layout_board(ScfEboard* b, int x, int y, int w, int h) size_t j; size_t k; - lines = scf_vector_alloc(); - if (!lines) - return -ENOMEM; for (i = 0; i < b->n_functions; i++) { f = b->functions[i]; printf("f: %s\n", f->name); + lines = scf_vector_alloc(); + if (!lines) + return -ENOMEM; + ses_pins_same_line(f, lines); } return 0; diff --git a/ses_layout.h b/ses_layout.h index 6dd16d7..e8cbad8 100644 --- a/ses_layout.h +++ b/ses_layout.h @@ -2,6 +2,7 @@ #define SES_LAYOUT_H #include"scf_eda_pb.h" +#include"scf_vector.h" int ses_layout_board(ScfEboard* b, int x, int y, int w, int h); -- 2.25.1