source: vis_dev/vis-2.3/src/hrc/hrcModify.c @ 99

Last change on this file since 99 was 14, checked in by cecile, 13 years ago

vis2.3

File size: 9.9 KB
Line 
1/**CFile***********************************************************************
2
3  FileName    [hrcModify.c]
4
5  PackageName [hrc]
6
7  Synopsis    [This files provides the basic functions concerned with
8               modifying the hierarchy. This ]
9
10  Description []
11
12  SeeAlso     []
13
14  Author      [Shaz Qadeer]
15
16  Copyright   [Copyright (c) 1994-1996 The Regents of the Univ. of California.
17  All rights reserved.
18
19  Permission is hereby granted, without written agreement and without license
20  or royalty fees, to use, copy, modify, and distribute this software and its
21  documentation for any purpose, provided that the above copyright notice and
22  the following two paragraphs appear in all copies of this software.
23
24  IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
25  DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
26  OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
27  CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29  THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
30  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN
32  "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE
33  MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.]
34
35******************************************************************************/
36
37#include "hrcInt.h"
38
39static char rcsid[] UNUSED = "$Id: hrcModify.c,v 1.4 2005/04/16 04:23:47 fabio Exp $";
40
41/*---------------------------------------------------------------------------*/
42/* Constant declarations                                                     */
43/*---------------------------------------------------------------------------*/
44
45
46/*---------------------------------------------------------------------------*/
47/* Stucture declarations                                                     */
48/*---------------------------------------------------------------------------*/
49
50
51/*---------------------------------------------------------------------------*/
52/* Type declarations                                                         */
53/*---------------------------------------------------------------------------*/
54
55
56/*---------------------------------------------------------------------------*/
57/* Variable declarations                                                     */
58/*---------------------------------------------------------------------------*/
59
60
61/*---------------------------------------------------------------------------*/
62/* Macro declarations                                                        */
63/*---------------------------------------------------------------------------*/
64
65
66/**AutomaticStart*************************************************************/
67
68/*---------------------------------------------------------------------------*/
69/* Static function prototypes                                                */
70/*---------------------------------------------------------------------------*/
71
72
73/**AutomaticEnd***************************************************************/
74
75
76/*---------------------------------------------------------------------------*/
77/* Definition of exported functions                                          */
78/*---------------------------------------------------------------------------*/
79
80
81
82/**Function********************************************************************
83
84  Synopsis    [Adds a subckt to a model.]
85
86  Description [If a subckt with the same instanceName is already present, the
87               function returns FALSE. Otherwise, a new sub-circuit is
88               allocated and initialized and TRUE is returned. Note that
89               it is the user's responsibility to free the string
90               instanceName. actualInputVars and actualOutputVars are
91               pointer-copied.]
92
93  SideEffects []
94
95  SeeAlso     []
96
97******************************************************************************/
98boolean
99Hrc_ModelAddSubckt(
100  Hrc_Model_t *callerModel,
101  Hrc_Model_t *calleeModel,
102  char *instanceName,
103  array_t *actualInputVars,
104  array_t *actualOutputVars)
105{
106  Hrc_Subckt_t *subckt; 
107 
108  if(!st_is_member(callerModel->subcktTable, instanceName)) {
109    subckt = ALLOC(Hrc_Subckt_t, 1);     
110    subckt->model = calleeModel;
111    subckt->instanceName = util_strsav(instanceName);
112    subckt->actualInputVars = actualInputVars;
113    subckt->actualOutputVars = actualOutputVars;
114    st_insert(callerModel->subcktTable, subckt->instanceName, (char *) subckt);
115    return TRUE;
116  }
117  else {
118    return FALSE;
119  }
120}
121
122/**Function********************************************************************
123
124  Synopsis    [Adds a name table to a model.]
125
126  Description [The function adds a name table to the master node of a model.]
127
128  SideEffects []
129
130  SeeAlso     []
131
132******************************************************************************/
133void
134Hrc_ModelAddNameTable(
135  Hrc_Model_t *model,
136  Tbl_Table_t *table)
137{
138  array_insert_last(Tbl_Table_t *, model->masterNode->nameTables, table);
139}
140
141/**Function********************************************************************
142
143  Synopsis    [Adds a child node to a node.]
144
145  Description [The function checks if a child with the same instance name
146               is already present in parent. If it is present, FALSE is
147               returned. Otherwise, the child is added and TRUE is returned.
148               Note that before using this function, child should have
149               created using Hrc_NodeAlloc().]
150
151  SideEffects []
152
153  SeeAlso     []
154
155******************************************************************************/
156boolean
157Hrc_NodeAddChild(
158  Hrc_Node_t *parent,
159  Hrc_Node_t *child,
160  array_t *actualInputs,
161  array_t *actualOutputs)
162{
163  if(!st_is_member(parent->childTable, child->instanceName)) {
164    st_insert(parent->childTable, child->instanceName, (char *) child);
165    child->parentNode = parent;
166    child->actualInputs = actualInputs;
167    child->actualOutputs = actualOutputs;
168    return TRUE;
169  }
170  else {
171    return FALSE;
172  }
173}
174
175/**Function********************************************************************
176
177  Synopsis    [Adds a latch to a node.]
178
179  Description [The function adds a latch to a node if the latch is not
180               present already and returns TRUE. Otherwise, it returns FALSE.]
181
182  SideEffects []
183
184  SeeAlso     []
185
186******************************************************************************/
187boolean
188Hrc_NodeAddLatch(
189  Hrc_Node_t *node,
190  Hrc_Latch_t *latch)
191{
192  char *latchOutputName = Var_VariableReadName(latch->latchOutput);
193 
194  if(!st_is_member(node->latchTable, latchOutputName)) {
195    st_insert(node->latchTable, latchOutputName, (char *) latch);
196    return TRUE;
197  }
198  else {
199    return FALSE;
200  }
201}
202
203/**Function********************************************************************
204
205  Synopsis    [Adds a variable to a node.]
206 
207  Description [The function adds a variable to a node if the variable is not
208               present already and returns TRUE. Otherwise, it returns FALSE.]
209
210  SideEffects []
211
212  SeeAlso     []
213
214******************************************************************************/
215boolean
216Hrc_NodeAddVariable(
217  Hrc_Node_t *node,
218  Var_Variable_t *var)
219{
220  char *varName = Var_VariableReadName(var);
221 
222  if(!st_is_member(node->varTable, varName)) {
223    st_insert(node->varTable, varName, (char *) var);
224    return TRUE;
225  }
226  else {
227    return FALSE;
228  }
229}
230
231/**Function********************************************************************
232 
233  Synopsis    [Deletes a variable from a node.]
234
235  Description [If the variable is present in node it is deleted and TRUE is
236               returned. Otherwise, nothing is done and FALSE is returned.
237               Note that this function should only be used for deleting an
238               internal variable of a node.]
239
240  SideEffects []
241
242  SeeAlso     []
243
244******************************************************************************/
245boolean
246Hrc_NodeDeleteVariable(
247  Hrc_Node_t *node,
248  Var_Variable_t *var)
249{
250  char *varName = Var_VariableReadName(var);
251 
252  return st_delete(node->varTable, &varName, &var);
253}
254
255/**Function********************************************************************
256
257  Synopsis    [Deletes a latch from a node.]
258
259  Description [If the latch is present in node it is deleted and TRUE is
260               returned. Otherwise, nothing is done and FALSE is returned.]
261
262  SideEffects []
263
264  SeeAlso     []
265
266******************************************************************************/
267boolean
268Hrc_NodeDeleteLatch(
269  Hrc_Node_t *node,
270  Hrc_Latch_t *latch)
271{
272  char *latchOutputName = Var_VariableReadName(latch->latchOutput);
273 
274  return st_delete(node->latchTable, &latchOutputName, &latch);
275}
276
277/*---------------------------------------------------------------------------*/
278/* Definition of internal functions                                          */
279/*---------------------------------------------------------------------------*/
280/**Function********************************************************************
281
282  Synopsis    [Deletes a child from a node.]
283
284  Description [If a child of the name childName exists in node, it is deleted
285               from the childTable of node and a pointer to this child is
286               returned. Otherwise, NULL is returned.]
287
288  SideEffects []
289
290  SeeAlso     [Hrc_TreeReplace()]
291
292******************************************************************************/
293Hrc_Node_t *
294HrcNodeDeleteChild(
295  Hrc_Node_t *node,
296  char *childName)
297{
298  Hrc_Node_t *childNode;
299 
300  if(st_delete(node->childTable, &childName, &childNode)) {
301    return childNode;
302  }
303  else {
304    return NIL(Hrc_Node_t);
305  }
306}
307
308
309/*---------------------------------------------------------------------------*/
310/* Definition of static functions                                            */
311/*---------------------------------------------------------------------------*/
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
Note: See TracBrowser for help on using the repository browser.