scf eda.proto
authoryu.dongliang <18588496441@163.com>
Fri, 7 Jul 2023 10:18:12 +0000 (18:18 +0800)
committeryu.dongliang <18588496441@163.com>
Fri, 7 Jul 2023 10:18:12 +0000 (18:18 +0800)
scf_eda.pb-c.c
scf_eda.pb-c.h
scf_eda.proto
scf_eda_pb.c
scf_eda_pb.h

index c4ce91661ae72cf032eb36dbb423aa84085b3b6b..977f9f47dc9fcde64a0ee38496e0d2818e01484a 100644 (file)
@@ -7,47 +7,47 @@
 #endif
 
 #include "scf_eda.pb-c.h"
-void   scf_eline__init
-                     (ScfEline         *message)
+void   scf_line__init
+                     (ScfLine         *message)
 {
-  static ScfEline init_value = SCF_ELINE__INIT;
+  static ScfLine init_value = SCF_LINE__INIT;
   *message = init_value;
 }
-size_t scf_eline__get_packed_size
-                     (const ScfEline *message)
+size_t scf_line__get_packed_size
+                     (const ScfLine *message)
 {
-  assert(message->base.descriptor == &scf_eline__descriptor);
+  assert(message->base.descriptor == &scf_line__descriptor);
   return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
 }
