ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
mtrBasic.c File Reference
#include "misc/util/util_hack.h"
#include "mtrInt.h"
Include dependency graph for mtrBasic.c:

Go to the source code of this file.

Functions

MtrNodeMtr_AllocNode (void)
 
void Mtr_DeallocNode (MtrNode *node)
 
MtrNodeMtr_InitTree (void)
 
void Mtr_FreeTree (MtrNode *node)
 
MtrNodeMtr_CopyTree (MtrNode *node, int expansion)
 
void Mtr_MakeFirstChild (MtrNode *parent, MtrNode *child)
 
void Mtr_MakeLastChild (MtrNode *parent, MtrNode *child)
 
MtrNodeMtr_CreateFirstChild (MtrNode *parent)
 
MtrNodeMtr_CreateLastChild (MtrNode *parent)
 
void Mtr_MakeNextSibling (MtrNode *first, MtrNode *second)
 
void Mtr_PrintTree (MtrNode *node)
 

Function Documentation

◆ Mtr_AllocNode()

MtrNode * Mtr_AllocNode ( void )

AutomaticStart AutomaticEnd Function********************************************************************

Synopsis [Allocates new tree node.]

Description [Allocates new tree node. Returns pointer to node.]

SideEffects [None]

SeeAlso [Mtr_DeallocNode]

Definition at line 118 of file mtrBasic.c.

119{
120 MtrNode *node;
121
122 node = ABC_ALLOC(MtrNode,1);
123 return node;
124
125} /* Mtr_AllocNode */
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
Definition mtr.h:131
Here is the caller graph for this function:

◆ Mtr_CopyTree()

MtrNode * Mtr_CopyTree ( MtrNode * node,
int expansion )

Function********************************************************************

Synopsis [Makes a copy of tree.]

Description [Makes a copy of tree. If parameter expansion is greater than 1, it will expand the tree by that factor. It is an error for expansion to be less than 1. Returns a pointer to the copy if successful; NULL otherwise.]

SideEffects [None]

SeeAlso [Mtr_InitTree]

Definition at line 215 of file mtrBasic.c.

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 */
void Mtr_FreeTree(MtrNode *node)
Definition mtrBasic.c:188
MtrNode * Mtr_AllocNode(void)
Definition mtrBasic.c:118
MtrNode * Mtr_CopyTree(MtrNode *node, int expansion)
Definition mtrBasic.c:215
void Mtr_DeallocNode(MtrNode *node)
Definition mtrBasic.c:140
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mtr_CreateFirstChild()

MtrNode * Mtr_CreateFirstChild ( MtrNode * parent)

Function********************************************************************

Synopsis [Creates a new node and makes it the first child of parent.]

Description [Creates a new node and makes it the first child of parent. Returns pointer to new child.]

SideEffects [None]

SeeAlso [Mtr_MakeFirstChild Mtr_CreateLastChild]

Definition at line 337 of file mtrBasic.c.

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 */
void Mtr_MakeFirstChild(MtrNode *parent, MtrNode *child)
Definition mtrBasic.c:269
Here is the call graph for this function:

◆ Mtr_CreateLastChild()

MtrNode * Mtr_CreateLastChild ( MtrNode * parent)

Function********************************************************************

Synopsis [Creates a new node and makes it the last child of parent.]

Description [Creates a new node and makes it the last child of parent. Returns pointer to new child.]

SideEffects [None]

SeeAlso [Mtr_MakeLastChild Mtr_CreateFirstChild]

Definition at line 366 of file mtrBasic.c.

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 */
void Mtr_MakeLastChild(MtrNode *parent, MtrNode *child)
Definition mtrBasic.c:300
Here is the call graph for this function:

◆ Mtr_DeallocNode()

void Mtr_DeallocNode ( MtrNode * node)

Function********************************************************************

Synopsis [Deallocates tree node.]

Description []

SideEffects [None]

SeeAlso [Mtr_AllocNode]

Definition at line 140 of file mtrBasic.c.

142{
143 ABC_FREE(node);
144 return;
145
146} /* end of Mtr_DeallocNode */
#define ABC_FREE(obj)
Definition abc_global.h:267
Here is the caller graph for this function:

◆ Mtr_FreeTree()

void Mtr_FreeTree ( MtrNode * node)

Function********************************************************************

Synopsis [Disposes of tree rooted at node.]

Description []

SideEffects [None]

SeeAlso [Mtr_InitTree]

Definition at line 188 of file mtrBasic.c.

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 */
#define MTR_TERMINAL
Definition mtr.h:100
#define MTR_TEST(node, flag)
Definition mtr.h:155
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mtr_InitTree()

MtrNode * Mtr_InitTree ( void )

Function********************************************************************

Synopsis [Initializes tree with one node.]

Description [Initializes tree with one node. Returns pointer to node.]

SideEffects [None]

SeeAlso [Mtr_FreeTree Mtr_InitGroupTree]

Definition at line 161 of file mtrBasic.c.

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 */
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mtr_MakeFirstChild()

void Mtr_MakeFirstChild ( MtrNode * parent,
MtrNode * child )

Function********************************************************************

Synopsis [Makes child the first child of parent.]

Description []

SideEffects [None]

SeeAlso [Mtr_MakeLastChild Mtr_CreateFirstChild]

Definition at line 269 of file mtrBasic.c.

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 */
#define assert(ex)
Definition util_old.h:213
Here is the caller graph for this function:

◆ Mtr_MakeLastChild()

void Mtr_MakeLastChild ( MtrNode * parent,
MtrNode * child )

Function********************************************************************

Synopsis [Makes child the last child of parent.]

Description []

SideEffects [None]

SeeAlso [Mtr_MakeFirstChild Mtr_CreateLastChild]

Definition at line 300 of file mtrBasic.c.

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 */
Here is the caller graph for this function:

◆ Mtr_MakeNextSibling()

void Mtr_MakeNextSibling ( MtrNode * first,
MtrNode * second )

Function********************************************************************

Synopsis [Makes second the next sibling of first.]

Description [Makes second the next sibling of first. Second becomes a child of the parent of first.]

SideEffects [None]

SeeAlso []

Definition at line 395 of file mtrBasic.c.

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 */

◆ Mtr_PrintTree()

void Mtr_PrintTree ( MtrNode * node)

Function********************************************************************

Synopsis [Prints a tree, one node per line.]

Description []

SideEffects [None]

SeeAlso [Mtr_PrintGroups]

Definition at line 423 of file mtrBasic.c.

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 */
void Mtr_PrintTree(MtrNode *node)
Definition mtrBasic.c:423
#define SIZEOF_VOID_P
Definition mtr.h:73
Here is the call graph for this function:
Here is the caller graph for this function: