Subversion Repositories Vertical

Rev

Rev 2 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /* contains the database functions that store the pin configurations
  2.  *
  3.  * $Header: c:\\cygwin\\cvsroot/Vert03/vertlib/database.c,v 1.1.1.1 2003/11/04 23:34:57 mjames Exp $
  4.  * $Log: database.c,v $
  5.  * Revision 1.1.1.1  2003/11/04 23:34:57  mjames
  6.  * Imported into local repositrory
  7.  *
  8.  * Revision 1.13  2003/01/02 21:37:15  mjames
  9.  * Experiment on creating NOT_ROUTABLE_H and NOT_ROUTABLE_L
  10.  * properties on the nets so that pin jumpers can be made without a problem.
  11.  *
  12.  * Still need to sort out pin assignments made to these not_routable nets
  13.  * which will become legal in some cases so that pullups and pulldown
  14.  * pins can be used on the FPGA.
  15.  *
  16.  * Revision 1.12  2002/09/30 13:26:49  MJAMES
  17.  * Upgraded nets to include 'lhs_expression' being the range on the
  18.  * left hand side of a signal connection to a port
  19.  *
  20.  * std_logic_vector (0) <= std_logic , on a port of a chip
  21.  *
  22.  * Revision 1.11  2002/08/06 12:52:54  mjames
  23.  * Merge in from latest version
  24.  *
  25.  *
  26.  * Revision 1.11  2002/03/21 17:13:05  mjames
  27.  * Added search path to vertical file opening for read
  28.  *
  29.  * Revision 1.10  2002/01/15 12:32:42  mjames
  30.  * DLL declarations put in,
  31.  *
  32.  * #ident used
  33.  *
  34.  * Revision 1.9  2001/11/19 09:45:25  mjames
  35.  * Corrected some case statments with no default action
  36.  *
  37.  * Revision 1.8  2001/10/31 22:20:02  mjames
  38.  * Tidying up problematical comments caused by CVS
  39.  * 'intelligent' comment guessing
  40.  *
  41.  * Revision 1.7  2001/10/31 16:22:55  mjames
  42.  * Added a datastructure to hide regular expression information from programs.
  43.  * Changed call to regexec to indicate 0 subexpressions to be matched
  44.  * rather than a number dependent on strlen(string) which was wrong.
  45.  * Net disconnection works on routed and named nets
  46.  *
  47.  * Revision 1.6  2001/10/23 21:12:43  mjames
  48.  * Created preliminary 'disconnect_node' function
  49.  *
  50.  * Revision 1.5  2001/10/10 20:18:24  mjames
  51.  * Added a vert_regcomp function to compile regular expressions
  52.  * with '^' (match start string) and  '$' (match end string) bracketing
  53.  * this => wildcard must match entire string not just a part of it.
  54.  *
  55.  * Revision 1.4  2001/10/07 20:50:53  mjames
  56.  * Added wildcard checking (warn user about
  57.  * using wildcard '*' on the end of a string in stead of wildcard '.*')
  58.  *
  59.  * Revision 1.3  2001/09/25 23:15:24  mjames
  60.  * Converted wildcards to use proper regexp pattern match library
  61.  *
  62.  * Revision 1.2  2001/06/06 12:10:24  mjames
  63.  * Move from HPUX
  64.  *
  65.  * Revision 1.1.1.1  2000/10/19 21:58:35  mjames
  66.  * Mike put it here
  67.  *
  68.  *
  69.  * Revision 1.61  2000/10/04  10:37:03  10:37:03  mjames (Mike James)
  70.  * COnversion to Vertical2, supports signals and components
  71.  *
  72.  * Revision 1.61  2000/10/04  10:37:03  10:37:03  mjames (Mike James)
  73.  * Part of Release PSAVAT01
  74.  *
  75.  * Revision 1.60  2000/10/03  10:05:27  10:05:27  mjames (Mike James)
  76.  * Added CONSTANTS and SIGNALS to architecture
  77.  *
  78.  * Revision 1.58  2000/09/27  14:42:11  14:42:11  mjames (Mike James)
  79.  * Part of Release Sep_27_ST_2000
  80.  *
  81.  * Revision 1.57  2000/09/21  10:15:40  10:15:40  mjames (Mike James)
  82.  * Part of Release Sep21Alpha
  83.  *
  84.  * Revision 1.56  2000/09/21  09:44:29  09:44:29  mjames (Mike James)
  85.  * Added in code to deal with pin equivalents, and removed some
  86.  * spurious diagnostic puts() calls .
  87.  *
  88.  * Revision 1.55  2000/08/25  09:57:09  09:57:09  mjames (Mike James)
  89.  * Part of Release Aug25_alpha
  90.  *
  91.  * Revision 1.54  2000/08/16  08:57:26  08:57:26  mjames (Mike James)
  92.  * Part of Release CD01_Aug2000
  93.  *
  94.  * Revision 1.53  2000/08/14  14:45:07  14:45:07  mjames (Mike James)
  95.  * Part of Release Aug_14_2000
  96.  *
  97.  * Revision 1.52  2000/08/11  08:30:28  08:30:28  mjames (Mike James)
  98.  * Part of Release Aug_11_2000
  99.  *
  100.  * Revision 1.51  2000/08/09  10:31:41  10:31:41  mjames (Mike James)
  101.  * Part of Release Aug__9_2000
  102.  *
  103.  * Revision 1.50  2000/05/31  11:42:48  11:42:48  mjames (Mike James)
  104.  * Part of Release May_31_2000
  105.  *
  106.  * Revision 1.49  2000/05/08  17:01:33  17:01:33  mjames (Mike James)
  107.  * Part of Release May__8_2000
  108.  *
  109.  * Revision 1.48  2000/05/08  16:59:26  16:59:26  mjames (Mike James)
  110.  * Part of Release May__8_2000
  111.  *
  112.  * Revision 1.47  2000/05/08  16:57:03  16:57:03  mjames (Mike James)
  113.  * Part of Release May__8_2000
  114.  *
  115.  * Revision 1.46  2000/03/08  16:18:48  16:18:48  mjames (Mike James)
  116.  * New version including PC
  117.  *
  118.  * Revision 1.43  2000/02/18  15:45:24  15:45:24  mjames (Mike James)
  119.  * Amended to support PC
  120.  *
  121.  * Revision 1.42  2000/01/20  15:58:41  15:58:41  mjames (Mike James)
  122.  * Part of Release R22
  123.  *
  124.  * Revision 1.41  99/12/22  11:15:22  11:15:22  mjames (Mike James)
  125.  * Part of Release Dec_22_1999
  126.  *
  127.  * Revision 1.40  99/06/25  14:34:42  14:34:42  mjames (Mike James)
  128.  * Added in reference to expression.h, but no changes made
  129.  * to the function of acfread yet.
  130.  *
  131.  * Revision 1.39  99/06/18  09:23:19  09:23:19  mjames (Mike James)
  132.  *
  133.  * Revision 1.38  99/05/04  09:50:36  09:50:36  mjames (Mike James)
  134.  * General checkin
  135.  *
  136.  * Revision 1.34  98/08/12  14:19:52  14:19:52  mjames (Mike James)
  137.  * Changed pin definition code to work with VHDL
  138.  * parsing
  139.  * as well as include file list being updated
  140.  *
  141.  * Revision 1.33  98/06/15  14:17:51  14:17:51  mjames (Mike James)
  142.  * Added socket templating pointers - reference to parent template
  143.  * for child template.
  144.  *
  145.  * Revision 1.32  98/02/11  11:25:52  11:25:52  mjames (Mike James)
  146.  * Checked in for version 6.2a
  147.  *
  148.  * Revision 1.31  98/01/13  11:33:35  11:33:35  mjames (Mike James)
  149.  * Added the bility to use a VHDL template file
  150.  * containing $ENT$ and $ARCH$ in the position where one
  151.  * wants the entity and architecture to be given.
  152.  *
  153.  * Revision 1.30  97/04/23  08:42:49  08:42:49  mjames (Mike James)
  154.  * CHecked in for release rel23041997
  155.  *
  156.  * Revision 1.29  96/12/23  15:13:48  15:13:48  mjames (Mike James)
  157.  * Added reverse pointer to show which unrouted net was
  158.  * responsible for the fixing of the pins.
  159.  *
  160.  * Revision 1.28  96/12/23  10:24:02  10:24:02  mjames (Mike James)
  161.  * Altered to make it sort the results
  162.  * of listing COMPONENTS and CHIP pins.
  163.  * /
  164.  *
  165.  * Revision 1.27  96/12/13  08:43:08  08:43:08  mjames (Mike James)
  166.  * Update to v5.1, added Write ID , exact routing
  167.  *
  168.  * Revision 1.26  96/08/06  13:38:51  13:38:51  mjames (Mike James)
  169.  * Added FIX_LOCATION pin attribute to netlist
  170.  *
  171.  * Revision 1.25  96/07/19  14:38:43  14:38:43  mjames (Mike James)
  172.  * Update to give to PRL
  173.  *
  174.  * Revision 1.24  1996/07/12  15:52:12  mjames
  175.  * Sorted out things like Alias and Jumpers
  176.  * Work Correctly
  177.  * Print COrrectly
  178.  *
  179.  * Revision 1.23  96/07/09  15:53:59  15:53:59  mjames (Mike James)
  180.  * Altered aliasing to make it hierarchical, also for jumpering
  181.  *
  182.  * Revision 1.22  96/06/17  11:02:43  11:02:43  mjames (Mike James)
  183.  * Altered the printing of JUMPERED and ALIASED nets
  184.  * ,
  185.  *
  186.  * Revision 1.21  96/06/11  14:11:44  14:11:44  mjames (Mike James)
  187.  * Added hierarchical jumpering
  188.  *
  189.  * Revision 1.20  96/06/04  11:53:18  11:53:18  mjames (Mike James)
  190.  * Added the ability to jumper nets by reference to a node on the nets
  191.  *
  192.  * Revision 1.19  96/05/29  10:52:29  10:52:29  mjames (Mike James)
  193.  *  Added name suffixing to socket ID's and net ID's
  194.  *
  195.  * Revision 1.18  96/04/26  16:01:30  16:01:30  mjames (Mike James)
  196.  * Added SET PORT to force ports on partition
  197.  * ,
  198.  *
  199.  * Revision 1.17  96/04/15  14:19:24  14:19:24  mjames (Mike James)
  200.  * Checkin before datatype printing
  201.  * modifications
  202.  *
  203.  * Revision 1.16  96/03/29  14:46:05  14:46:05  mjames (Mike James)
  204.  * Added VHDL netlist writing to the capabilities of ACFREAD
  205.  *
  206.  * Revision 1.14  96/03/18  13:50:28  13:50:28  mjames (Mike James)
  207.  * Real Revision 2.1
  208.  *
  209.  * Revision 1.11  96/03/13  15:35:30  15:35:30  mjames (Mike James)
  210.  * Changed the name_pref filed to reflect how a net has been routed
  211.  *
  212.  * Revision 1.10  96/02/13  09:13:28  09:13:28  mjames (Mike James)
  213.  * Updated to be version 2.0 with net joining
  214.  *
  215.  * Revision 1.9  96/02/09  10:50:24  10:50:24  mjames (Mike James)
  216.  * Added different behaviour for 'write id' and 'write name'
  217.  * 'write id' now writes all pins including unused ones
  218.  * 'write name' only writes used pins in the ACF file
  219.  *
  220.  *  .
  221.  *
  222.  *
  223.  * Revision 1.8  96/02/08  15:28:29  15:28:29  mjames (Mike James)
  224.  * First release
  225.  *
  226.  * Revision 1.7  96/02/07  16:01:34  16:01:34  mjames (Mike James)
  227.  * Added correct RCS header
  228.  *
  229.  * Revision 1.6  96/02/07  15:50:44  15:50:44  mjames (Mike James)
  230.  * Added RCS ident message
  231.  *
  232.  * Revision 1.5  96/02/07  11:04:07  11:04:07  mjames (Mike James)
  233.  * Checkin before adding new command parsing to program
  234.  *
  235.  * Revision 1.4  96/01/10  13:14:11  13:14:11  mjames (Mike James)
  236.  *  Works in debug mode with EPLD listings and PCB layout
  237.  *
  238.  * Revision 1.3  96/01/08  15:22:51  15:22:51  mjames (Mike James)
  239.  * Managing to make sense of things now
  240.  *
  241.  * Revision 1.2  96/01/07  20:22:29  Mike_James
  242.  * extending database routines
  243.  *
  244.  * Revision 1.1  96/01/07  12:38:12  Mike_James
  245.  * Initial revision
  246.  *
  247.  * Revision 1.2  96/01/04  17:55:52  17:55:52  mjames (Mike James)
  248.  * Correcly reading ACF
  249.  *
  250.  * Revision 1.1  96/01/04  11:37:22  11:37:22  mjames (Mike James)
  251.  * Initial revision
  252.  *
  253. */
  254. #include <stdio.h>
  255. #include <string.h>
  256. #include <stdlib.h>
  257. #include <ctype.h>
  258. #include <sys/types.h>
  259. #include <regex.h>
  260.  
  261.  
  262. #include "vertcl_main.h"
  263. #include "expression.h"
  264. #include "generic.h"
  265. #include "database.h"
  266. #include "lx_support.h"
  267. #include "cmdparse.h"
  268. #include "cmdlog.h"
  269. #include "acf_yacc.h"
  270. #include "chck_names.h"
  271. #include "sorting.h"
  272. #include "version.h"
  273.  
  274. #ident  "@(#)$Header: c:\\cygwin\\cvsroot/Vert03/vertlib/database.c,v 1.1.1.1 2003/11/04 23:34:57 mjames Exp $"
  275.  
  276.  
  277.  
  278. vhdl_t * default_vhdl_datatype;
  279. vhdl_t * default_vhdl_bustype;
  280.  
  281. /* string constants used around the place*/
  282.  
  283. char   nullstr[]        =   "";
  284.  
  285.  
  286. /* database pointers */
  287. __declspec (dllexport) socket_t * socket_head = NULL;
  288.  
  289. __declspec (dllexport)socket_t * template_head = NULL;
  290.  
  291.  
  292.  
  293. net_t    * routed_list   = NULL;
  294. net_t    * named_list   = NULL;
  295. net_t    * named_tail   = NULL; /* as routed nets are moved to the named list */
  296. net_t    * unrouted_list = NULL;
  297.  
  298.  
  299. /* these are ident counters. The first counts net identifiers */
  300. static int n_idents = 1; /* net identifiers */
  301. static int s_idents = 1; /* socket identifiers */
  302. static int i_idents = 1; /* pin identifiers */
  303.  
  304. /* compares two strings case insensitive with a pointer sanity check */
  305.  
  306. int strcmp2(char * s, char * t)
  307. {
  308.   if(!s || !t)
  309.     return(-1);
  310.   for(;tolower(*s) == tolower(*t);s++,t++)
  311.     if(*s==0)
  312.       return(0);
  313.   return(tolower(*s) - tolower(*t));
  314. }
  315.  
  316. /* allocates a space for a string */
  317.  
  318.  
  319. #if !defined allocstr
  320. /* we now use strdup.... */
  321. char * allocstr(char * s)
  322. {
  323.   char * t;
  324.   /* added a check for allocating null string
  325.    *  (its strlen that bombs in CygWin) */
  326.   if (!s) return NULL;
  327.  
  328.   t=malloc(strlen(s)+1);
  329.   strcpy(t,s);
  330.   return t;
  331. }
  332. #endif
  333.  
  334. /* allocates a space for a string and a suffix dependent on property */
  335.  
  336. #if defined USE_ALLOCSTR_PROP
  337. static char * allocstr_prop(char * s,property_t prop)
  338. {
  339.   char * t;
  340.   switch (prop) {
  341.     case Ident:
  342.     case Type:
  343.     case Name:
  344.     case Value:  t=strdup(s);
  345.                  break;
  346.   }
  347.   return t;
  348. }
  349. #endif
  350.  
  351. /* this is a check on a socket ident - if absent, generates one  */
  352.  
  353. __declspec (dllexport) void ensure_socket_ident(socket_t * chip)
  354. {
  355.   char id[10];
  356.   if (chip->identifier == nullstr)
  357.   {
  358.     sprintf(id,"ID%d",s_idents++);
  359.     set_socket(chip,Ident,id);
  360.   };
  361. }
  362.  
  363.  
  364. /* set a socket property */
  365. __declspec (dllexport)void set_socket(socket_t * chip,property_t prop,char * str)
  366. {
  367.   char * s;
  368.   s = strdup(str);
  369.  
  370. /*   printf("(Set socket prop%d to %s)",prop,s); */
  371.   switch(prop)
  372.   {
  373.     case Ident:  chip->identifier = s; break;
  374.     case Type:   chip->type       = s; break;
  375.     case Name:   chip->name       = s; break;
  376.     case Value:  chip->value      = s; break;
  377.     default: break;
  378.   };
  379. }
  380.  
  381. /* find a socket property */
  382. __declspec (dllexport) socket_t * find_socket(property_t prop,
  383.                        char * str,
  384.                        int srchonly,
  385.                        socket_t ** headref)
  386. {
  387.   socket_t * c=*headref, *p=NULL;
  388.   int f=0;
  389. /* printf("-- Socket %s : prop %d pointer=%p\n",str,prop,c); */
  390.  
  391.   while(c)
  392.     {
  393.     switch(prop)
  394.       {
  395.       case Ident: f=strcmp2(c->identifier,str)==0;/*puts(c->identifier); */ break;
  396.       case Type:  f=strcmp2(c->type,str)==0;       break;
  397.       case Name:  f=strcmp2(c->name,str)==0; /*puts(c->name);*/      break;
  398.       case Value: f=strcmp2(c->value,str)==0;      break;
  399.       default : break; /* never find if wrong field specified */
  400.       };
  401.     if(f) break;
  402.     p=c;
  403.     c=c->next;
  404.     };
  405.  
  406.   if(srchonly || f )
  407.     return(c);
  408.  
  409.   c=calloc(1,sizeof(socket_t)); /* all pointers are set to be null */
  410.  
  411.   c->identifier = nullstr;
  412.   c->type       = nullstr;
  413.   c->name       = nullstr;
  414.   c->value      = nullstr;
  415.  
  416.   set_socket(c,prop,allocstr(str));
  417.  
  418.   /* link in otherwise */
  419.   if(p)
  420.     p->next = c;
  421.   if (!(*headref))
  422.     *headref = c;
  423.   return c;
  424. }
  425.  
  426. /* matches s into a table of n strings r[], default value is d */
  427. int str_to_int(char * s,char * r[],int n,int d)
  428. {
  429.   int i;
  430.   for(i=0;i<n;i++)
  431.     if(strcmp2(s,r[i])==0)
  432.     {
  433.       d=i;
  434.       break;
  435.     };
  436.   return d;
  437. }
  438.  
  439.  
  440.  
  441. char * decode_how_routed[]= {
  442.   "FREE_NAME",
  443.   "MATCHED_NAME",
  444.   "USED_WIRES",
  445.   "USED_FIXED_WIRES",
  446.   "USED_EXACT_WIRES",
  447.   "CREATED_NET",
  448.   "CREATED_JUMPER",
  449.   "FIXED_PINS",
  450.   "NOT_ROUTABLE",
  451.   "NOT_ROUTABLE_L", /* additions V16.5 onward */
  452.   "NOT_ROUTABLE_H"
  453. };
  454.  
  455. /* set a net property */
  456. __declspec (dllexport) void set_net(net_t * net,property_t prop,char * str)
  457. {
  458.   char * s;
  459.   s = strdup(str);
  460.   switch(prop)
  461.   {
  462.     case Ident:     net->identifier = s; break;
  463.     case Name:      net->name       = s; break;
  464. /*
  465.     case Datatype:  net->datatype   = s; break;
  466. */
  467.     case How_Routed:
  468.            net->how_routed  = (HowRouted_t)str_to_int(str,
  469.                                                       decode_how_routed,
  470.                                                       sizeof(decode_how_routed)/sizeof(char *),
  471.                                                       0);
  472.        break;
  473.     default: break;
  474.    };
  475. }
  476.  
  477.  
  478. /* find a net by property, in a list pointed to by a pointer referred to
  479.    by net_head  */
  480. __declspec (dllexport) net_t * find_net(net_t ** net_head,property_t prop,char * str,int srchonly )
  481. {
  482.   net_t * c, *p;
  483.   int f=0;
  484.   c= *net_head;
  485.   p=NULL;
  486.   while(c)
  487.     {
  488.     switch(prop)
  489.       {
  490.       case Ident: f=strcmp2(c->identifier,str)==0; break;
  491.       case Name:  f=strcmp2(c->name,str)==0;       break;
  492.       default: break;
  493.       };
  494.     if(f)
  495.       break;
  496.     p=c;
  497.     c=c->next;
  498.     };
  499.   if(srchonly || f)
  500.     return(c);
  501.  
  502.   c=calloc(1,sizeof(net_t)); /* all pointers are set to be null */
  503.   c->name       = nullstr;
  504.   c->identifier = nullstr;
  505.   c->list_ref   = net_head; /* record which list this net is a member of */
  506.  
  507.   c->nodecount  = 0;    /* calloc does this :  put here for readability : Oct 2000 */
  508.  
  509.   c->type_defined= 0;  
  510.   set_net(c,prop,str);
  511.  
  512.   c->list_ref = net_head; /* which list does this net begin life on */
  513.  
  514.   /* link at end of list otherwise */
  515.   if(p)
  516.     p->next = c;
  517.   c->prev = p;  /* and refer back to it */
  518.   if (!(*net_head))
  519.     *net_head = c;
  520.  
  521.   return c;
  522. }
  523.  
  524. /* set a node property */
  525. __declspec (dllexport) void set_node(node_t * node,property_t prop,char * str)
  526. {
  527.   char * s;
  528.   s = strdup(str);
  529.   switch(prop)
  530.   {
  531.     case Ident:     node->identifier = s; break;
  532.     case Name:      node->name       = s; break;
  533. /*
  534.     case Datatype:  node->datatype    = s; break;
  535. */
  536.     default: break;
  537.    };
  538. }
  539.  
  540.  
  541.  
  542. /* locate a node on a chip by a property */
  543. __declspec (dllexport) node_t * find_node(socket_t * socket,
  544.                    property_t prop,
  545.                    char * str,
  546.                    int srchonly)
  547. {
  548.   node_t * c, *p;
  549.   int f=0;
  550.  
  551. /* catch null pointer reference 23 May 2001 */
  552.   if (!socket)
  553.     return NULL;
  554.  
  555.   c=socket->nodes;
  556.  
  557.   p=NULL;
  558.   while(c)
  559.     {
  560.     switch(prop)
  561.       {
  562.  
  563.       case Ident:     f=strcmp2(c->identifier,str)==0; break;
  564.       case Name:      f=strcmp2(c->name,str)==0;       break;
  565. /*      case Datatype:  f=strcmp2(c->datatype,str)==0;       break; */
  566.       default:  break;
  567.       };
  568.     if(f)
  569.       break;
  570.     p=c;
  571.     c=c->sktnext;
  572.     };
  573.   if(srchonly || f)
  574.     return(c);
  575.  
  576.   c=calloc(1,sizeof(node_t)); /* all pointers are set to be null */
  577.   c->name       = nullstr;
  578.   c->identifier = nullstr;
  579.   c->socket     = socket;
  580.  
  581.   set_node(c,prop,str);
  582.   /* link at end of list otherwise */
  583.   if(p)
  584.     p->sktnext = c;
  585.  
  586.   if(!socket->nodes)
  587.     socket->nodes = c;
  588.  
  589.   socket->lastnode = c;
  590.   return c;
  591. }
  592.  
  593. /* this connects the node to the list of node references on the net and
  594.    connects the net to the list of net references on the node */
  595.  
  596. __declspec (dllexport) void connect_node_net( char * orig_name,
  597.                        node_t * cnode,
  598.                        net_t * cnet,
  599.                        pindir_t pintype,
  600.                        vhdl_t * vhdl,
  601.                        vhdl_t * orig_vhdl,
  602.                        expression_t * lhs_expr)
  603.   {
  604.   noderef_t * noderef;
  605.   cnet->nodecount++; /* one more node on this net */
  606.  
  607.   cnode->net = cnet; /* refer back to net this node is on */
  608.   cnode->refcount++; /* and count references */
  609.  
  610.   noderef = calloc(1,sizeof(noderef_t));
  611.  
  612.   noderef->net = cnet; /* this node reference refers back to its parent net */
  613.  
  614.   noderef->pindir  = pintype; /* the reference has the pin direction _wanted_ */
  615.  
  616.   noderef->orig_name   = orig_name; /* copy any alias over */
  617.  
  618. /* remeved reference to datatype */
  619.   noderef->vhdltype      = vhdl;
  620.  
  621.   noderef->orig_vhdltype = orig_vhdl;
  622.  
  623.   noderef->base_noderef = noderef; /* its original reference is itself */
  624.  
  625.   noderef->lhs_expr     = lhs_expr;
  626.  
  627. /* link node  reference to the net */
  628.   noderef->next = cnet->nodes;
  629.   cnet->nodes = noderef; /* place reference on head of list */
  630.   noderef->node = cnode;
  631.  
  632.   }
  633.  
  634.  
  635.  
  636. /* disconnect a node from the netlist */
  637. /* this intends to remove chip node from net in the routed list. If anyone has made a reference to the node
  638.    in a manner which results in this node reappearing then there will be a problem as it will
  639.    reappear (some route algorithms eg. create will do this) */
  640.  
  641. __declspec (dllexport) void disconnect_node(socket_t * chip, node_t * node)
  642.   {
  643.   noderef_t * ref, * last_ref;
  644.   /* locate the net on the routed or named list */
  645.   if(node->net && (node->net->list_ref== &routed_list || node->net->list_ref== &named_list))
  646.     {
  647.     net_t * net;
  648.     net = node->net;
  649.     ref = net->nodes;
  650.     last_ref = NULL;
  651.     /* locate the reference made */
  652.     while(ref)
  653.       {
  654.       if (ref->node == node)
  655.         break;
  656.       last_ref = ref;
  657.       ref = ref->next;
  658.       }
  659.     /* reference is located. Remove from list of node references,
  660.        also patch up list head if needed */
  661.     if(ref)
  662.       {
  663.       if(last_ref == NULL)
  664.         {
  665.         net->nodes = ref->next;
  666.         }
  667.       else
  668.         {
  669.         last_ref->next = ref->next;
  670.         }
  671.       free(ref);      
  672.       node->net = NULL; /* disconnect the ned from the node */
  673.       node->refcount = node->refcount ? node->refcount--: 0 ;
  674.      
  675.       }
  676.     }
  677.   }
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684. __declspec (dllexport) void define_pin(net_t ** net_head,
  685.                 socket_t * chip,
  686.                 char * i_name,
  687.                 int pin_type,
  688.                 int pin_group,
  689.                 char * i_identifier,
  690.                 vhdl_t * vhdl,
  691.                 expression_t * lhs_expr)
  692. {
  693.   unrouted_ref_t * ref, *ptr;
  694.  
  695.   int null_name;
  696.   char name[MAXIDLEN];
  697.   char identifier[MAXIDLEN];
  698.  
  699.   /* actions here are :
  700.   1: find a new node;
  701.   2: attach a reference to it to the socket pin list;
  702.   3: find the net it is joined to by name;
  703.   */
  704.  
  705.   null_name = ISNULLSTR(i_name);
  706.  
  707.  
  708.   /* if the name is not given, then dont create a net for it as it
  709.      is a waste of time */
  710.   if(null_name)
  711.     /* count another ident for posisble use */
  712.     sprintf(name,"NE%d",n_idents++);
  713.   else
  714.     strcpy(name,i_name);
  715.  
  716.   if(ISNULLSTR(i_identifier))
  717.     /* count another ident for posisble use */
  718.     sprintf(identifier,"ID%d",i_idents++);
  719.   else
  720.     strcpy(identifier,i_identifier);
  721.  
  722. /*   printf("-- Joining name %s to pin %s\n",name,identifier );
  723. */
  724.  
  725.  
  726.   /* at this stage, simply create a potential reference */
  727.  
  728.  
  729.   ref = calloc(1,sizeof(unrouted_ref_t));
  730.  
  731.  
  732.   ref->pindir  = pin_type;        /* the reference has the pin direction _wanted_ */
  733.   ref->pin_group  = pin_group;
  734. /* removed reference to datatype */
  735.  
  736.   ref->vhdltype       = copy_vhdl(vhdl,chip);
  737.   ref->orig_vhdltype  = NULL;
  738.   ref->identifier     = allocstr(identifier);
  739.   ref->name           = allocstr(name);
  740.   ref->orig_name      = NULL;
  741.   ref->listref        = net_head;  /* identify the list context */
  742.   ref->lhs_expr       = lhs_expr;  
  743.   ref->next = NULL;
  744.   if(!chip->unrouted_refs)
  745.     chip->unrouted_refs = ref;
  746.   else {
  747.     ptr = chip->unrouted_refs;
  748.     while(ptr->next)
  749.       ptr=ptr->next;
  750.     ptr->next = ref;
  751.     }  
  752.  
  753.   /* splice the unrouted reference on */
  754.   ref->next           = NULL;
  755.  
  756.  
  757. }
  758.  
  759.  
  760. /* this function clears the name fields on identified nets */
  761. static void del_list_net_names(net_t * list,char * template )
  762.   {
  763.   int rc,found;
  764.   char * pattern;
  765.   /* compile regular expression */
  766.   vert_regex_t * preg;
  767.  
  768.  
  769.   if (template)
  770.     {
  771.     pattern = template;
  772.     }
  773.   else
  774.     {
  775.     pattern = ".*";
  776.     }
  777.  
  778.   rc = vert_regcomp(&preg,pattern);
  779.  
  780.   if (rc != 0 )
  781.     {
  782.     char errbuff[100];
  783.     regerror(rc,preg->preg,errbuff,100);
  784.     Log(LOG_ERROR,"-- Problem (rc=%d) %s with '%s' as regular expression\n",rc,errbuff,pattern);
  785.    
  786.     return /*TCL_ERROR*/;
  787.     }
  788.  
  789.  
  790.   Log(LOG_GENERAL,"-- Beginning clearing name fields : net ID prefix '%s' --\n",
  791.       template?template:"[ALL ID's]");
  792.   while(list) {
  793.     found  = regexec(preg->preg,list->identifier,0,preg->regpatt,0);
  794.     if(!found) {
  795.       Log(LOG_GENERAL,"-- Cleared name field for net ID '%s'\n",list->identifier);
  796.       list->name = nullstr;
  797.       }
  798.     list = list->next;
  799.     }
  800.   Log(LOG_GENERAL,"-- Finished clearing name fields --\n");
  801.   vert_regfree(&preg);
  802.   }
  803.  
  804. __declspec (dllexport)void del_net_names(char * template )
  805.   {
  806.   del_list_net_names(routed_list,template );
  807.   }
  808.  
  809. /* added 8 March 2000 for PC support */
  810.  
  811. __declspec (dllexport) void ensure_env_var(char * name, char * defval) {
  812.   generic_info_t gen[1];
  813.   if (get_generic_value(&global_generics, name,gen) != IS_STRING) {
  814.     char sbuff [MAXIDLEN];
  815.     gen->name     = name;
  816.     gen->typename = "env_string";
  817. /* cannot use $(1) type command line variables as
  818.  *they are not passed here :  argc = 0 , argv = NULL*/
  819.     expand_string(defval , sbuff,0 , NULL);
  820.     gen->expr     = compile_string(sbuff);
  821.     gen->g_type   = IS_ENV_VAL;
  822.     gen->g_class  = DEFAULT;
  823.  
  824.     set_generic_value(&global_generics,gen );
  825.     };
  826.   }
  827.  
  828. /* initialise default information used around the design database */
  829. __declspec (dllexport) void InitialiseData(void) {
  830.   generic_info_t gen[1];
  831.   InitialiseVersionStrings();  
  832.  
  833.   if (!default_vhdl_datatype)
  834.     default_vhdl_datatype= calloc(1,sizeof(vhdl_t));
  835.   if (!default_vhdl_bustype)
  836.     default_vhdl_bustype = calloc(1,sizeof(vhdl_t));
  837.  
  838.   /* if we are using VHDL then look at the VHDL bus formatting tail*/
  839.   if (get_generic_value(&global_generics, "vhdl_bit_type",gen) == IS_STRING) {
  840.     default_vhdl_datatype->basetype = strdup( gen->expr->left.s );
  841.     }
  842.   else
  843.     default_vhdl_datatype->basetype = "std_logic";
  844.    
  845.   /* if we are using VHDL then look at the VHDL bus formatting tail*/
  846.   if (get_generic_value(&global_generics, "vhdl_bus_type",gen) == IS_STRING) {
  847.     default_vhdl_bustype->basetype = strdup( gen->expr->left.s);
  848.     }
  849.   else
  850.     default_vhdl_bustype->basetype = "std_logic_vector";
  851.  
  852.   default_vhdl_bustype->expr     = compile_expression(TO,compile_constant(0),compile_constant(0));
  853.   default_vhdl_bustype->is_vector=1;  /* is this port a vector */
  854.   default_vhdl_bustype->is_downto=1;  /* is the vector X TO Y or X DOWNTO Y  */
  855.  
  856.  /* look up VERTICAL_INIT and give it a default value if unknown */  
  857.   ensure_env_var("VERTICAL_INIT",VERTICAL_INI_PATH);
  858.  
  859.   ensure_env_var("VERTICAL_PATH",VERTICAL_PATH);
  860.  
  861.  
  862.  }  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.  
  869. __declspec (dllexport) char * decode_which_list(net_t ** list_head) {
  870.   if(list_head == NULL)           return "No List";
  871.   if(list_head == &routed_list)   return "routed list";
  872.   if(list_head == &named_list)    return "named list";
  873.   if(list_head == &unrouted_list) return "unrouted list";
  874.   return "ERROR : unknown";
  875.   }
  876.  
  877.  
  878.  
  879.  
  880.