-size_t scf_eline__pack
-                     (const ScfEline *message,
+size_t scf_line__pack
+                     (const ScfLine *message,
                       uint8_t       *out)
 {
-  assert(message->base.descriptor == &scf_eline__descriptor);
+  assert(message->base.descriptor == &scf_line__descriptor);
   return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
 }
-size_t scf_eline__pack_to_buffer
-                     (const ScfEline *message,
+size_t scf_line__pack_to_buffer
+                     (const ScfLine *message,
                       ProtobufCBuffer *buffer)
 {
-  assert(message->base.descriptor == &scf_eline__descriptor);
+  assert(message->base.descriptor == &scf_line__descriptor);
   return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
 }
-ScfEline *
-       scf_eline__unpack
+ScfLine *
+       scf_line__unpack
                      (ProtobufCAllocator  *allocator,
                       size_t               len,
                       const uint8_t       *data)
 {
-  return (ScfEline *)
-     protobuf_c_message_unpack (&scf_eline__descriptor,
+  return (ScfLine *)
+     protobuf_c_message_unpack (&scf_line__descriptor,
                                 allocator, len, data);
 }
-void   scf_eline__free_unpacked
-                     (ScfEline *message,
+void   scf_line__free_unpacked
+                     (ScfLine *message,
                       ProtobufCAllocator *allocator)
 {
-  assert(message->base.descriptor == &scf_eline__descriptor);
+  assert(message->base.descriptor == &scf_line__descriptor);
   protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
 }
 void   scf_epin__init
@@ -93,6 +93,92 @@ void   scf_epin__free_unpacked
   assert(message->base.descriptor == &scf_epin__descriptor);
   protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
 }
+void   scf_econn__init
+                     (ScfEconn         *message)
+{
+  static ScfEconn init_value = SCF_ECONN__INIT;
+  *message = init_value;
+}
+size_t scf_econn__get_packed_size
+                     (const ScfEconn *message)
+{
+  assert(message->base.descriptor == &scf_econn__descriptor);
+  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t scf_econn__pack
+                     (const ScfEconn *message,
+                      uint8_t       *out)
+{
+  assert(message->base.descriptor == &scf_econn__descriptor);
+  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t scf_econn__pack_to_buffer
+                     (const ScfEconn *message,
+                      ProtobufCBuffer *buffer)
+{
+  assert(message->base.descriptor == &scf_econn__descriptor);
+  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+ScfEconn *
+       scf_econn__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data)
+{
+  return (ScfEconn *)
+     protobuf_c_message_unpack (&scf_econn__descriptor,
+                                allocator, len, data);
+}
+void   scf_econn__free_unpacked
+                     (ScfEconn *message,
+                      ProtobufCAllocator *allocator)
+{
+  assert(message->base.descriptor == &scf_econn__descriptor);
+  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void   scf_eline__init
+                     (ScfEline         *message)
+{
+  static ScfEline init_value = SCF_ELINE__INIT;
+  *message = init_value;
+}
+size_t scf_eline__get_packed_size
+                     (const ScfEline *message)
+{
+  assert(message->base.descriptor == &scf_eline__descriptor);
+  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t scf_eline__pack
+                     (const ScfEline *message,
+                      uint8_t       *out)
+{
+  assert(message->base.descriptor == &scf_eline__descriptor);
+  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t scf_eline__pack_to_buffer
+                     (const ScfEline *message,
+                      ProtobufCBuffer *buffer)
+{
+  assert(message->base.descriptor == &scf_eline__descriptor);
+  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+ScfEline *
+       scf_eline__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data)
+{
+  return (ScfEline *)
+     protobuf_c_message_unpack (&scf_eline__descriptor,
+                                allocator, len, data);
+}
+void   scf_eline__free_unpacked
+                     (ScfEline *message,
+                      ProtobufCAllocator *allocator)
+{
+  assert(message->base.descriptor == &scf_eline__descriptor);
+  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
 void   scf_ecomponent__init
                      (ScfEcomponent         *message)
 {
@@ -222,7 +308,7 @@ void   scf_eboard__free_unpacked
   assert(message->base.descriptor == &scf_eboard__descriptor);
   protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
 }
-static const ProtobufCFieldDescriptor scf_eline__field_descriptors[4] =
+static const ProtobufCFieldDescriptor scf_line__field_descriptors[4] =
 {
   {
     "x0",
@@ -230,7 +316,7 @@ static const ProtobufCFieldDescriptor scf_eline__field_descriptors[4] =
     PROTOBUF_C_LABEL_REQUIRED,
     PROTOBUF_C_TYPE_UINT32,
     0,   /* quantifier_offset */
-    offsetof(ScfEline, x0),
+    offsetof(ScfLine, x0),
     NULL,
     NULL,
     0,             /* flags */
@@ -242,7 +328,7 @@ static const ProtobufCFieldDescriptor scf_eline__field_descriptors[4] =
     PROTOBUF_C_LABEL_REQUIRED,
     PROTOBUF_C_TYPE_UINT32,
     0,   /* quantifier_offset */
-    offsetof(ScfEline, y0),
+    offsetof(ScfLine, y0),
     NULL,
     NULL,
     0,             /* flags */
@@ -254,7 +340,7 @@ static const ProtobufCFieldDescriptor scf_eline__field_descriptors[4] =
     PROTOBUF_C_LABEL_REQUIRED,
     PROTOBUF_C_TYPE_UINT32,
     0,   /* quantifier_offset */
-    offsetof(ScfEline, x1),
+    offsetof(ScfLine, x1),
     NULL,
     NULL,
     0,             /* flags */
@@ -266,40 +352,40 @@ static const ProtobufCFieldDescriptor scf_eline__field_descriptors[4] =
     PROTOBUF_C_LABEL_REQUIRED,
     PROTOBUF_C_TYPE_UINT32,
     0,   /* quantifier_offset */
-    offsetof(ScfEline, y1),
+    offsetof(ScfLine, y1),
     NULL,
     NULL,
     0,             /* flags */
     0,NULL,NULL    /* reserved1,reserved2, etc */
   },
 };
-static const unsigned scf_eline__field_indices_by_name[] = {
+static const unsigned scf_line__field_indices_by_name[] = {
   0,   /* field[0] = x0 */
   2,   /* field[2] = x1 */
   1,   /* field[1] = y0 */
   3,   /* field[3] = y1 */
 };
-static const ProtobufCIntRange scf_eline__number_ranges[1 + 1] =
+static const ProtobufCIntRange scf_line__number_ranges[1 + 1] =
 {
   { 1, 0 },
   { 0, 4 }
 };
-const ProtobufCMessageDescriptor scf_eline__descriptor =
+const ProtobufCMessageDescriptor scf_line__descriptor =
 {
   PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_eline",
-  "ScfEline",
-  "ScfEline",
+  "scf_line",
+  "ScfLine",
+  "ScfLine",
   "",
-  sizeof(ScfEline),
+  sizeof(ScfLine),
   4,
-  scf_eline__field_descriptors,
-  scf_eline__field_indices_by_name,
-  1,  scf_eline__number_ranges,
-  (ProtobufCMessageInit) scf_eline__init,
+  scf_line__field_descriptors,
+  scf_line__field_indices_by_name,
+  1,  scf_line__number_ranges,
+  (ProtobufCMessageInit) scf_line__init,
   NULL,NULL,NULL    /* reserved[123] */
 };
-static const ProtobufCFieldDescriptor scf_epin__field_descriptors[7] =
+static const ProtobufCFieldDescriptor scf_epin__field_descriptors[6] =
 {
   {
     "tos",
@@ -373,24 +459,11 @@ static const ProtobufCFieldDescriptor scf_epin__field_descriptors[7] =
     0,             /* flags */
     0,NULL,NULL    /* reserved1,reserved2, etc */
   },
-  {
-    "lines",
-    7,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_MESSAGE,
-    offsetof(ScfEpin, n_lines),
-    offsetof(ScfEpin, lines),
-    &scf_eline__descriptor,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
 };
 static const unsigned scf_epin__field_indices_by_name[] = {
   2,   /* field[2] = cid */
   3,   /* field[3] = flags */
   1,   /* field[1] = id */
-  6,   /* field[6] = lines */
   0,   /* field[0] = tos */
   4,   /* field[4] = x */
   5,   /* field[5] = y */
@@ -398,7 +471,7 @@ static const unsigned scf_epin__field_indices_by_name[] = {
 static const ProtobufCIntRange scf_epin__number_ranges[1 + 1] =
 {
   { 1, 0 },
-  { 0, 7 }
+  { 0, 6 }
 };
 const ProtobufCMessageDescriptor scf_epin__descriptor =
 {
@@ -408,13 +481,141 @@ const ProtobufCMessageDescriptor scf_epin__descriptor =
   "ScfEpin",
   "",
   sizeof(ScfEpin),
-  7,
+  6,
   scf_epin__field_descriptors,
   scf_epin__field_indices_by_name,
   1,  scf_epin__number_ranges,
   (ProtobufCMessageInit) scf_epin__init,
   NULL,NULL,NULL    /* reserved[123] */
 };
+static const ProtobufCFieldDescriptor scf_econn__field_descriptors[2] =
+{
+  {
+    "lid",
+    1,
+    PROTOBUF_C_LABEL_REQUIRED,
+    PROTOBUF_C_TYPE_UINT64,
+    0,   /* quantifier_offset */
+    offsetof(ScfEconn, lid),
+    NULL,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "cids",
+    2,
+    PROTOBUF_C_LABEL_REPEATED,
+    PROTOBUF_C_TYPE_UINT64,
+    offsetof(ScfEconn, n_cids),
+    offsetof(ScfEconn, cids),
+    NULL,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+};
+static const unsigned scf_econn__field_indices_by_name[] = {
+  1,   /* field[1] = cids */
+  0,   /* field[0] = lid */
+};
+static const ProtobufCIntRange scf_econn__number_ranges[1 + 1] =
+{
+  { 1, 0 },
+  { 0, 2 }
+};
+const ProtobufCMessageDescriptor scf_econn__descriptor =
+{
+  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
+  "scf_econn",
+  "ScfEconn",
+  "ScfEconn",
+  "",
+  sizeof(ScfEconn),
+  2,
+  scf_econn__field_descriptors,
+  scf_econn__field_indices_by_name,
+  1,  scf_econn__number_ranges,
+  (ProtobufCMessageInit) scf_econn__init,
+  NULL,NULL,NULL    /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor scf_eline__field_descriptors[4] =
+{
+  {
+    "id",
+    1,
+    PROTOBUF_C_LABEL_REQUIRED,
+    PROTOBUF_C_TYPE_UINT64,
+    0,   /* quantifier_offset */
+    offsetof(ScfEline, id),
+    NULL,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "pins",
+    2,
+    PROTOBUF_C_LABEL_REPEATED,
+    PROTOBUF_C_TYPE_UINT64,
+    offsetof(ScfEline, n_pins),
+    offsetof(ScfEline, pins),
+    NULL,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "conns",
+    3,
+    PROTOBUF_C_LABEL_REPEATED,
+    PROTOBUF_C_TYPE_MESSAGE,
+    offsetof(ScfEline, n_conns),
+    offsetof(ScfEline, conns),
+    &scf_econn__descriptor,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "lines",
+    4,
+    PROTOBUF_C_LABEL_REPEATED,
+    PROTOBUF_C_TYPE_MESSAGE,
+    offsetof(ScfEline, n_lines),
+    offsetof(ScfEline, lines),
+    &scf_line__descriptor,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+};
+static const unsigned scf_eline__field_indices_by_name[] = {
+  2,   /* field[2] = conns */
+  0,   /* field[0] = id */
+  3,   /* field[3] = lines */
+  1,   /* field[1] = pins */
+};
+static const ProtobufCIntRange scf_eline__number_ranges[1 + 1] =
+{
+  { 1, 0 },
+  { 0, 4 }
+};
+const ProtobufCMessageDescriptor scf_eline__descriptor =
+{
+  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
+  "scf_eline",
+  "ScfEline",
+  "ScfEline",
+  "",
+  sizeof(ScfEline),
+  4,
+  scf_eline__field_descriptors,
+  scf_eline__field_indices_by_name,
+  1,  scf_eline__number_ranges,
+  (ProtobufCMessageInit) scf_eline__init,
+  NULL,NULL,NULL    /* reserved[123] */
+};
 static const ProtobufCFieldDescriptor scf_ecomponent__field_descriptors[7] =
 {
   {
index 81d6c72c487bfa177e20b98390a4f74e04efae9a..a3170abb2649f21e66db32e7b232603128a51999 100644 (file)
@@ -15,8 +15,10 @@ PROTOBUF_C__BEGIN_DECLS
 #endif
 
 
-typedef struct _ScfEline ScfEline;
+typedef struct _ScfLine ScfLine;
 typedef struct _ScfEpin ScfEpin;
+typedef struct _ScfEconn ScfEconn;
+typedef struct _ScfEline ScfEline;
 typedef struct _ScfEcomponent ScfEcomponent;
 typedef struct _ScfEfunction ScfEfunction;
 typedef struct _ScfEboard ScfEboard;
@@ -27,7 +29,7 @@ typedef struct _ScfEboard ScfEboard;
 
 /* --- messages --- */
 
-struct  _ScfEline
+struct  _ScfLine
 {
   ProtobufCMessage base;
   uint32_t x0;
@@ -35,8 +37,8 @@ struct  _ScfEline
   uint32_t x1;
   uint32_t y1;
 };
-#define SCF_ELINE__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_eline__descriptor) \
+#define SCF_LINE__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&scf_line__descriptor) \
     , 0, 0, 0, 0 }
 
 
@@ -50,12 +52,38 @@ struct  _ScfEpin
   uint64_t flags;
   uint32_t x;
   uint32_t y;
-  size_t n_lines;
-  ScfEline **lines;
 };
 #define SCF_EPIN__INIT \
  { PROTOBUF_C_MESSAGE_INIT (&scf_epin__descriptor) \
-    , 0,NULL, 0, 0, 0, 0, 0, 0,NULL }
+    , 0,NULL, 0, 0, 0, 0, 0 }
+
+
+struct  _ScfEconn
+{
+  ProtobufCMessage base;
+  uint64_t lid;
+  size_t n_cids;
+  uint64_t *cids;
+};
+#define SCF_ECONN__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&scf_econn__descriptor) \
+    , 0, 0,NULL }
+
+
+struct  _ScfEline
+{
+  ProtobufCMessage base;
+  uint64_t id;
+  size_t n_pins;
+  uint64_t *pins;
+  size_t n_conns;
+  ScfEconn **conns;
+  size_t n_lines;
+  ScfLine **lines;
+};
+#define SCF_ELINE__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&scf_eline__descriptor) \
+    , 0, 0,NULL, 0,NULL, 0,NULL }
 
 
 struct  _ScfEcomponent
@@ -98,24 +126,24 @@ struct  _ScfEboard
     , 0,NULL }
 
 
-/* ScfEline methods */
-void   scf_eline__init
-                     (ScfEline         *message);
-size_t scf_eline__get_packed_size
-                     (const ScfEline   *message);
-size_t scf_eline__pack
-                     (const ScfEline   *message,
+/* ScfLine methods */
+void   scf_line__init
+                     (ScfLine         *message);
+size_t scf_line__get_packed_size
+                     (const ScfLine   *message);
+size_t scf_line__pack
+                     (const ScfLine   *message,
                       uint8_t             *out);
-size_t scf_eline__pack_to_buffer
-                     (const ScfEline   *message,
+size_t scf_line__pack_to_buffer
+                     (const ScfLine   *message,
                       ProtobufCBuffer     *buffer);
-ScfEline *
-       scf_eline__unpack
+ScfLine *
+       scf_line__unpack
                      (ProtobufCAllocator  *allocator,
                       size_t               len,
                       const uint8_t       *data);
-void   scf_eline__free_unpacked
-                     (ScfEline *message,
+void   scf_line__free_unpacked
+                     (ScfLine *message,
                       ProtobufCAllocator *allocator);
 /* ScfEpin methods */
 void   scf_epin__init
@@ -136,6 +164,44 @@ ScfEpin *
 void   scf_epin__free_unpacked
                      (ScfEpin *message,
                       ProtobufCAllocator *allocator);
+/* ScfEconn methods */
+void   scf_econn__init
+                     (ScfEconn         *message);
+size_t scf_econn__get_packed_size
+                     (const ScfEconn   *message);
+size_t scf_econn__pack
+                     (const ScfEconn   *message,
+                      uint8_t             *out);
+size_t scf_econn__pack_to_buffer
+                     (const ScfEconn   *message,
+                      ProtobufCBuffer     *buffer);
+ScfEconn *
+       scf_econn__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data);
+void   scf_econn__free_unpacked
+                     (ScfEconn *message,
+                      ProtobufCAllocator *allocator);
+/* ScfEline methods */
+void   scf_eline__init
+                     (ScfEline         *message);
+size_t scf_eline__get_packed_size
+                     (const ScfEline   *message);
+size_t scf_eline__pack
+                     (const ScfEline   *message,
+                      uint8_t             *out);
+size_t scf_eline__pack_to_buffer
+                     (const ScfEline   *message,
+                      ProtobufCBuffer     *buffer);
+ScfEline *
+       scf_eline__unpack
+                     (ProtobufCAllocator  *allocator,
+                      size_t               len,
+                      const uint8_t       *data);
+void   scf_eline__free_unpacked
+                     (ScfEline *message,
+                      ProtobufCAllocator *allocator);
 /* ScfEcomponent methods */
 void   scf_ecomponent__init
                      (ScfEcomponent         *message);
@@ -195,12 +261,18 @@ void   scf_eboard__free_unpacked
                       ProtobufCAllocator *allocator);
 /* --- per-message closures --- */
 
-typedef void (*ScfEline_Closure)
-                 (const ScfEline *message,
+typedef void (*ScfLine_Closure)
+                 (const ScfLine *message,
                   void *closure_data);
 typedef void (*ScfEpin_Closure)
                  (const ScfEpin *message,
                   void *closure_data);
+typedef void (*ScfEconn_Closure)
+                 (const ScfEconn *message,
+                  void *closure_data);
+typedef void (*ScfEline_Closure)
+                 (const ScfEline *message,
+                  void *closure_data);
 typedef void (*ScfEcomponent_Closure)
                  (const ScfEcomponent *message,
                   void *closure_data);
@@ -216,8 +288,10 @@ typedef void (*ScfEboard_Closure)
 
 /* --- descriptors --- */
 
-extern const ProtobufCMessageDescriptor scf_eline__descriptor;
+extern const ProtobufCMessageDescriptor scf_line__descriptor;
 extern const ProtobufCMessageDescriptor scf_epin__descriptor;
+extern const ProtobufCMessageDescriptor scf_econn__descriptor;
+extern const ProtobufCMessageDescriptor scf_eline__descriptor;
 extern const ProtobufCMessageDescriptor scf_ecomponent__descriptor;
 extern const ProtobufCMessageDescriptor scf_efunction__descriptor;
 extern const ProtobufCMessageDescriptor scf_eboard__descriptor;
index d46b24677c2b02bee48d049a1c7b002cb5694750..1edf3a21ffc8c56f8e0df9dca04e4dd9c83f91ce 100644 (file)
@@ -1,6 +1,6 @@
 syntax="proto2";
 
-message scf_eline
+message scf_line
 {
        required uint32 x0    = 1;
        required uint32 y0    = 2;
@@ -17,7 +17,20 @@ message scf_epin
 
        required uint32    x     = 5;
        required uint32    y     = 6;
-       repeated scf_eline lines = 7;
+}
+
+message scf_econn
+{
+       required uint64    lid   = 1;
+       repeated uint64    cids  = 2;
+}
+
+message scf_eline
+{
+       required uint64    id    = 1;
+       repeated uint64    pins  = 2;
+       repeated scf_econn conns = 3;
+       repeated scf_line  lines = 4;
 }
 
 message scf_ecomponent
index 2791ce380d73dfbc4218b24c237125212f0534a9..87a67746b2a3707cd1e502673514f53d052d9f8c 100644 (file)
@@ -14,6 +14,74 @@ static int component_pins[SCF_EDA_Components_NB] =
        SCF_EDA_Transistor_NB,
 };
 
+ScfEconn* scf_econn__alloc()
+{
+       ScfEconn* ec = malloc(sizeof(ScfEconn));
+       if (!ec)
+               return NULL;
+
+       scf_econn__init(ec);
+       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;
+}
+
+void scf_econn__free(ScfEconn* ec)
+{
+       if (ec) {
+               if (ec->cids)
+                       free(ec->cids);
+
+               free(ec);
+       }
+}
+
 ScfEline* scf_eline__alloc()
 {
        ScfEline* l = malloc(sizeof(ScfEline));
@@ -24,64 +92,105 @@ ScfEline* scf_eline__alloc()
        return l;
 }
 
-void scf_eline__free(ScfEline* l)
+int scf_eline__add_line(ScfEline* el, ScfLine*  l)
 {
-       if (l)
-               free(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;
 }
 
-ScfEpin* scf_epin__alloc()
+int scf_eline__del_line(ScfEline* el, ScfLine*  l)
 {
-       ScfEpin* pin = malloc(sizeof(ScfEpin));
-       if (!pin)
-               return NULL;
+       if (!el || !l)
+               return -EINVAL;
 
-       scf_epin__init(pin);
-       return pin;
+       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_epin__add_component(ScfEpin* pin, uint64_t cid, uint64_t pid)
+int scf_eline__add_pin(ScfEline* el, uint64_t  cid, uint64_t pid)
 {
-       if (!pin)
+       if (!el)
                return -EINVAL;
 
-       for (size_t i = 0; i + 1 < pin->n_tos; i += 2) {
+       for (size_t i = 0; i + 1 < el->n_pins; i += 2) {
 
-               if (pin->tos[i] == cid && pin->tos[i + 1] == pid)
+               if (el->pins[i] == cid && el->pins[i + 1] == pid)
                        return 0;
        }
 
-       uint64_t* p = realloc(pin->tos, sizeof(uint64_t) * (pin->n_tos + 2));
+       uint64_t* p = realloc(el->pins, sizeof(uint64_t) * (el->n_pins + 2));
        if (!p)
                return -ENOMEM;
 
-       pin->tos = p;
-       pin->tos[pin->n_tos++] = cid;
-       pin->tos[pin->n_tos++] = pid;
+       el->pins = p;
+       el->pins[el->n_pins++] = cid;
+       el->pins[el->n_pins++] = pid;
        return 0;
 }
 
-int scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid)
+int scf_eline__del_pin(ScfEline* el, uint64_t  cid, uint64_t pid)
 {
-       if (!pin)
+       if (!el)
                return -EINVAL;
 
        uint64_t* p;
        size_t    i;
        size_t    j;
 
-       for (i = 0; i + 1 < pin->n_tos; i += 2) {
+       for (i = 0; i + 1 < el->n_pins; i += 2) {
 
-               if (pin->tos[i] == cid && pin->tos[i + 1] == pid) {
+               if (el->pins[i] == cid && el->pins[i + 1] == pid) {
 
-                       for (j = i + 2;  j  < pin->n_tos; j++)
-                               pin->tos[j - 2] = pin->tos[j];
+                       for (j = i + 2;  j  < el->n_pins; j++)
+                               el->pins[j - 2] = el->pins[j];
 
-                       pin->n_tos -= 2;
+                       el->n_pins -= 2;
 
-                       p = realloc(pin->tos, sizeof(uint64_t) * pin->n_tos);
+                       p = realloc(el->pins, sizeof(uint64_t) * el->n_pins);
                        if (p)
-                               pin->tos = p;
+                               el->pins = p;
                        return 0;
                }
        }
@@ -89,76 +198,143 @@ int scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid)
        return -EINVAL;
 }
 
-int scf_epin__add_line(ScfEpin* pin, ScfEline* l)
+int scf_eline__add_conn(ScfEline* el, ScfEconn* ec)
 {
-       if (!pin || !l)
+       if (!el || !ec)
                return -EINVAL;
 
-       for (size_t i = 0; i < pin->n_lines; i++) {
+       for (size_t i = 0; i < el->n_conns; i++) {
 
-               if (pin->lines[i]->x0 == l->x0
-                && pin->lines[i]->y0 == l->y0
-                && pin->lines[i]->x1 == l->x1
-                && pin->lines[i]->y1 == l->y1)
+               if (el->conns[i] == ec)
                        return 0;
        }
 
-       void* p = realloc(pin->lines, sizeof(ScfEline*) * (pin->n_lines + 1));
+       void* p = realloc(el->conns, sizeof(ScfEconn*) * (el->n_conns + 1));
        if (!p)
                return -ENOMEM;
 
-       pin->lines = p;
-       pin->lines[pin->n_lines++] = l;
+       el->conns = p;
+       el->conns[el->n_conns++] = ec;
        return 0;
 }
 
-int scf_epin__del_line(ScfEpin* pin, ScfEline* l)
+int scf_eline__del_conn(ScfEline* el, ScfEconn* ec)
 {
-       if (!pin || !l)
+       if (!el || !ec)
                return -EINVAL;
 
-       void*  p;
-       size_t i;
-       size_t j;
-       size_t n = pin->n_lines;
+       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;
+}
+
+void scf_eline__free(ScfEline* l)
+{
+       if (l) {
+               size_t i;
+
+               if (l->pins)
+                       free(l->pins);
+
+               if (l->conns) {
+                       for (i = 0; i < l->n_conns; i++)
+                               scf_econn__free(l->conns[i]);
 
-       for (i = 0; i < pin->n_lines; ) {
+                       free(l->conns);
+               }
 
-               if (pin->lines[i]->x0 == l->x0
-                && pin->lines[i]->y0 == l->y0
-                && pin->lines[i]->x1 == l->x1
-                && pin->lines[i]->y1 == l->y1) {
+               if (l->lines) {
+                       for (i = 0; i < l->n_lines; i++)
+                               free(l->lines[i]);
 
-                       for (j = i + 1;  j    < pin->n_lines; j++)
-                               pin->lines[j - 1] = pin->lines[j];
+                       free(l->lines);
+               }
 
-                       pin->n_lines--;
-               } else
-                       i++;
+               free(l);
        }
+}
+
+ScfEpin* scf_epin__alloc()
+{
+       ScfEpin* pin = malloc(sizeof(ScfEpin));
+       if (!pin)
+               return NULL;
+
+       scf_epin__init(pin);
+       return pin;
+}
+
+int scf_epin__add_component(ScfEpin* pin, uint64_t cid, uint64_t pid)
+{
+       if (!pin)
+               return -EINVAL;
 
-       if (pin->n_lines < n) {
-               p = realloc(pin->lines, sizeof(ScfEline*) * pin->n_lines);
-               if (p)
-                       pin->lines = p;
+       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;
 }
 
-void scf_epin__free(ScfEpin* pin)
+int scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid)
 {
-       if (pin) {
-               scf_logd("pin: %p\n", pin);
+       if (!pin)
+               return -EINVAL;
 
-               if (pin->lines) {
-                       size_t i;
+       uint64_t* p;
+       size_t    i;
+       size_t    j;
 
-                       for (i = 0; i < pin->n_lines; i++)
-                               scf_eline__free(pin->lines[i]);
+       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];
 
-                       free(pin->lines);
+                       pin->n_tos -= 2;
+
+                       p = realloc(pin->tos, sizeof(uint64_t) * pin->n_tos);
+                       if (p)
+                               pin->tos = p;
+                       return 0;
                }
+       }
+
+       return -EINVAL;
+}
+
+void scf_epin__free(ScfEpin* pin)
+{
+       if (pin) {
+               scf_logd("pin: %p\n", pin);
 
                if (pin->tos)
                        free(pin->tos);
index 739e566c90116f4ed992d3926ebab772197751ba..ca5eb6524a99b5f989ae4146fbe1b933b54323e8 100644 (file)
@@ -40,14 +40,25 @@ enum {
        SCF_EDA_Transistor_NB,
 };
 
+ScfEconn*      scf_econn__alloc();
+int            scf_econn__add_cid(ScfEconn* ec, uint64_t  cid);
+int            scf_econn__del_cid(ScfEconn* ec, uint64_t  cid);
+void           scf_econn__free(ScfEconn* ec);
+
 ScfEline*      scf_eline__alloc();
-void           scf_eline__free (ScfEline* l);
+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);
+void           scf_eline__free    (ScfEline* el);
 
 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);
-int            scf_epin__add_line     (ScfEpin* pin, ScfEline* l);
-int            scf_epin__del_line     (ScfEpin* pin, ScfEline* l);
 void           scf_epin__free         (ScfEpin* pin);
 
 ScfEcomponent* scf_ecomponent__alloc(uint64_t type);