Merge branch 'master' into xcircuit-3.10
[xcircuit.git] / asg / parse_support.c
blob728e0f722601b3cb512f77aa483cdebe9989f118
1 /************************************************************
2 **
3 ** COPYRIGHT (C) 2004 GANNON UNIVERSITY
4 ** ALL RIGHTS RESERVED
5 **
6 ** This software is distributed on an as-is basis
7 ** with no warranty implied or intended. No author
8 ** or distributor takes responsibility to anyone
9 ** regarding its use of or suitability.
11 ** The software may be distributed and modified
12 ** freely for academic and other non-commercial
13 ** use but may NOT be utilized or included in whole
14 ** or part within any commercial product.
16 ** This copyright notice must remain on all copies
17 ** and modified versions of this software.
19 ************************************************************/
22 /* file parse_support.c */
23 /* ------------------------------------------------------------------------
24 * Routines for integrating ASG into a language parser, such as the
25 * hpice parser in XCircuit 3.2.7+.
26 * ------------------------------------------------------------------------
28 #include <stdio.h>
29 #include <stdarg.h>
30 #include <ctype.h>
31 #include <string.h>
32 #include "network.h"
34 /*---------------------------------------------------------------
35 * Global Variable Definitions
36 *---------------------------------------------------------------
39 module *curobj_module;
41 /***********************************************************************************
42 Add2TermModule - This method is used to add a new module found in the parse tree of a language. E.g., this can be used in HSPICE
43 parser to add a module.
46 **************************************************************************************/
48 void Add2TermModule( name, type, inNode, outNode )
49 char* name; // Parser-supplied module name (e.g., CAP32)
50 char* type; // Parser-supplied identification type (e.g., CAPACITOR)
51 char* inNode; // Net name for input net
52 char* outNode; // Net name for output net
54 net* pNet;
56 //Create a new Module( Capacitor or Resistor or Inductor or Buffer, Inverter gate etc)
57 curobj_module = newobject(name, type);
59 //Add Inputports
60 pNet = get_net(inNode);
62 //If Input Node does not exist in the global database
63 if( pNet == NULL )
65 newnode(inNode);
67 addin(inNode, 0, 1);
69 //Add output ports
70 pNet = get_net(outNode);
72 //If output Node does not exist in the global database
73 if( pNet == NULL )
75 newnode(outNode);
77 addout(outNode, 0, 1);
80 /***********************************************************************************
81 Add3TermModule - This method is used to add a new module. This can be used in HSPICE
82 parser to add a module.
85 **************************************************************************************/
87 void Add3TermModule( name, type, inNode, outNode, inoutNode)
88 char* name; // Parser-supplied module name (e.g., CAP32)
89 char* type; // Parser-supplied identification type (e.g., CAPACITOR)
90 char* inNode; // Net name for input (left) net
91 char* outNode; // Net name for output (right) net
92 char* inoutNode; // Net name for inout (top) net
94 net* pNet;
96 //Create a new Module( Capacitor or Resistor or Inductor or Buffer, Inverter gate etc)
97 curobj_module = newobject(name, type);
99 //Add Inputports
100 pNet = get_net(inNode);
102 //If Input Node does not exist in the global database
103 if( pNet == NULL )
105 newnode(inNode);
107 addin(inNode, 0, 1);
109 //Add output ports
110 pNet = get_net(outNode);
112 //If output Node does not exist in the global database
113 if( pNet == NULL )
115 newnode(outNode);
117 addout(outNode, 0, 1);
119 //Add inout ports
120 pNet = get_net(inoutNode);
122 //If inout Node does not exist in the global database
123 if( pNet == NULL )
125 newnode(inoutNode);
127 addinout(inoutNode, 0, 1);
130 /*----------------------------------------------------------------------*/
131 /* AddNTermModule --- */
132 /* Add a module of N terminals to the database */
133 /* */
134 /* name = Parser-supplied module name (e.g., CAP32) */
135 /* type = Parser-supplied identification type (e.g., CAPACITOR) */
136 /* N = Number of nodes, followed by list of node names. */
137 /* followed by pairs of char * types declaring the name of the pin */
138 /* (expected in the xcircuit object) followed by the name of the net. */
139 /*----------------------------------------------------------------------*/
141 void AddNTermModule(char *name, char *type, int N, ...)
143 va_list args;
144 int i;
145 net *pNet;
146 char *pinName;
147 char *netName;
148 objectptr pobj;
150 // Create a new Module (Capacitor, Resistor, Inductor or Buffer, Inverter gate etc)
151 curobj_module = newobject(name, type);
153 // Get the corresponding XCircuit object and get the object dimensions
154 pobj = NameToObject(type, NULL, FALSE);
155 if (pobj != NULL) {
156 curobj_module->x_size = pobj->bbox.width;
157 curobj_module->y_size = pobj->bbox.height;
159 else {
160 error("AddNTermModule: No such object", type);
163 va_start(args, N);
165 for (i = 0; i < N; i++) {
166 // Add port
167 pinName = va_arg(args, char *);
168 netName = va_arg(args, char *);
169 pNet = get_net(netName);
171 // If Input Node does not exist in the global database
172 if (pNet == NULL) {
173 newnode(netName);
175 add_xc_term(type, pinName, netName, i, N);
177 va_end(args);
180 /*--------------------------------------------------------------*/
181 /* Handle modules with an abitrary number of terminals in the */
182 /* following way: AddNTermModule() is called with N = 0 to */
183 /* create curobj_module (which is global). Then, for each pin, */
184 /* the routine AddModuleTerm() is called to associate a net */
185 /* with each pin, in turn. */
186 /*--------------------------------------------------------------*/
188 /*--------------------------------------------------------------*/
189 /* For the moment, pins will be named "1", "2", etc. To do: */
190 /* look up the object having a name matching "type". Confirm */
191 /* a match in the number of pins N, and then pick up the pin */
192 /* names from the object itself. Presumably this is done by */
193 /* assuming that the object has an info label "spice:..." and */
194 /* using that. It is the responsibility of the user to ensure */
195 /* that the library used to represent primitives in the spice */
196 /* deck contains the correct number and order of pins. */
197 /*--------------------------------------------------------------*/
199 void AddModuleTerm(char *type, char *netName, int portnum, int allports)
201 net *pNet;
203 pNet = get_net(netName);
205 // If Input Node does not exist in the global database
206 if (pNet == NULL) {
207 newnode(netName);
209 add_xc_term(type, NULL, netName, portnum, allports);
212 /*---------------------------------------------------------------
213 * END OF FILE
214 *---------------------------------------------------------------