use scf/pack instead of protobuf in native/eda
authoryu.dongliang <18588496441@163.com>
Sat, 9 Mar 2024 14:09:20 +0000 (22:09 +0800)
committeryu.dongliang <18588496441@163.com>
Sat, 9 Mar 2024 14:09:20 +0000 (22:09 +0800)
core/scf_core_types.h
native/eda/scf_eda.h
native/eda/scf_eda_pack.c [new file with mode: 0644]
native/eda/scf_eda_pack.h [new file with mode: 0644]
pack/main.c
pack/scf_pack.c
pack/scf_pack.h
parse/Makefile
parse/scf_parse.c
util/scf_def.h

index 971f3186d14d5a647d83aa1a913863a272f8bfc4..100bbc6ad1f3e67a9c5261499844ce703c12fe1f 100644 (file)
@@ -23,10 +23,10 @@ typedef struct scf_regs_ops_s   scf_regs_ops_t;
 typedef struct scf_register_s   scf_register_t;
 typedef struct scf_OpCode_s     scf_OpCode_t;
 
-typedef struct _ScfEpin         ScfEpin;
-typedef struct _ScfEcomponent   ScfEcomponent;
-typedef struct _ScfEfunction    ScfEfunction;
-typedef struct _ScfEboard       ScfEboard;
+typedef struct scf_epin_s        ScfEpin;
+typedef struct scf_ecomponent_s  ScfEcomponent;
+typedef struct scf_efunction_s   ScfEfunction;
+typedef struct scf_eboard_s      ScfEboard;
 
 enum scf_core_types {
        SCF_OP_ADD      = 0,    // +
index dabdca3a1406b6f6efb76a4300bf9f5a580e4daa..6b147c3cbc74dceb9615b43ec43147b633dccd30 100644 (file)
@@ -2,7 +2,7 @@
 #define SCF_EDA_H
 
 #include"scf_native.h"
-#include"scf_eda_pb.h"
+#include"scf_eda_pack.h"
 
 typedef struct {
 
diff --git a/native/eda/scf_eda_pack.c b/native/eda/scf_eda_pack.c
new file mode 100644 (file)
index 0000000..12c1e89
--- /dev/null
@@ -0,0 +1,589 @@
+#include "scf_eda_pack.h"
+//#include "scf_def.h"
+
+static int component_pins[SCF_EDA_Components_NB] =
+{
+       0, // None
+       SCF_EDA_Battery_NB, // SCF_EDA_Battery
+
+       2, // SCF_EDA_Resistor
+       2, // SCF_EDA_Capacitor
+       2, // SCF_EDA_Inductor
+
+       SCF_EDA_Diode_NB,
+       SCF_EDA_NPN_NB,
+       SCF_EDA_PNP_NB,
+};
+
+static scf_edata_t  component_datas[] =
+{
+       {SCF_EDA_None,       0,                   0,  0, 0,         0, 0,    0,    0, 0},
+       {SCF_EDA_Battery,    0, SCF_EDA_Battery_POS,  0, 0,         0, 0,    0,    0, 0},
+
+       {SCF_EDA_Resistor,   0,                   0,  0, 0, 10 * 1000, 0,    0,    0, 0},
+       {SCF_EDA_Capacitor,  0,                   0,  0, 0,      1e12, 0,  0.1,    0, 0},
+       {SCF_EDA_Inductor,   0,                   0,  0, 0,         0, 0,    0, 1000, 0},
+};
+
+static scf_edata_t  pin_datas[] =
+{
+       {SCF_EDA_None,  0,                 0, 0, 0,   0, 0, 0, 0, 0},
+
+       {SCF_EDA_Diode, 0, SCF_EDA_Diode_NEG, 0, 0, 750, 0, 0, 0, 0},
+
+       {SCF_EDA_NPN,   0, SCF_EDA_NPN_B,     0, 0, 750, 0, 0, 0, 0},
+       {SCF_EDA_NPN,   0, SCF_EDA_NPN_C,     0, 0,  10, 0, 0, 0, 150},
+
+       {SCF_EDA_PNP,   0, SCF_EDA_PNP_B,     0, 0, 750, 0, 0, 0, 0},
+       {SCF_EDA_PNP,   0, SCF_EDA_PNP_C,     0, 0,  10, 0, 0, 0, 150},
+};
+
+static scf_edata_t* _pin_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(pin_datas) / sizeof(pin_datas[0]); i++) {
+               ed =              &pin_datas[i];
+
+               if (ed->type == type && ed->model == model && ed->pid == pid)
+                       return ed;
+       }
+
+       return NULL;
+}
+
+static scf_edata_t* _component_find_data(const uint64_t type, const uint64_t model)
+{
+       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)
+                       return ed;
+       }
+
+       return NULL;
+}
+
+ScfEconn* scf_econn__alloc()
+{
+       ScfEconn* ec = calloc(1, sizeof(ScfEconn));
+
+       return ec;
+}
+
+int scf_econn__add_cid(ScfEconn* ec, uint64_t cid)
+{
+       if (!ec)
+               return -EINVAL;
+
+       for (size_t i = 0; i < ec->n_cids; i++) {
+
+               if (ec->cids[i] == cid)
+                       return 0;
+       }
+
+       uint64_t* p = realloc(ec->cids, sizeof(uint64_t) * (ec->n_cids + 1));
+       if (!p)
+               return -ENOMEM;
+
+       ec->cids = p;
+       ec->cids[ec->n_cids++] = cid;
+       return 0;
+}
+
+int scf_econn__del_cid(ScfEconn* ec, uint64_t cid)
+{
+       if (!ec)
+               return -EINVAL;
+
+       uint64_t* p;
+       size_t    i;
+       size_t    j;
+
+       for (i = 0; i < ec->n_cids; i++) {
+
+               if (ec->cids[i] == cid) {
+
+                       for (j = i + 1;  j  < ec->n_cids; j++)
+                               ec->cids[j - 1] = ec->cids[j];
+
+                       ec->n_cids--;
+
+                       p = realloc(ec->cids, sizeof(uint64_t) * ec->n_cids);
+                       if (p)
+                               ec->cids = p;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
+}
+
+ScfEline* scf_eline__alloc()
+{
+       ScfEline* l = calloc(1, sizeof(ScfEline));
+
+       return l;
+}
+
+int scf_eline__add_line(ScfEline* el, ScfLine*  l)
+{
+       if (!el || !l)
+               return -EINVAL;
+
+       for (size_t i = 0; i < el->n_lines; i++) {
+
+               if (el->lines[i] == l)
+                       return 0;
+
+               if (el->lines[i]->x0 == l->x0
+                && el->lines[i]->y0 == l->y0
+                && el->lines[i]->x1 == l->x1
+                && el->lines[i]->y1 == l->y1)
+                       return 0;
+       }
+
+       void* p = realloc(el->lines, sizeof(ScfLine*) * (el->n_lines + 1));
+       if (!p)
+               return -ENOMEM;
+
+       el->lines = p;
+       el->lines[el->n_lines++] = l;
+       return 0;
+}
+
+int scf_eline__del_line(ScfEline* el, ScfLine*  l)
+{
+       if (!el || !l)
+               return -EINVAL;
+
+       void*   p;
+       size_t  i;
+       size_t  j;
+
+       for (i = 0; i < el->n_lines; i++) {
+
+               if (el->lines[i]->x0 == l->x0
+                && el->lines[i]->y0 == l->y0
+                && el->lines[i]->x1 == l->x1
+                && el->lines[i]->y1 == l->y1) {
+
+                       for (j = i + 1;  j  < el->n_lines; j++)
+                               el->lines[j - 1] = el->lines[j];
+
+                       el->n_lines--;
+
+                       p = realloc(el->lines, sizeof(ScfLine*) * el->n_lines);
+                       if (p)
+                               el->lines = p;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
+}
+
+int scf_eline__add_pin(ScfEline* el, uint64_t  cid, uint64_t pid)
+{
+       if (!el)
+               return -EINVAL;
+
+       for (size_t i = 0; i + 1 < el->n_pins; i += 2) {
+
+               if (el->pins[i] == cid && el->pins[i + 1] == pid)
+                       return 0;
+       }
+
+       uint64_t* p = realloc(el->pins, sizeof(uint64_t) * (el->n_pins + 2));
+       if (!p)
+               return -ENOMEM;
+
+       el->pins = p;
+       el->pins[el->n_pins++] = cid;
+       el->pins[el->n_pins++] = pid;
+       return 0;
+}
+
+int scf_eline__del_pin(ScfEline* el, uint64_t  cid, uint64_t pid)
+{
+       if (!el)
+               return -EINVAL;
+
+       uint64_t* p;
+       size_t    i;
+       size_t    j;
+
+       for (i = 0; i + 1 < el->n_pins; i += 2) {
+
+               if (el->pins[i] == cid && el->pins[i + 1] == pid) {
+
+                       for (j = i + 2;  j  < el->n_pins; j++)
+                               el->pins[j - 2] = el->pins[j];
+
+                       el->n_pins -= 2;
+
+                       p = realloc(el->pins, sizeof(uint64_t) * el->n_pins);
+                       if (p)
+                               el->pins = p;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
+}
+
+int scf_eline__add_conn(ScfEline* el, ScfEconn* ec)
+{
+       if (!el || !ec)
+               return -EINVAL;
+
+       for (size_t i = 0; i < el->n_conns; i++) {
+
+               if (el->conns[i] == ec)
+                       return 0;
+       }
+
+       void* p = realloc(el->conns, sizeof(ScfEconn*) * (el->n_conns + 1));
+       if (!p)
+               return -ENOMEM;
+
+       el->conns = p;
+       el->conns[el->n_conns++] = ec;
+       return 0;
+}
+
+int scf_eline__del_conn(ScfEline* el, ScfEconn* ec)
+{
+       if (!el || !ec)
+               return -EINVAL;
+
+       void*   p;
+       size_t  i;
+       size_t  j;
+
+       for (i = 0; i < el->n_conns; i++) {
+
+               if (el->conns[i] == ec) {
+
+                       for (j = i + 1;  j  < el->n_conns; j++)
+                               el->conns[j - 1] = el->conns[j];
+
+                       el->n_conns--;
+
+                       p = realloc(el->conns, sizeof(ScfEconn*) * el->n_conns);
+                       if (p)
+                               el->conns = p;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
+}
+
+ScfEpin* scf_epin__alloc()
+{
+       ScfEpin* pin = calloc(1, sizeof(ScfEpin));
+
+       return pin;
+}
+
+int scf_epin__add_component(ScfEpin* pin, uint64_t cid, uint64_t pid)
+{
+       if (!pin)
+               return -EINVAL;
+
+       for (size_t i = 0; i + 1 < pin->n_tos; i += 2) {
+
+               if (pin->tos[i] == cid && pin->tos[i + 1] == pid)
+                       return 0;
+       }
+
+       uint64_t* p = realloc(pin->tos, sizeof(uint64_t) * (pin->n_tos + 2));
+       if (!p)
+               return -ENOMEM;
+
+       pin->tos = p;
+       pin->tos[pin->n_tos++] = cid;
+       pin->tos[pin->n_tos++] = pid;
+       return 0;
+}
+
+int scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid)
+{
+       if (!pin)
+               return -EINVAL;
+
+       uint64_t* p;
+       size_t    i;
+       size_t    j;
+
+       for (i = 0; i + 1 < pin->n_tos; i += 2) {
+
+               if (pin->tos[i] == cid && pin->tos[i + 1] == pid) {
+
+                       for (j = i + 2;  j  < pin->n_tos; j++)
+                               pin->tos[j - 2] = pin->tos[j];
+
+                       pin->n_tos -= 2;
+
+                       p = realloc(pin->tos, sizeof(uint64_t) * pin->n_tos);
+                       if (p)
+                               pin->tos = p;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
+}
+
+ScfEcomponent* scf_ecomponent__alloc(uint64_t type)
+{
+       ScfEcomponent* c;
+       scf_edata_t*      ed;
+
+       if (type >= SCF_EDA_Components_NB)
+               return NULL;
+
+       c = calloc(1, sizeof(ScfEcomponent));
+       if (!c)
+               return NULL;
+
+       c->type = type;
+
+       ed = _component_find_data(c->type, c->model);
+       if (ed) {
+               c->v  = ed->v;
+               c->a  = ed->a;
+               c->r  = ed->r;
+               c->jr = ed->jr;
+               c->uf = ed->uf;
+               c->uh = ed->uh;
+       }
+
+       int i;
+       for (i = 0; i < component_pins[type]; i++) {
+
+               ScfEpin* pin = scf_epin__alloc();
+               if (!pin) {
+                       ScfEcomponent_free(c);
+                       return NULL;
+               }
+
+               pin->id = i;
+
+               if (scf_ecomponent__add_pin(c, pin) < 0) {
+                       ScfEcomponent_free(c);
+                       ScfEpin_free(pin);
+                       return NULL;
+               }
+
+               ed = _pin_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;
+                       pin->hfe = ed->hfe;
+               }
+       }
+
+       return c;
+}
+
+int scf_ecomponent__add_pin(ScfEcomponent* c, ScfEpin* pin)
+{
+       if (!c || !pin)
+               return -EINVAL;
+
+       void* p = realloc(c->pins, sizeof(ScfEpin*) * (c->n_pins + 1));
+       if (!p)
+               return -ENOMEM;
+
+       c->pins = p;
+       c->pins[c->n_pins++] = pin;
+       return 0;
+}
+
+int scf_ecomponent__del_pin(ScfEcomponent* c, ScfEpin* pin)
+{
+       if (!c)
+               return -EINVAL;
+
+       size_t   i;
+       size_t   j;
+       void*    p;
+
+       for (i = 0; i < c->n_pins; i++) {
+
+               if (c->pins[i] == pin) {
+
+                       for (j = i + 1; j  < c->n_pins; j++)
+                               c->pins[j - 1] = c->pins[j];
+
+                       c->n_pins--;
+
+                       p = realloc(c->pins, sizeof(ScfEpin*) * c->n_pins);
+                       if (p)
+                               c->pins = p;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
+}
+
+ScfEfunction*  scf_efunction__alloc(const char* name)
+{
+       ScfEfunction* f = calloc(1, sizeof(ScfEfunction));
+       if (!f)
+               return NULL;
+
+       f->n_name = strlen(name) + 1;
+
+       f->name = strdup(name);
+       if (!f->name) {
+               free(f);
+               return NULL;
+       }
+
+       return f;
+}
+
+int scf_efunction__add_component(ScfEfunction* f, ScfEcomponent* c)
+{
+       if (!f || !c)
+               return -EINVAL;
+
+       void* p = realloc(f->components, sizeof(ScfEcomponent*) * (f->n_components + 1));
+       if (!p)
+               return -ENOMEM;
+
+       f->components = p;
+       f->components[f->n_components++] = c;
+       return 0;
+}
+
+int scf_efunction__del_component(ScfEfunction* f, ScfEcomponent* c)
+{
+       if (!f || !c)
+               return -EINVAL;
+
+       size_t   i;
+       size_t   j;
+       void*    p;
+
+       for (i = 0; i < f->n_components; i++) {
+
+               if (f->components[i] == c) {
+
+                       for (j = i + 1;  j < f->n_components; j++)
+                               f->components[j - 1] = f->components[j];
+
+                       f->n_components--;
+
+                       p = realloc(f->components, sizeof(ScfEcomponent*) * f->n_components);
+                       if (p)
+                               f->components = p;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
+}
+
+int scf_efunction__add_eline(ScfEfunction* f, ScfEline* el)
+{
+       if (!f || !el)
+               return -EINVAL;
+
+       void* p = realloc(f->elines, sizeof(ScfEline*) * (f->n_elines + 1));
+       if (!p)
+               return -ENOMEM;
+
+       f->elines = p;
+       f->elines[f->n_elines++] = el;
+       return 0;
+}
+
+int scf_efunction__del_eline(ScfEfunction* f, ScfEline* el)
+{
+       if (!f || !el)
+               return -EINVAL;
+
+       size_t   i;
+       size_t   j;
+       void*    p;
+
+       for (i = 0; i < f->n_elines; i++) {
+
+               if (f->elines[i] == el) {
+
+                       for (j = i + 1;  j < f->n_elines; j++)
+                               f->elines[j - 1] = f->elines[j];
+
+                       f->n_elines--;
+
+                       p = realloc(f->elines, sizeof(ScfEline*) * f->n_elines);
+                       if (p)
+                               f->elines = p;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
+}
+
+ScfEboard* scf_eboard__alloc()
+{
+       ScfEboard* b = calloc(1, sizeof(ScfEboard));
+
+       return b;
+}
+
+int scf_eboard__add_function(ScfEboard* b, ScfEfunction* f)
+{
+       if (!b || !f)
+               return -EINVAL;
+
+       void* p = realloc(b->functions, sizeof(ScfEfunction*) * (b->n_functions + 1));
+       if (!p)
+               return -ENOMEM;
+
+       b->functions = p;
+       b->functions[b->n_functions++] = f;
+       return 0;
+}
+
+int scf_eboard__del_function(ScfEboard* b, ScfEfunction* f)
+{
+       if (!b)
+               return -EINVAL;
+
+       size_t   i;
+       size_t   j;
+       void*    p;
+
+       for (i = 0; i < b->n_functions; i++) {
+
+               if (b->functions[i] == f) {
+
+                       for (j = i + 1;  j < b->n_functions; j++)
+                               b->functions[j - 1] = b->functions[j];
+
+                       b->n_functions--;
+
+                       p = realloc(b->functions, sizeof(ScfEfunction*) * b->n_functions);
+                       if (p)
+                               b->functions = p;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
+}
diff --git a/native/eda/scf_eda_pack.h b/native/eda/scf_eda_pack.h
new file mode 100644 (file)
index 0000000..8b3dbd3
--- /dev/null
@@ -0,0 +1,393 @@
+#ifndef SCF_EDA_PACK_H
+#define SCF_EDA_PACK_H
+
+#include "scf_pack.h"
+
+enum {
+       SCF_EDA_None,
+       SCF_EDA_Battery,
+
+       SCF_EDA_Resistor,
+       SCF_EDA_Capacitor,
+       SCF_EDA_Inductor,
+
+       SCF_EDA_Diode,
+       SCF_EDA_NPN,
+       SCF_EDA_PNP,
+
+       SCF_EDA_Components_NB,
+};
+
+#define SCF_EDA_PIN_NONE   0
+#define SCF_EDA_PIN_IN     1
+#define SCF_EDA_PIN_OUT    2
+#define SCF_EDA_PIN_POS    4
+#define SCF_EDA_PIN_NEG    8
+#define SCF_EDA_PIN_CF     16
+#define SCF_EDA_PIN_BORDER 32
+
+#define SCF_EDA_V_INIT   -10001001.0
+#define SCF_EDA_V_MIN    -10000000.0
+#define SCF_EDA_V_MAX     10000000.0
+
+#define SCF_EDA_V_Diode_ON  0.58
+#define SCF_EDA_V_Diode_OFF 0.55
+
+#define SCF_EDA_V_NPN_ON    0.70
+#define SCF_EDA_V_NPN_OFF   0.61
+
+enum {
+       SCF_EDA_Battery_NEG,
+       SCF_EDA_Battery_POS,
+       SCF_EDA_Battery_NB,
+};
+
+enum {
+       SCF_EDA_Diode_NEG,
+       SCF_EDA_Diode_POS,
+       SCF_EDA_Diode_NB,
+};
+
+enum {
+       SCF_EDA_Status_ON,
+       SCF_EDA_Status_OFF,
+       SCF_EDA_Path_OFF,
+       SCF_EDA_Path_TO,
+};
+
+enum {
+       SCF_EDA_NPN_B,
+       SCF_EDA_NPN_E,
+       SCF_EDA_NPN_C,
+       SCF_EDA_NPN_NB,
+};
+
+enum {
+       SCF_EDA_PNP_B,
+       SCF_EDA_PNP_E,
+       SCF_EDA_PNP_C,
+       SCF_EDA_PNP_NB,
+};
+
+typedef struct {
+       uint64_t  type;
+       uint64_t  model;
+       uint64_t  pid;
+
+       double    v;
+       double    a;
+       double    r;
+       double    jr;
+       double    uf;
+       double    uh;
+       double    hfe;
+} scf_edata_t;
+
+typedef struct {
+       SCF_PACK_DEF_VAR(int, x0);
+       SCF_PACK_DEF_VAR(int, y0);
+       SCF_PACK_DEF_VAR(int, x1);
+       SCF_PACK_DEF_VAR(int, y1);
+} ScfLine;
+
+SCF_PACK_TYPE(ScfLine)
+SCF_PACK_INFO_VAR(ScfLine, x0),
+SCF_PACK_INFO_VAR(ScfLine, y0),
+SCF_PACK_INFO_VAR(ScfLine, x1),
+SCF_PACK_INFO_VAR(ScfLine, y1),
+SCF_PACK_END(ScfLine)
+
+typedef struct scf_epin_s        ScfEpin;
+typedef struct scf_ecomponent_s  ScfEcomponent;
+typedef struct scf_efunction_s   ScfEfunction;
+typedef struct scf_eboard_s      ScfEboard;
+
+struct scf_epin_s
+{
+       SCF_PACK_DEF_VAR(uint64_t, id);
+       SCF_PACK_DEF_VAR(uint64_t, cid);
+       SCF_PACK_DEF_VAR(uint64_t, lid);
+       SCF_PACK_DEF_VAR(uint64_t, flags);
+       SCF_PACK_DEF_VARS(uint64_t, tos);
+       SCF_PACK_DEF_VAR(uint64_t, c_lid);
+
+       SCF_PACK_DEF_VAR(double, v);
+       SCF_PACK_DEF_VAR(double, jv);
+       SCF_PACK_DEF_VAR(double, a);
+       SCF_PACK_DEF_VAR(double, ja);
+
+       SCF_PACK_DEF_VAR(double, r);
+       SCF_PACK_DEF_VAR(double, jr);
+       SCF_PACK_DEF_VAR(double, uf);
+       SCF_PACK_DEF_VAR(double, uh);
+       SCF_PACK_DEF_VAR(double, hfe);
+
+       SCF_PACK_DEF_VAR(double, dr);
+       SCF_PACK_DEF_VAR(double, jdr);
+
+       SCF_PACK_DEF_VAR(double, sr);
+       SCF_PACK_DEF_VAR(double, jsr);
+
+       SCF_PACK_DEF_VAR(double, pr);
+       SCF_PACK_DEF_VAR(double, jpr);
+
+       SCF_PACK_DEF_VAR(uint64_t, path);
+
+       SCF_PACK_DEF_VAR(int, x);
+       SCF_PACK_DEF_VAR(int, y);
+
+       SCF_PACK_DEF_VAR(int, n_diodes);
+       SCF_PACK_DEF_VAR(int, l_pos);
+
+       SCF_PACK_DEF_VAR(uint8_t, vflag);
+       SCF_PACK_DEF_VAR(uint8_t, pflag);
+       SCF_PACK_DEF_VAR(uint8_t, vconst);
+       SCF_PACK_DEF_VAR(uint8_t, aconst);
+};
+
+SCF_PACK_TYPE(ScfEpin)
+SCF_PACK_INFO_VAR(ScfEpin, id),
+SCF_PACK_INFO_VAR(ScfEpin, cid),
+SCF_PACK_INFO_VAR(ScfEpin, lid),
+SCF_PACK_INFO_VAR(ScfEpin, flags),
+SCF_PACK_INFO_VARS(ScfEpin, tos, uint64_t),
+SCF_PACK_INFO_VAR(ScfEpin, c_lid),
+
+SCF_PACK_INFO_VAR(ScfEpin, v),
+SCF_PACK_INFO_VAR(ScfEpin, jv),
+SCF_PACK_INFO_VAR(ScfEpin, a),
+SCF_PACK_INFO_VAR(ScfEpin, ja),
+
+SCF_PACK_INFO_VAR(ScfEpin, r),
+SCF_PACK_INFO_VAR(ScfEpin, jr),
+SCF_PACK_INFO_VAR(ScfEpin, uf),
+SCF_PACK_INFO_VAR(ScfEpin, uh),
+SCF_PACK_INFO_VAR(ScfEpin, hfe),
+
+SCF_PACK_INFO_VAR(ScfEpin, dr),
+SCF_PACK_INFO_VAR(ScfEpin, jdr),
+
+SCF_PACK_INFO_VAR(ScfEpin, sr),
+SCF_PACK_INFO_VAR(ScfEpin, jsr),
+
+SCF_PACK_INFO_VAR(ScfEpin, pr),
+SCF_PACK_INFO_VAR(ScfEpin, jpr),
+
+SCF_PACK_INFO_VAR(ScfEpin, path),
+SCF_PACK_INFO_VAR(ScfEpin, x),
+SCF_PACK_INFO_VAR(ScfEpin, y),
+SCF_PACK_INFO_VAR(ScfEpin, n_diodes),
+SCF_PACK_INFO_VAR(ScfEpin, l_pos),
+
+SCF_PACK_INFO_VAR(ScfEpin, vflag),
+SCF_PACK_INFO_VAR(ScfEpin, pflag),
+SCF_PACK_INFO_VAR(ScfEpin, vconst),
+SCF_PACK_INFO_VAR(ScfEpin, aconst),
+SCF_PACK_END(ScfEpin)
+
+typedef struct {
+       SCF_PACK_DEF_VAR(uint64_t, lid);
+       SCF_PACK_DEF_VARS(uint64_t, cids);
+} ScfEconn;
+
+SCF_PACK_TYPE(ScfEconn)
+SCF_PACK_INFO_VAR(ScfEconn, lid),
+SCF_PACK_INFO_VARS(ScfEconn, cids, uint64_t),
+SCF_PACK_END(ScfEconn)
+
+typedef struct {
+       SCF_PACK_DEF_VAR(uint64_t, id);
+       SCF_PACK_DEF_VARS(uint64_t, pins);
+       SCF_PACK_DEF_VAR(uint64_t, c_pins);
+       SCF_PACK_DEF_VAR(uint64_t, flags);
+       SCF_PACK_DEF_VAR(int64_t, color);
+
+       SCF_PACK_DEF_OBJS(ScfEconn, conns);
+       SCF_PACK_DEF_OBJS(ScfLine, lines);
+
+       SCF_PACK_DEF_VAR(double, v);
+       SCF_PACK_DEF_VAR(double, jv);
+       SCF_PACK_DEF_VAR(double, a);
+       SCF_PACK_DEF_VAR(double, ja);
+       SCF_PACK_DEF_VAR(uint8_t, vconst);
+       SCF_PACK_DEF_VAR(uint8_t, aconst);
+       SCF_PACK_DEF_VAR(uint8_t, vflag);
+} ScfEline;
+
+SCF_PACK_TYPE(ScfEline)
+SCF_PACK_INFO_VAR(ScfEline, id),
+SCF_PACK_INFO_VARS(ScfEline, pins, uint64_t),
+SCF_PACK_INFO_VAR(ScfEline, c_pins),
+SCF_PACK_INFO_VAR(ScfEline, flags),
+SCF_PACK_INFO_VAR(ScfEline, color),
+
+SCF_PACK_INFO_OBJS(ScfEline, conns, ScfEconn),
+SCF_PACK_INFO_OBJS(ScfEline, lines, ScfLine),
+
+SCF_PACK_INFO_VAR(ScfEline, v),
+SCF_PACK_INFO_VAR(ScfEline, jv),
+SCF_PACK_INFO_VAR(ScfEline, a),
+SCF_PACK_INFO_VAR(ScfEline, ja),
+SCF_PACK_INFO_VAR(ScfEline, vconst),
+SCF_PACK_INFO_VAR(ScfEline, aconst),
+SCF_PACK_INFO_VAR(ScfEline, vflag),
+SCF_PACK_END(ScfEline)
+
+struct scf_ecomponent_s
+{
+       SCF_PACK_DEF_VAR(uint64_t, id);
+       SCF_PACK_DEF_VAR(uint64_t, type);
+       SCF_PACK_DEF_VAR(uint64_t, model);
+       SCF_PACK_DEF_OBJS(ScfEpin, pins);
+
+       SCF_PACK_DEF_VAR(double, v);
+       SCF_PACK_DEF_VAR(double, jv);
+       SCF_PACK_DEF_VAR(double, a);
+       SCF_PACK_DEF_VAR(double, ja);
+
+       SCF_PACK_DEF_VAR(double, r);
+       SCF_PACK_DEF_VAR(double, jr);
+       SCF_PACK_DEF_VAR(double, uf);
+       SCF_PACK_DEF_VAR(double, uh);
+
+       SCF_PACK_DEF_VAR(int64_t, color);
+       SCF_PACK_DEF_VAR(int, status);
+       SCF_PACK_DEF_VAR(int, x);
+       SCF_PACK_DEF_VAR(int, y);
+       SCF_PACK_DEF_VAR(int, w);
+       SCF_PACK_DEF_VAR(int, h);
+       SCF_PACK_DEF_VAR(uint8_t, vflag);
+       SCF_PACK_DEF_VAR(uint8_t, lock);
+};
+
+SCF_PACK_TYPE(ScfEcomponent)
+SCF_PACK_INFO_VAR(ScfEcomponent, id),
+SCF_PACK_INFO_VAR(ScfEcomponent, type),
+SCF_PACK_INFO_VAR(ScfEcomponent, model),
+SCF_PACK_INFO_OBJS(ScfEcomponent, pins, ScfEpin),
+
+SCF_PACK_INFO_VAR(ScfEcomponent, v),
+SCF_PACK_INFO_VAR(ScfEcomponent, jv),
+SCF_PACK_INFO_VAR(ScfEcomponent, a),
+SCF_PACK_INFO_VAR(ScfEcomponent, ja),
+
+SCF_PACK_INFO_VAR(ScfEcomponent, r),
+SCF_PACK_INFO_VAR(ScfEcomponent, jr),
+SCF_PACK_INFO_VAR(ScfEcomponent, uf),
+SCF_PACK_INFO_VAR(ScfEcomponent, uh),
+
+SCF_PACK_INFO_VAR(ScfEcomponent, color),
+SCF_PACK_INFO_VAR(ScfEcomponent, status),
+SCF_PACK_INFO_VAR(ScfEcomponent, x),
+SCF_PACK_INFO_VAR(ScfEcomponent, y),
+SCF_PACK_INFO_VAR(ScfEcomponent, w),
+SCF_PACK_INFO_VAR(ScfEcomponent, h),
+SCF_PACK_INFO_VAR(ScfEcomponent, vflag),
+SCF_PACK_INFO_VAR(ScfEcomponent, lock),
+SCF_PACK_END(ScfEcomponent)
+
+struct scf_efunction_s
+{
+       SCF_PACK_DEF_VARS(uint8_t, name);
+       SCF_PACK_DEF_OBJS(ScfEcomponent, components);
+       SCF_PACK_DEF_OBJS(ScfEline,      elines);
+       SCF_PACK_DEF_VAR(int, x);
+       SCF_PACK_DEF_VAR(int, y);
+       SCF_PACK_DEF_VAR(int, w);
+       SCF_PACK_DEF_VAR(int, h);
+};
+
+SCF_PACK_TYPE(ScfEfunction)
+SCF_PACK_INFO_VARS(ScfEfunction, name,       uint8_t),
+SCF_PACK_INFO_OBJS(ScfEfunction, components, ScfEcomponent),
+SCF_PACK_INFO_OBJS(ScfEfunction, elines,     ScfEline),
+SCF_PACK_INFO_VAR(ScfEfunction,  x),
+SCF_PACK_INFO_VAR(ScfEfunction,  y),
+SCF_PACK_INFO_VAR(ScfEfunction,  w),
+SCF_PACK_INFO_VAR(ScfEfunction,  h),
+SCF_PACK_END(ScfEfunction)
+
+struct scf_eboard_s
+{
+       SCF_PACK_DEF_OBJS(ScfEfunction, functions);
+};
+
+SCF_PACK_TYPE(ScfEboard)
+SCF_PACK_INFO_OBJS(ScfEboard, functions, ScfEfunction),
+SCF_PACK_END(ScfEboard)
+
+
+ScfEconn*   scf_econn__alloc();
+int            scf_econn__add_cid(ScfEconn* ec, uint64_t  cid);
+int            scf_econn__del_cid(ScfEconn* ec, uint64_t  cid);
+
+ScfEline*      scf_eline__alloc();
+int            scf_eline__add_line(ScfEline* el, ScfLine*  l);
+int            scf_eline__del_line(ScfEline* el, ScfLine*  l);
+
+int            scf_eline__add_pin (ScfEline* el, uint64_t  cid, uint64_t pid);
+int            scf_eline__del_pin (ScfEline* el, uint64_t  cid, uint64_t pid);
+
+int            scf_eline__add_conn(ScfEline* el, ScfEconn* ec);
+int            scf_eline__del_conn(ScfEline* el, ScfEconn* ec);
+
+ScfEpin*       scf_epin__alloc();
+int            scf_epin__add_component(ScfEpin* pin, uint64_t cid, uint64_t pid);
+int            scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid);
+
+ScfEcomponent* scf_ecomponent__alloc  (uint64_t type);
+int            scf_ecomponent__add_pin(ScfEcomponent* c, ScfEpin* pin);
+int            scf_ecomponent__del_pin(ScfEcomponent* c, ScfEpin* pin);
+
+ScfEfunction*  scf_efunction__alloc        (const   char* name);
+int            scf_efunction__add_component(ScfEfunction* f, ScfEcomponent* c);
+int            scf_efunction__del_component(ScfEfunction* f, ScfEcomponent* c);
+
+int            scf_efunction__add_eline    (ScfEfunction* f, ScfEline* el);
+int            scf_efunction__del_eline    (ScfEfunction* f, ScfEline* el);
+
+ScfEboard*     scf_eboard__alloc();
+int            scf_eboard__add_function(ScfEboard* b, ScfEfunction* f);
+int            scf_eboard__del_function(ScfEboard* b, ScfEfunction* f);
+
+#define EDA_INST_ADD_COMPONENT(_ef, _c, _type) \
+       do { \
+               _c = scf_ecomponent__alloc(_type); \
+               if (!_c) \
+                       return -ENOMEM; \
+               \
+               (_c)->id = (_ef)->n_components; \
+               \
+               int ret = scf_efunction__add_component(_ef, _c); \
+               if (ret < 0) { \
+                       ScfEcomponent_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)
+
+#define EDA_PIN_ADD_PIN(_c0, _pid0, _c1, _pid1) \
+       do { \
+               int ret = scf_epin__add_component((_c0)->pins[_pid0], (_c1)->id, (_pid1)); \
+               if (ret < 0) \
+                       return ret; \
+               \
+               ret = scf_epin__add_component((_c1)->pins[_pid1], (_c0)->id, (_pid0)); \
+               if (ret < 0) \
+                       return ret; \
+       } while (0)
+
+#define EDA_PIN_ADD_PIN_EF(_ef, _p0, _p1) \
+       EDA_PIN_ADD_PIN((_ef)->components[(_p0)->cid], (_p0)->id, (_ef)->components[(_p1)->cid], (_p1)->id)
+
+#endif
index 8d1d344f903cf61f6e7d537806a1c1694703ee5b..7b6abb817097f481f73a98df8c6fb51382d929b6 100644 (file)
@@ -40,14 +40,14 @@ int main()
        uint8_t* buf = NULL;
        int      len = 0;
 
-       scf_B_pack(&b, &buf, &len);
+       B_pack(&b, &buf, &len);
 
        int i;
        int j;
        for (i = 0; i < len; i++)
                printf("i: %d, %#x\n", i, buf[i]);
 #if 1
-       scf_B_unpack(&p, buf, len);
+       B_unpack(&p, buf, len);
        printf("p: %p, p->as: %p\n", p, p->as);
        printf("p->d: %lg, p->n_as: %ld, p->as: %p\n", p->d, p->n_as, p->as);
 
@@ -62,7 +62,7 @@ int main()
                printf("\n");
        }
 
-       scf_B_free(p);
+       B_free(p);
        free(buf);
 #endif
        return 0;
index a4f76a8567a6aee119c27c73ad330712b3836516..1d440fe5a5aa0919d424470f691124330d4d4467 100644 (file)
@@ -19,7 +19,7 @@ int __scf_pack_one_index(uint8_t* pack, uint64_t u, int shift)
                        max = i;
                else
                        max -= i;
-               scf_loge("max: %d, i: %d, j: %d, k: %d, shift: %d\n", max, i, j, k, shift);
+               scf_logd("max: %d, i: %d, j: %d, k: %d, shift: %d\n", max, i, j, k, shift);
 
                pack[j] |= max << k;
 
@@ -48,14 +48,14 @@ int __scf_pack_one_index(uint8_t* pack, uint64_t u, int shift)
                        return -EINVAL;
                }
 
-               scf_logi("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
+               scf_logd("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
 
                max = i;
        }
 
        if (8 - k < shift && 0 != max) {
                pack[++j] = 0;
-               scf_logi("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
+               scf_logd("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
        }
 
        return j + 1;
@@ -94,7 +94,7 @@ int __scf_pack_byte_map(uint8_t* pack, uint64_t u, int shift)
        for (i = 0; i < bytes; i++) {
                if (p[i]) {
                        pack[++j] = p[i];
-                       scf_logi("bytes: %d, map: %#x, i: %d, j: %d, p[i]: %#x\n", bytes, map, i, j, p[i]);
+                       scf_logd("bytes: %d, map: %#x, i: %d, j: %d, p[i]: %#x\n", bytes, map, i, j, p[i]);
                }
        }
 
@@ -119,7 +119,7 @@ int __scf_pack2(uint8_t* pack, uint64_t u, int shift)
                u = ~u;
        }
 
-       scf_logw("bits: %d, not: %d, u: %#lx, sum: %d\n", bits, not, u, sum);
+       scf_logd("bits: %d, not: %d, u: %#lx, sum: %d\n", bits, not, u, sum);
 
        pack[0] = not;
 
@@ -180,34 +180,32 @@ int __scf_unpack2(void* p, int shift, const uint8_t* buf, int len)
                        else
                                max -= i;
 
-                       u |= 1u << max;
+                       u |= 1ull << max;
 
-                       if (i < 2)
+                       if (max < 2)
                                shift  = 1;
-                       else if (i < 4)
+                       else if (max < 4)
                                shift  = 2;
 
-                       else if (i < 8)
+                       else if (max < 8)
                                shift  = 3;
-                       else if (i < 16)
+                       else if (max < 16)
                                shift  = 4;
 
-                       else if (i < 32)
+                       else if (max < 32)
                                shift  = 5;
-                       else if (i < 64)
+                       else if (max < 64)
                                shift  = 6;
                        else {
                                scf_loge("unpack error\n");
                                return -EINVAL;
                        }
 
-                       scf_logi("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
-
-                       max = i;
+                       scf_logd("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
                }
 
                j++;
-               scf_logi("u: %ld, %#lx\n", u, u);
+               scf_logd("u: %ld, %#lx\n", u, u);
 
        } else if (!(buf[0] & 0x8)) {
                j = 1;
@@ -221,7 +219,7 @@ int __scf_unpack2(void* p, int shift, const uint8_t* buf, int len)
 
                        u |= u8 << (k << 3);
 
-                       scf_loge("buf[%d]: %#x, u: %#lx\n", j, buf[j], u);
+                       scf_logd("buf[%d]: %#x, u: %#lx, k: %d, bits: %d\n", j, buf[j], u, k, bits);
                        j++;
                }
 
@@ -232,7 +230,7 @@ int __scf_unpack2(void* p, int shift, const uint8_t* buf, int len)
                        if (1 >= len)
                                return -EINVAL;
 
-                       map |= buf[1] & 0xf;
+                       map |= buf[1] << 4;
                        j = 2;
                } else
                        j = 1;
@@ -247,6 +245,8 @@ int __scf_unpack2(void* p, int shift, const uint8_t* buf, int len)
                        uint64_t u8 = buf[j++];
 
                        u |= u8 << (k << 3);
+
+                       scf_logd("buf[%d]: %#x, u: %#lx, k: %d, map: %#x, bits: %d\n", j, buf[j], u, k, map, bits);
                }
        }
 
@@ -266,6 +266,7 @@ int __scf_unpack2(void* p, int shift, const uint8_t* buf, int len)
                        break;
        };
 
+       scf_logd("u: %#lx, j: %d, bits: %d\n", u, j, bits);
        return j;
 }
 
@@ -338,7 +339,7 @@ int __scf_pack(void* p, int size, uint8_t** pbuf, int* plen)
                        *(uint32_t*)pack = *(uint32_t*)p;
                        len = 4;
 #endif
-                       scf_logi("p: %p, %d, len: %d\n\n", p, *(uint32_t*)p, len);
+                       scf_logd("p: %p, %d, len: %d\n\n", p, *(uint32_t*)p, len);
                        break;
                case 8:
 #if 1
@@ -349,7 +350,7 @@ int __scf_pack(void* p, int size, uint8_t** pbuf, int* plen)
                        *(uint64_t*)pack = *(uint64_t*)p;
                        len = 8;
 #endif
-                       scf_logi("p: %p, %ld, %#lx, %lg, len: %d\n\n", p, *(uint64_t*)p, *(uint64_t*)p, *(double*)p, len);
+                       scf_logd("p: %p, %ld, %#lx, %lg, len: %d\n\n", p, *(uint64_t*)p, *(uint64_t*)p, *(double*)p, len);
                        break;
                default:
                        scf_loge("data size '%d' NOT support!\n", size);
@@ -375,12 +376,12 @@ int scf_pack(void* p, scf_pack_info_t* infos, int n_infos, uint8_t** pbuf, int*
        if (!*pbuf)
                *plen = 0;
 
-       printf("\n");
-       scf_logw("p: %p\n", p);
+//     printf("\n");
+       scf_logd("p: %p\n", p);
 
        int i;
        for (i = 0; i < n_infos; i++) {
-               printf("name: %s, size: %ld, offset: %ld, noffset: %ld, msize: %ld, members: %p, n_members: %ld\n",
+               scf_logd("name: %s, size: %ld, offset: %ld, noffset: %ld, msize: %ld, members: %p, n_members: %ld\n",
                                infos[i].name, infos[i].size, infos[i].offset, infos[i].noffset, infos[i].msize, infos[i].members, infos[i].n_members);
 
                if (infos[i].noffset >= 0) {
@@ -389,7 +390,7 @@ int scf_pack(void* p, scf_pack_info_t* infos, int n_infos, uint8_t** pbuf, int*
                        long  n = *(long* )(p + infos[i].noffset);
                        int   j;
 
-                       scf_loge("a: %p, n: %ld, infos[i].msize: %ld, infos[i].noffset: %ld\n", a, n, infos[i].msize, infos[i].noffset);
+                       scf_logd("a: %p, n: %ld, infos[i].msize: %ld, infos[i].noffset: %ld\n", a, n, infos[i].msize, infos[i].noffset);
 
                        for (j = 0; j < n; j++) {
 
@@ -427,7 +428,7 @@ int scf_pack(void* p, scf_pack_info_t* infos, int n_infos, uint8_t** pbuf, int*
                        return ret;
                }
 
-               scf_loge("size: %ld\n\n", infos[i].size);
+               scf_logd("size: %ld\n\n", infos[i].size);
        }
 
        return 0;
@@ -458,7 +459,7 @@ int scf_unpack(void** pp, scf_pack_info_t* infos, int n_infos, const uint8_t* bu
                                return -ENOMEM;
                        *(void**)(p + infos[i].offset) = a;
 
-                       scf_loge("a: %p, n: %ld, infos[i].msize: %ld\n", a, n, infos[i].msize);
+                       scf_logd("a: %p, n: %ld, infos[i].msize: %ld\n", a, n, infos[i].msize);
 
                        for (j = 0; j < n; j++) {
 
@@ -523,7 +524,7 @@ int scf_unpack_free(void* p, scf_pack_info_t* infos, int n_infos)
                        long  n = *(long* )(p + infos[i].noffset);
                        void* a = *(void**)(p + infos[i].offset);
 
-                       scf_loge("a: %p, n: %ld, infos[i].msize: %ld\n", a, n, infos[i].msize);
+                       scf_logd("a: %p, n: %ld, infos[i].msize: %ld\n", a, n, infos[i].msize);
 
                        if (infos[i].members) {
 
@@ -536,7 +537,7 @@ int scf_unpack_free(void* p, scf_pack_info_t* infos, int n_infos)
                                }
                        }
 
-                       scf_logi("a: %p\n", a);
+                       scf_logd("a: %p\n", a);
                        free(a);
                        continue;
                }
@@ -550,7 +551,7 @@ int scf_unpack_free(void* p, scf_pack_info_t* infos, int n_infos)
                }
        }
 
-       scf_logi("p: %p\n", p);
+       scf_logd("p: %p\n", p);
        free(p);
        return 0;
 }
index 1235e80e25c5e6363d99d13e03af72c65aa1adeb..133497b65f4e782e8bc5975b143099583c6e9578 100644 (file)
@@ -45,15 +45,15 @@ static scf_pack_info_t scf_pack_info_##type[] = {
 
 #define SCF_PACK_END(type) \
 }; \
-static int scf_##type##_pack(type* p, uint8_t** pbuf, int* plen) \
+static int type##_pack(type* p, uint8_t** pbuf, int* plen) \
 { \
        return scf_pack(p, scf_pack_info_##type, SCF_PACK_N_INFOS(type), pbuf, plen); \
 } \
-static int scf_##type##_unpack(type** pp, uint8_t* buf, int len) \
+static int type##_unpack(type** pp, uint8_t* buf, int len) \
 { \
        return scf_unpack((void**)pp, scf_pack_info_##type, SCF_PACK_N_INFOS(type), buf, len); \
 } \
-static int scf_##type##_free(type* p) \
+static int type##_free(type* p) \
 { \
        return scf_unpack_free(p, scf_pack_info_##type, SCF_PACK_N_INFOS(type)); \
 }
index 7091925a8b9078c96b4ce889143fb6555bb716e1..44938841bc0619b78ffc369fabca32ed229901ca 100644 (file)
@@ -44,8 +44,8 @@ CFILES += ../native/risc/scf_naja.c
 
 CFILES += ../native/eda/scf_eda.c
 CFILES += ../native/eda/scf_eda_inst.c
-CFILES += ../native/eda/scf_eda_pb.c
-CFILES += ../native/eda/scf_eda.pb-c.c
+CFILES += ../native/eda/scf_eda_pack.c
+CFILES += ../pack/scf_pack.c
 
 CFILES += ../elf/scf_elf.c
 CFILES += ../elf/scf_elf_link.c
@@ -167,6 +167,7 @@ CFLAGS += -I../util
 CFLAGS += -I../core
 CFLAGS += -I../lex
 CFLAGS += -I../parse
+CFLAGS += -I../pack
 CFLAGS += -I../elf
 CFLAGS += -I../vm
 CFLAGS += -I../native
@@ -175,7 +176,7 @@ CFLAGS += -I../native/risc
 CFLAGS += -I../native/eda
 
 LDFLAGS += -ldl
-LDFLAGS += -lprotobuf-c
+#LDFLAGS += -lprotobuf-c
 
 all:
        gcc $(CFLAGS) $(CFILES) $(LDFLAGS) -o scf
index 6852dda452c51f1d7b0235323846569f08415727..8c4ae85a1fe5ef9ff3ca3cd3bd390c06b241904d 100644 (file)
@@ -2058,23 +2058,24 @@ int scf_eda_write_pb(scf_parse_t* parse, const char* out, scf_vector_t* function
                f->ef   = NULL;
 
                if (ret < 0) {
-                       scf_eboard__free(b);
+                       ScfEboard_free(b);
                        return ret;
                }
        }
 
-       size_t len = scf_eboard__get_packed_size(b);
+       uint8_t* buf = NULL;
+       int      len = 0;
 
-       scf_loge("len: %ld\n", len);
-
-       uint8_t* buf = malloc(len);
-       if (!buf) {
-               scf_eboard__free(b);
-               return -ENOMEM;
+       int ret = ScfEboard_pack(b, &buf, &len);
+       if (ret < 0) {
+               ScfEboard_free(b);
+               free(buf);
+               return ret;
        }
 
-       scf_eboard__pack(b, buf);
-       scf_eboard__free(b);
+       scf_loge("len: %d\n", len);
+
+       ScfEboard_free(b);
        b = NULL;
 
        FILE* fp = fopen(out, "wb");
@@ -2083,6 +2084,7 @@ int scf_eda_write_pb(scf_parse_t* parse, const char* out, scf_vector_t* function
 
        fwrite(buf, len, 1, fp);
        fclose(fp);
+       free(buf);
        return 0;
 }
 
index 707a2a820b3d4d92e1553ef8bb0cb73d79fcb73d..55b1def0cdce3471b7196b3eb26fe0e2d2d573b7 100644 (file)
@@ -10,6 +10,8 @@
 #include<errno.h>
 #include<time.h>
 #include<unistd.h>
+#include<limits.h>
+#include<math.h>
 
 #if 1
 #include<sys/time.h>