ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
mtrBasic.c
Go to the documentation of this file.
1
62
63#include "misc/util/util_hack.h"
64#include "mtrInt.h"
65
67
68/*---------------------------------------------------------------------------*/
69/* Constant declarations */
70/*---------------------------------------------------------------------------*/
71
72/*---------------------------------------------------------------------------*/
73/* Stucture declarations */
74/*---------------------------------------------------------------------------*/
75
76/*---------------------------------------------------------------------------*/
77/* Type declarations */
78/*---------------------------------------------------------------------------*/
79
80/*---------------------------------------------------------------------------*/
81/* Variable declarations */
82/*---------------------------------------------------------------------------*/
83
84#ifndef lint
85static char rcsid[] MTR_UNUSED = "$Id: mtrBasic.c,v 1.13 2009/02/20 02:03:47 fabio Exp $";
86#endif
87
88/*---------------------------------------------------------------------------*/
89/* Macro declarations */
90/*---------------------------------------------------------------------------*/
91
93
94/*---------------------------------------------------------------------------*/
95/* Static function prototypes */
96/*---------------------------------------------------------------------------*/
97
98
100
101
102/*---------------------------------------------------------------------------*/
103/* Definition of exported functions */
104/*---------------------------------------------------------------------------*/
105
117MtrNode *
119{
120 MtrNode *node;
121
122 node = ABC_ALLOC(MtrNode,1);
123 return node;
124
125} /* Mtr_AllocNode */
126
127
139void
141 MtrNode * node /* node to be deallocated */)
142{
143 ABC_FREE(node);
144 return;
145
146} /* end of Mtr_DeallocNode */
147
148
160MtrNode *
162{
163 MtrNode *node;
164
165 node = Mtr_AllocNode();
166 if (node == NULL) return(NULL);
167
168 node->parent = node->child = node->elder = node->younger = NULL;
169 node->flags = 0;
170
171 return(node);
172
173} /* end of Mtr_InitTree */
174
175
187void
189 MtrNode * node)
190{
191 if (node == NULL) return;
192 if (! MTR_TEST(node,MTR_TERMINAL)) Mtr_FreeTree(node->child);
193 Mtr_FreeTree(node->younger);
194 Mtr_DeallocNode(node);
195 return;
196
197} /* end of Mtr_FreeTree */
198
199
214MtrNode *
216 MtrNode * node,
217 int expansion)
218{
219 MtrNode *copy;
220
221 if (node == NULL) return(NULL);
222 if (expansion < 1) return(NULL);
223 copy = Mtr_AllocNode();
224 if (copy == NULL) return(NULL);
225 copy->parent = copy->elder = copy->child = copy->younger = NULL;
226 if (node->child != NULL) {
227 copy->child = Mtr_CopyTree(node->child, expansion);
228 if (copy->child == NULL) {
229 Mtr_DeallocNode(copy);
230 return(NULL);
231 }
232 }
233 if (node->younger != NULL) {
234 copy->younger = Mtr_CopyTree(node->younger, expansion);
235 if (copy->younger == NULL) {
236 Mtr_FreeTree(copy);
237 return(NULL);
238 }
239 }
240 copy->flags = node->flags;
241 copy->low = node->low * expansion;
242 copy->size = node->size * expansion;
243 copy->index = node->index * expansion;
244 if (copy->younger) copy->younger->elder = copy;
245 if (copy->child) {
246 MtrNode *auxnode = copy->child;
247 while (auxnode != NULL) {
248 auxnode->parent = copy;
249 auxnode = auxnode->younger;
250 }
251 }
252 return(copy);
253
254} /* end of Mtr_CopyTree */
255
256
268void
270 MtrNode * parent,
271 MtrNode * child)
272{
273 child->parent = parent;
274 child->younger = parent->child;
275 child->elder = NULL;
276 if (parent->child != NULL) {
277#ifdef MTR_DEBUG
278 assert(parent->child->elder == NULL);
279#endif
280 parent->child->elder = child;
281 }
282 parent->child = child;
283 return;
284
285} /* end of Mtr_MakeFirstChild */
286
287
299void
301 MtrNode * parent,
302 MtrNode * child)
303{
304 MtrNode *node;
305
306 child->younger = NULL;
307
308 if (parent->child == NULL) {
309 parent->child = child;
310 child->elder = NULL;
311 } else {
312 for (node = parent->child;
313 node->younger != NULL;
314 node = node->younger);
315 node->younger = child;
316 child->elder = node;
317 }
318 child->parent = parent;
319 return;
320
321} /* end of Mtr_MakeLastChild */
322
323
336MtrNode *
338 MtrNode * parent)
339{
340 MtrNode *child;
341
342 child = Mtr_AllocNode();
343 if (child == NULL) return(NULL);
344
345 child->child = child->younger = child-> elder = NULL;
346 child->flags = 0;
347 Mtr_MakeFirstChild(parent,child);
348 return(child);
349
350} /* end of Mtr_CreateFirstChild */
351
352
365MtrNode *
367 MtrNode * parent)
368{
369 MtrNode *child;
370
371 child = Mtr_AllocNode();
372 if (child == NULL) return(NULL);
373
374 child->child = child->younger = child->elder = NULL;
375 child->flags = 0;
376 Mtr_MakeLastChild(parent,child);
377 return(child);
378
379} /* end of Mtr_CreateLastChild */
380
381
394void
396 MtrNode * first,
397 MtrNode * second)
398{
399 second->younger = first->younger;
400 if (first->younger != NULL) {
401 first->younger->elder = second;
402 }
403 second->parent = first->parent;
404 first->younger = second;
405 second->elder = first;
406 return;
407
408} /* end of Mtr_MakeNextSibling */
409
410
422void
424 MtrNode * node)
425{
426 if (node == NULL) return;
427 (void) fprintf(stdout,
428#if SIZEOF_VOID_P == 8
429 "N=0x%-8lx C=0x%-8lx Y=0x%-8lx E=0x%-8lx P=0x%-8lx F=%x L=%u S=%u\n",
430 (unsigned long) node, (unsigned long) node->child,
431 (unsigned long) node->younger, (unsigned long) node->elder,
432 (unsigned long) node->parent, node->flags, node->low, node->size);
433#else
434 "N=0x%-8x C=0x%-8x Y=0x%-8x E=0x%-8x P=0x%-8x F=%x L=%hu S=%hu\n",
435 (unsigned) node, (unsigned) node->child,
436 (unsigned) node->younger, (unsigned) node->elder,
437 (unsigned) node->parent, node->flags, node->low, node->size);
438#endif
439 if (!MTR_TEST(node,MTR_TERMINAL)) Mtr_PrintTree(node->child);
440 Mtr_PrintTree(node->younger);
441 return;
442
443} /* end of Mtr_PrintTree */
444
445/*---------------------------------------------------------------------------*/
446/* Definition of internal functions */
447/*---------------------------------------------------------------------------*/
448
449/*---------------------------------------------------------------------------*/
450/* Definition of static functions */
451/*---------------------------------------------------------------------------*/
452
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Mtr_PrintTree(MtrNode *node)
Definition mtrBasic.c:423
MtrNode * Mtr_InitTree(void)
Definition mtrBasic.c:161
MtrNode * Mtr_CreateFirstChild(MtrNode *parent)
Definition mtrBasic.c:337
void Mtr_FreeTree(MtrNode *node)
Definition mtrBasic.c:188
void Mtr_MakeNextSibling(MtrNode *first, MtrNode *second)
Definition mtrBasic.c:395
void Mtr_MakeFirstChild(MtrNode *parent, MtrNode *child)
Definition mtrBasic.c:269
MtrNode * Mtr_AllocNode(void)
Definition mtrBasic.c:118
MtrNode * Mtr_CopyTree(MtrNode *node, int expansion)
Definition mtrBasic.c:215
MtrNode * Mtr_CreateLastChild(MtrNode *parent)
Definition mtrBasic.c:366
void Mtr_MakeLastChild(MtrNode *parent, MtrNode *child)
Definition mtrBasic.c:300
void Mtr_DeallocNode(MtrNode *node)
Definition mtrBasic.c:140
#define MTR_TERMINAL
Definition mtr.h:100
#define MTR_UNUSED
Definition mtr.h:95
#define SIZEOF_VOID_P
Definition mtr.h:73
#define MTR_TEST(node, flag)
Definition mtr.h:155
Definition mtr.h:131
MtrHalfWord low
Definition mtr.h:133
MtrHalfWord flags
Definition mtr.h:132
struct MtrNode * elder
Definition mtr.h:138
struct MtrNode * parent
Definition mtr.h:136
struct MtrNode * younger
Definition mtr.h:139
struct MtrNode * child
Definition mtr.h:137
MtrHalfWord index
Definition mtr.h:135
MtrHalfWord size
Definition mtr.h:134
#define assert(ex)
Definition util_old.h:213