1 /* gEDA - GPL Electronic Design Automation
2 * gnetlist - gEDA Netlist
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2020 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32 #include <libgeda/libgeda.h>
34 #include "../include/globals.h"
35 #include "../include/prototype.h"
37 /* used by the extract functions below */
38 #define DELIMITERS ",; "
40 /* hack rename this to be s_return_tail */
41 /* update object_tail or any list of that matter */
42 NETLIST
*s_netlist_return_tail(NETLIST
* head
)
44 NETLIST
*nl_current
= NULL
;
45 NETLIST
*ret_struct
= NULL
;
48 while (nl_current
!= NULL
) { /* goto end of list */
49 ret_struct
= nl_current
;
50 nl_current
= nl_current
->next
;
56 /* hack rename this to be s_return_head */
57 /* update object_tail or any list of that matter */
58 NETLIST
*s_netlist_return_head(NETLIST
* tail
)
60 NETLIST
*nl_current
= NULL
;
61 NETLIST
*ret_struct
= NULL
;
64 while (nl_current
!= NULL
) { /* goto end of list */
65 ret_struct
= nl_current
;
66 nl_current
= nl_current
->prev
;
73 /* returns new node */
74 NETLIST
*s_netlist_add(NETLIST
* ptr
)
78 new_node
= (NETLIST
*) g_malloc(sizeof(NETLIST
));
80 /* setup node information */
82 new_node
->cpins
= NULL
;
83 new_node
->component_uref
= NULL
;
84 new_node
->object_ptr
= NULL
;
85 new_node
->hierarchy_tag
= NULL
;
86 new_node
->composite_component
= FALSE
;
88 /* Setup link list stuff */
89 new_node
->next
= NULL
;
92 new_node
->prev
= NULL
; /* setup previous link */
95 new_node
->prev
= ptr
; /* setup previous link */
101 void s_netlist_print(NETLIST
* ptr
)
103 NETLIST
*nl_current
= NULL
;
107 if (nl_current
== NULL
) {
111 while (nl_current
!= NULL
) {
113 if (nl_current
->nlid
!= -1) {
115 if (nl_current
->component_uref
) {
116 printf("component %s \n", nl_current
->component_uref
);
118 printf("component SPECIAL \n");
121 if (nl_current
->hierarchy_tag
) {
122 printf("Hierarchy tag: %s\n", nl_current
->hierarchy_tag
);
125 if (nl_current
->cpins
) {
126 s_cpinlist_print(nl_current
->cpins
);
132 nl_current
= nl_current
->next
;
137 void s_netlist_post_process(TOPLEVEL
* pr_current
, NETLIST
* head
)
140 CPINLIST
*pl_current
;
143 printf("\n- Staring post processing\n");
144 printf("- Naming nets:\n");
147 /* this pass gives all nets a name, whether specified or creates a */
150 while (nl_current
!= NULL
) {
151 if (nl_current
->cpins
) {
152 pl_current
= nl_current
->cpins
;
153 while (pl_current
!= NULL
) {
155 if (pl_current
->plid
!= -1) {
159 if (pl_current
->plid
!= -1 && pl_current
->nets
) {
161 g_free(pl_current
->net_name
);
165 /* only name nets of components which */
167 if (nl_current
->component_uref
) {
168 pl_current
->net_name
=
169 s_net_name(pr_current
,
172 nl_current
->hierarchy_tag
,
175 /* put this name also in the first
176 node of the nets linked list */
177 if (pl_current
->net_name
&& pl_current
->nets
) {
178 if (pl_current
->nets
->next
) {
179 pl_current
->nets
->next
->net_name
=
180 g_strdup (pl_current
->net_name
);
186 pl_current
= pl_current
->next
;
189 nl_current
= nl_current
->next
;
194 printf("- Renaming nets:\n");
197 s_rename_all(pr_current
, head
);
201 printf("- Resolving hierarchy:\n");
203 s_hierarchy_post_process(pr_current
, head
);
206 if (pr_current
->hierarchy_uref_mangle
== FALSE
) {
208 printf("- Removing refdes mangling:\n");
210 s_hierarchy_remove_uref_mangling(pr_current
, head
);
216 void s_netlist_name_named_nets (TOPLEVEL
*pr_current
,
217 NETLIST
*named_netlist
,
218 NETLIST
*unnamed_netlist
) {
221 CPINLIST
*pl_current
;
226 printf("\n- Staring post processing\n");
227 printf("- Naming nets of graphical objects:\n");
230 /* this pass gives all nets a name, whether specified or creates a */
232 nl_current
= unnamed_netlist
;
233 while (nl_current
!= NULL
) {
234 if (nl_current
->cpins
) {
235 pl_current
= nl_current
->cpins
;
236 while (pl_current
!= NULL
) {
238 if (pl_current
->plid
!= -1) {
242 if (pl_current
->plid
!= -1 && pl_current
->nets
) {
245 n_current
= pl_current
->nets
;
246 while (n_current
!= NULL
) {
247 g_free (n_current
->net_name
);
248 n_current
->net_name
= s_netlist_netname_of_netid(pr_current
,
252 if (n_current
->net_name
!= NULL
) {
253 net_name
= n_current
->net_name
;
255 n_current
= n_current
->next
;
257 if (net_name
!= NULL
) {
258 pl_current
->net_name
= g_strdup(net_name
);
261 pl_current
= pl_current
->next
;
264 nl_current
= nl_current
->next
;
271 char *s_netlist_netname_of_netid (TOPLEVEL
*pr_current
,
272 NETLIST
*netlist_head
,
276 CPINLIST
*pl_current
;
279 nl_current
= netlist_head
;
281 /* walk through the list of components, and through the list
282 * of individual pins on each, looking for the net identifier
284 while (nl_current
!= NULL
) {
285 pl_current
= nl_current
->cpins
;
286 while (pl_current
!= NULL
) {
287 if (pl_current
->net_name
) {
288 n_current
= pl_current
->nets
;
289 while (n_current
!= NULL
) {
290 if (n_current
->nid
== net_id
) {
291 return (g_strdup(n_current
->net_name
));
293 n_current
= n_current
->next
;
296 pl_current
= pl_current
->next
;
298 nl_current
= nl_current
->next
;