gnetlist

s_netlist.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gnetlist - gEDA Netlist
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License 
00017  * along with this program; if not, write to the Free Software 
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <stdio.h>
00024 #include <ctype.h>
00025 #ifdef HAVE_STDLIB_H
00026 #include <stdlib.h>
00027 #endif
00028 #ifdef HAVE_ASSERT_H
00029 #include <assert.h>
00030 #endif
00031 
00032 #include <libgeda/libgeda.h>
00033 
00034 #include "../include/globals.h"
00035 #include "../include/prototype.h"
00036 
00037 #ifdef HAVE_LIBDMALLOC
00038 #include <dmalloc.h>
00039 #endif
00040 
00041 /* used by the extract functions below */
00042 #define DELIMITERS ",; "
00043 
00044 /* hack rename this to be s_return_tail */
00045 /* update object_tail or any list of that matter */
00046 NETLIST *s_netlist_return_tail(NETLIST * head)
00047 {
00048     NETLIST *nl_current = NULL;
00049     NETLIST *ret_struct = NULL;
00050 
00051     nl_current = head;
00052     while (nl_current != NULL) {    /* goto end of list */
00053     ret_struct = nl_current;
00054     nl_current = nl_current->next;
00055     }
00056 
00057     return (ret_struct);
00058 }
00059 
00060 /* hack rename this to be s_return_head */
00061 /* update object_tail or any list of that matter */
00062 NETLIST *s_netlist_return_head(NETLIST * tail)
00063 {
00064     NETLIST *nl_current = NULL;
00065     NETLIST *ret_struct = NULL;
00066 
00067     nl_current = tail;
00068     while (nl_current != NULL) {    /* goto end of list */
00069     ret_struct = nl_current;
00070     nl_current = nl_current->prev;
00071     }
00072 
00073     return (ret_struct);
00074 }
00075 
00076 
00077 /* returns new node */
00078 NETLIST *s_netlist_add(NETLIST * ptr)
00079 {
00080     NETLIST *new_node;
00081 
00082     new_node = (NETLIST *) g_malloc(sizeof(NETLIST));
00083 
00084     /* setup node information */
00085     new_node->nlid = 0;
00086     new_node->cpins = NULL;
00087     new_node->component_uref = NULL;
00088     new_node->object_ptr = NULL;
00089     new_node->hierarchy_tag = NULL;
00090     new_node->composite_component = FALSE;
00091 
00092     /* Setup link list stuff */
00093     new_node->next = NULL;
00094 
00095     if (ptr == NULL) {
00096     new_node->prev = NULL;  /* setup previous link */
00097     return (new_node);
00098     } else {
00099     new_node->prev = ptr;   /* setup previous link */
00100     ptr->next = new_node;
00101     return (ptr->next);
00102     }
00103 }
00104 
00105 void s_netlist_print(NETLIST * ptr)
00106 {
00107     NETLIST *nl_current = NULL;
00108 
00109     nl_current = ptr;
00110 
00111     if (nl_current == NULL) {
00112     return;
00113     }
00114 
00115     while (nl_current != NULL) {
00116 
00117     if (nl_current->nlid != -1) {
00118 
00119         if (nl_current->component_uref) {
00120         printf("component %s \n", nl_current->component_uref);
00121         } else {
00122         printf("component SPECIAL \n");
00123         }
00124 
00125         if (nl_current->hierarchy_tag) {
00126         printf("Hierarchy tag: %s\n", nl_current->hierarchy_tag);
00127         }
00128 
00129         if (nl_current->cpins) {
00130         s_cpinlist_print(nl_current->cpins);
00131         }
00132 
00133         printf("\n");
00134     }
00135 
00136     nl_current = nl_current->next;
00137     }
00138     printf("\n");
00139 }
00140 
00141 void s_netlist_post_process(TOPLEVEL * pr_current, NETLIST * head)
00142 {
00143     NETLIST *nl_current;
00144     CPINLIST *pl_current;
00145 
00146     nl_current = head;
00147 
00148     if (verbose_mode) {
00149     printf("\n- Staring post processing\n");
00150     printf("- Naming nets:\n");
00151     }
00152 
00153     /* this pass gives all nets a name, whether specified or creates a */
00154     /* name */
00155     nl_current = head;
00156     while (nl_current != NULL) {
00157     if (nl_current->cpins) {
00158         pl_current = nl_current->cpins;
00159         while (pl_current != NULL) {
00160 
00161         if (pl_current->plid != -1) {
00162             verbose_print("p");
00163         }
00164 
00165         if (pl_current->plid != -1 && pl_current->nets) {
00166 
00167             g_free(pl_current->net_name);
00168 
00169             verbose_print("n");
00170 
00171             /* only name nets of components which */
00172             /* have a uref */
00173             if (nl_current->component_uref) {
00174             pl_current->net_name =
00175                 s_net_name(pr_current,
00176                        head,
00177                        pl_current->nets,
00178                        nl_current->hierarchy_tag,
00179                        pl_current->type);
00180 
00181             /* put this name also in the first 
00182                node of the nets linked list */
00183             if (pl_current->net_name && pl_current->nets) {
00184                 if (pl_current->nets->next) {
00185                 pl_current->nets->next->net_name =
00186                     g_strdup (pl_current->net_name);
00187                 }
00188             }
00189             }
00190         }
00191 
00192         pl_current = pl_current->next;
00193         }
00194     }
00195     nl_current = nl_current->next;
00196     }
00197 
00198     verbose_done();
00199     if (verbose_mode) {
00200     printf("- Renaming nets:\n");
00201     }
00202 
00203     s_rename_all(pr_current, head);
00204 
00205     verbose_done();
00206     if (verbose_mode) {
00207     printf("- Resolving hierarchy:\n");
00208     }
00209     s_hierarchy_post_process(pr_current, head);
00210 
00211     verbose_done();
00212     if (pr_current->hierarchy_uref_mangle == FALSE) {
00213     if (verbose_mode) {
00214         printf("- Removing refdes mangling:\n");
00215     }
00216     s_hierarchy_remove_uref_mangling(pr_current, head);
00217     }
00218 
00219     verbose_done();
00220 }
00221 
00222 void s_netlist_name_named_nets (TOPLEVEL *pr_current,
00223                 NETLIST *named_netlist,
00224                 NETLIST *unnamed_netlist) {
00225 
00226   NETLIST *nl_current;
00227   CPINLIST *pl_current;
00228   NET *n_current;
00229   char *net_name;
00230   
00231   if (verbose_mode) {
00232     printf("\n- Staring post processing\n");
00233     printf("- Naming nets of graphical objects:\n");
00234   }
00235   
00236   /* this pass gives all nets a name, whether specified or creates a */
00237   /* name */
00238   nl_current = unnamed_netlist;
00239   while (nl_current != NULL) {
00240     if (nl_current->cpins) {
00241       pl_current = nl_current->cpins;
00242       while (pl_current != NULL) {
00243     
00244     if (pl_current->plid != -1) {
00245       verbose_print("p");
00246     }
00247     
00248     if (pl_current->plid != -1 && pl_current->nets) {
00249       verbose_print("n");
00250       net_name = NULL;
00251       n_current = pl_current->nets;
00252       while (n_current != NULL) {
00253         g_free (n_current->net_name);
00254         n_current->net_name = s_netlist_netname_of_netid(pr_current,
00255                                  named_netlist,
00256                                  n_current->nid);
00257         
00258         if (n_current->net_name != NULL) {
00259           net_name = n_current->net_name;
00260         }
00261         n_current = n_current->next;
00262       }
00263       if (net_name != NULL) {
00264         pl_current->net_name = g_strdup(net_name);
00265       }
00266     }
00267     pl_current = pl_current->next;
00268       }
00269     }
00270     nl_current = nl_current->next;
00271   }
00272 
00273   verbose_done();
00274     
00275 }
00276 
00277 char *s_netlist_netname_of_netid (TOPLEVEL *pr_current,
00278                   NETLIST *netlist_head,
00279                   int net_id) {
00280 
00281   NETLIST *nl_current;
00282   CPINLIST *pl_current;
00283   NET *n_current;
00284   
00285   nl_current = netlist_head;
00286   
00287   /* walk through the list of components, and through the list
00288    * of individual pins on each, looking for the net identifier
00289    */
00290   while (nl_current != NULL) {
00291     pl_current = nl_current->cpins;
00292     while (pl_current != NULL) {
00293       if (pl_current->net_name) {
00294     n_current = pl_current->nets;
00295     while (n_current != NULL) {
00296       if (n_current->nid == net_id) {
00297         return (g_strdup(n_current->net_name));
00298       }
00299       n_current = n_current->next;
00300     }
00301       }
00302       pl_current = pl_current->next;
00303     }
00304     nl_current = nl_current->next;
00305     } 
00306   return NULL;
00307 }
 All Data Structures Files Functions Variables Defines