scf_variable_t* v = dn->var;
if (v && v->w)
- printf("exit active: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data);
+ printf("exit active: v_%d_%d/%s, dn: %#lx\n", v->w->line, v->w->pos, v->w->text->data, 0xffff & (uintptr_t)dn);
}
}
scf_variable_t* v = dn->var;
if (v && v->w)
- printf("exit alias: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data);
+ printf("exit alias: v_%d_%d/%s, dn: %#lx\n", v->w->line, v->w->pos, v->w->text->data, 0xffff & (uintptr_t)dn);
}
}
scf_variable_t* v = dn->var;
if (v && v->w)
- printf("saves: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data);
+ printf("saves: v_%d_%d/%s, dn: %#lx\n", v->w->line, v->w->pos, v->w->text->data, 0xffff & (uintptr_t)dn);
}
}
scf_variable_t* v = dn->var;
if (v && v->w)
- printf("resaves: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data);
+ printf("resaves: v_%d_%d/%s, dn: %#lx\n", v->w->line, v->w->pos, v->w->text->data, 0xffff & (uintptr_t)dn);
}
}
return 0;
if (SCF_OP_ADDRESS_OF == node->type) {
- scf_logd("type: %d, %d, node: %p, %p\n", dag_node->type, node->type, dag_node, node);
- scf_logd("var: %p, %p\n", dag_node->var, node->var);
-// scf_logi("var: %#lx, %#lx\n", 0xffff & (uintptr_t)dag_node->var, 0xffff & (uintptr_t)node->var);
+ scf_logd("type: %d, %d, node: %#lx, %#lx, ", dag_node->type, node->type, 0xffff & (uintptr_t)dag_node, 0xffff & (uintptr_t)node);
+// scf_loge("var: %p, %p\n", dag_node->var, node->var);
+// printf("var: %#lx, %#lx\n", 0xffff & (uintptr_t)dag_node->var, 0xffff & (uintptr_t)node->var);
}
if (scf_type_is_var(node->type)) {
|| SCF_OP_INC == node->type
|| SCF_OP_DEC == node->type
|| SCF_OP_INC_POST == node->type
- || SCF_OP_DEC_POST == node->type) {
+ || SCF_OP_DEC_POST == node->type
+ || SCF_OP_ADDRESS_OF == node->type) {
if (dag_node->var == _scf_operand_get((scf_node_t*)node))
return 1;
return 0;
return -ENOMEM;
scf_list_add_tail(h, &dn->list);
+
+ dn->old = *pp;
} else {
dn->var->local_flag |= v->local_flag;
dn->var->tmp_flag |= v->tmp_flag;
if (0 == scf_dag_dn_same(child0, child1))
return 0;
}
+
return 1;
}
int type; // node type
scf_variable_t* var;
+ scf_dag_node_t* old;
scf_node_t* node;
scf_vector_t* parents;
#include"scf_optimizer.h"
-static scf_dag_node_t* _func_dag_find_dn(scf_vector_t* dag, scf_dag_node_t* dn_bb, scf_list_t* f_dag)
-{
- scf_dag_node_t* dn_func = NULL;
- scf_list_t* l;
-
- int i;
- for (i = 0; i < dag->size; i++) {
- dn_func = dag->data[i];
-
- scf_variable_t* v1 = dn_func->var;
-
- if (dn_func->type == dn_bb->type) {
-
- if (dn_func->var == dn_bb->var)
- break;
-
- if (scf_dag_dn_same(dn_func, dn_bb))
- break;
-
- if (dn_bb->node) {
- if (scf_dag_node_like(dn_func, dn_bb->node, f_dag))
- break;
- }
- }
- dn_func = NULL;
- }
-
- return dn_func;
-}
-
-static int _bb_dag_update(scf_basic_block_t* bb, scf_vector_t* dag, scf_list_t* f_dag)
+static int _bb_dag_update(scf_basic_block_t* bb)
{
scf_dag_node_t* dn;
scf_dag_node_t* dn_bb;
if (SCF_OP_ADDRESS_OF == dn->type || SCF_OP_DEREFERENCE == dn->type) {
- dn_func = _func_dag_find_dn(dag, dn, f_dag);
+ dn_func = dn->old;
} else {
assert(dn_bb->parents && dn_bb->parents->size > 0);
if (dn != dn_bb->parents->data[dn_bb->parents->size - 1])
continue;
- dn_func = _func_dag_find_dn(dag, dn_bb, f_dag);
+ dn_func = dn_bb->old;
}
if (!dn_func) {
assert(dn->childs);
assert(2 == dn->childs->size);
- dn_func = _func_dag_find_dn(dag, dn, f_dag);
+ dn_func = dn->old;
+
if (!dn_func) {
scf_loge("\n");
return -1;
scf_3ac_code_t* c;
scf_3ac_code_t* c2;
scf_vector_t* roots;
- scf_vector_t* dag;
scf_list_t* l;
scf_list_t* l2;
scf_list_t h;
scf_list_init(&h);
- dag = scf_vector_alloc();
- if (!dag)
- return -ENOMEM;
-
- for (l = scf_list_head(&bb->code_list_head); l != scf_list_sentinel(&bb->code_list_head);
- l = scf_list_next(l)) {
- c = scf_list_data(l, scf_3ac_code_t, list);
-
- if (c->dsts) {
- assert(1 == c->dsts->size);
-
- dst = c->dsts->data[0];
-
- assert(0 == scf_vector_add_unique(dag, dst->dag_node));
- }
-
- if (c->srcs) {
- for (i = 0; i < c->srcs->size; i++) {
- src = c->srcs->data[i];
-
- assert(0 == scf_vector_add_unique(dag, src->dag_node));
- }
- }
- }
-
ret = scf_basic_block_dag2(bb, &bb->dag_list_head);
if (ret < 0)
return ret;
- ret = _bb_dag_update(bb, dag, &f->dag_list_head);
+ ret = _bb_dag_update(bb);
if (ret < 0) {
scf_loge("\n");
return ret;
scf_logd("bb: %p, roots->size: %d\n", bb, roots->size);
for (i = 0; i < roots->size; i++) {
- dn = roots->data[i];
+ dn = roots->data[i];
if (!dn)
continue;
if (c->dsts) {
dst = c->dsts->data[0];
-
- dn = _func_dag_find_dn(dag, dst->dag_node, &f->dag_list_head);
- if (!dn) {
- scf_loge("\n");
- return -1;
- }
+ dn = dst->dag_node->old;
dst->dag_node = dn;
}
for (i = 0; i < c->srcs->size; i++) {
src = c->srcs->data[i];
- dn = _func_dag_find_dn(dag, src->dag_node, &f->dag_list_head);
- if (!dn) {
-
- scf_variable_t* v = src->dag_node->var;
- if (v->w)
- scf_loge("v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data);
- else
- scf_loge("v_%#lx\n", 0xffff & (uintptr_t)v);
- scf_3ac_code_print(c, NULL);
- return -1;
- }
+ dn = src->dag_node->old;
src->dag_node = dn;
}
scf_dag_node_free_list(&bb->dag_list_head);
scf_vector_free(roots);
- scf_vector_free(dag);
return 0;
}
int i;
// scf_basic_block_print_list(bb_list_head);
-
+#if 1
for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head);
l = scf_list_next(l)) {
return ret;
}
}
-
+#endif
+// scf_basic_block_print_list(bb_list_head);
return 0;
}
(ProtobufCMessageInit) scf_line__init,
NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor scf_epin__field_descriptors[16] =
+static const ProtobufCFieldDescriptor scf_epin__field_descriptors[18] =
{
{
"id",
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
- "x",
+ "tr",
13,
PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_DOUBLE,
+ 0, /* quantifier_offset */
+ offsetof(ScfEpin, tr),
+ NULL,
+ NULL,
+ 0, /* flags */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "jtr",
+ 14,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_DOUBLE,
+ 0, /* quantifier_offset */
+ offsetof(ScfEpin, jtr),
+ NULL,
+ NULL,
+ 0, /* flags */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "x",
+ 15,
+ PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_INT32,
0, /* quantifier_offset */
offsetof(ScfEpin, x),
},
{
"y",
- 14,
+ 16,
PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_INT32,
0, /* quantifier_offset */
},
{
"vflag",
- 15,
+ 17,
PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_BOOL,
0, /* quantifier_offset */
},
{
"pflag",
- 16,
+ 18,
PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_BOOL,
0, /* quantifier_offset */
3, /* field[3] = flags */
0, /* field[0] = id */
9, /* field[9] = jR */
+ 13, /* field[13] = jtr */
2, /* field[2] = lid */
- 15, /* field[15] = pflag */
+ 17, /* field[17] = pflag */
4, /* field[4] = tos */
+ 12, /* field[12] = tr */
10, /* field[10] = uF */
11, /* field[11] = uH */
- 14, /* field[14] = vflag */
- 12, /* field[12] = x */
- 13, /* field[13] = y */
+ 16, /* field[16] = vflag */
+ 14, /* field[14] = x */
+ 15, /* field[15] = y */
};
static const ProtobufCIntRange scf_epin__number_ranges[1 + 1] =
{
{ 1, 0 },
- { 0, 16 }
+ { 0, 18 }
};
const ProtobufCMessageDescriptor scf_epin__descriptor =
{
"ScfEpin",
"",
sizeof(ScfEpin),
- 16,
+ 18,
scf_epin__field_descriptors,
scf_epin__field_indices_by_name,
1, scf_epin__number_ranges,
double jr;
double uf;
double uh;
+ double tr;
+ double jtr;
int32_t x;
int32_t y;
protobuf_c_boolean vflag;
};
#define SCF_EPIN__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&scf_epin__descriptor) \
- , 0, 0, 0, 0, 0,NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+ , 0, 0, 0, 0, 0,NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
struct _ScfEconn
required double uF = 11;
required double uH = 12;
- required int32 x = 13;
- required int32 y = 14;
- required bool vflag = 15;
- required bool pflag = 16;
+ required double tr = 13;
+ required double jtr = 14;
+
+ required int32 x = 15;
+ required int32 y = 16;
+ required bool vflag = 17;
+ required bool pflag = 18;
}
message scf_econn
SCF_EDA_Transistor_NB,
};
+static scf_edata_t component_datas[] =
+{
+ {SCF_EDA_None, 0, 0, 0, 0, 0, 0, 0, 0},
+ {SCF_EDA_Battery, 0, SCF_EDA_Battery_POS, 0, 0, 0, 0, 0, 0},
+
+ {SCF_EDA_Resistor, 0, 0, 0, 0, 10 * 1000, 0, 0, 0},
+ {SCF_EDA_Capacitor, 0, 0, 0, 0, 0, 0, 0.1, 0},
+ {SCF_EDA_Inductor, 0, 0, 0, 0, 0, 0, 0, 1000},
+
+ {SCF_EDA_Diode, 0, SCF_EDA_Diode_NEG, 0, 0, 750, 0, 0, 0},
+ {SCF_EDA_Transistor, 0, SCF_EDA_Transistor_B, 0, 0, 750, 0, 0, 0},
+ {SCF_EDA_Transistor, 0, SCF_EDA_Transistor_C, 0, 0, 750, 0, 0, 0},
+};
+
+static scf_edata_t* _eda_find_data(const uint64_t type, const uint64_t model, const uint64_t pid)
+{
+ scf_edata_t* ed;
+
+ int i;
+ for (i = 0; i < sizeof(component_datas) / sizeof(component_datas[0]); i++) {
+ ed = &component_datas[i];
+
+ if (ed->type == type && ed->model == model && ed->pid == pid)
+ return ed;
+ }
+
+ return NULL;
+}
+
ScfEconn* scf_econn__alloc()
{
ScfEconn* ec = malloc(sizeof(ScfEconn));
ScfEcomponent* scf_ecomponent__alloc(uint64_t type)
{
+ ScfEcomponent* c;
+ scf_edata_t* ed;
+
if (type >= SCF_EDA_Components_NB)
return NULL;
- ScfEcomponent* c = malloc(sizeof(ScfEcomponent));
+ c = malloc(sizeof(ScfEcomponent));
if (!c)
return NULL;
scf_epin__free(pin);
return NULL;
}
+
+ ed = _eda_find_data(c->type, c->model, pin->id);
+ if (ed) {
+ pin->v = ed->v;
+ pin->a = ed->a;
+ pin->r = ed->r;
+ pin->jr = ed->jr;
+ pin->uf = ed->uf;
+ pin->uh = ed->uh;
+ }
}
return c;
SCF_EDA_Transistor_NB,
};
+typedef struct {
+ uint64_t type;
+ uint64_t model;
+ uint64_t pid;
+
+ double v;
+ double a;
+ double r;
+ double jr;
+ double uf;
+ double uh;
+} scf_edata_t;
+
+
ScfEconn* scf_econn__alloc();
int scf_econn__add_cid(ScfEconn* ec, uint64_t cid);
int scf_econn__del_cid(ScfEconn* ec, uint64_t cid);