ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcDec.c File Reference
#include "misc/extra/extra.h"
#include "misc/vec/vec.h"
#include "bool/bdc/bdc.h"
#include "bool/dec/dec.h"
#include "bool/kit/kit.h"
#include "opt/dau/dau.h"
#include "misc/util/utilTruth.h"
#include "opt/dsc/dsc.h"
Include dependency graph for abcDec.c:

Go to the source code of this file.

Classes

struct  Abc_TtStore_t_
 

Typedefs

typedef typedefABC_NAMESPACE_IMPL_START struct Abc_TtStore_t_ Abc_TtStore_t
 DECLARATIONS ///.
 

Functions

void Abc_TruthReadHex (word *pTruth, char *pString, int nVars)
 
void Abc_TruthWriteHex (FILE *pFile, word *pTruth, int nVars)
 
Abc_TtStore_tAbc_TruthStoreAlloc (int nVars, int nFuncs)
 
Abc_TtStore_tAbc_TruthStoreAlloc2 (int nVars, int nFuncs, word *pBuffer)
 
void Abc_TtStoreFree (Abc_TtStore_t *p, int nVarNum)
 
int Abc_FileSize (char *pFileName)
 
char * Abc_FileRead (char *pFileName)
 
void Abc_TruthGetParams (char *pFileName, int *pnVars, int *pnTruths)
 
void Abc_TruthStoreRead (char *pFileName, Abc_TtStore_t *p)
 
void Abc_TtStoreWrite (char *pFileName, Abc_TtStore_t *p, int fBinary)
 
Abc_TtStore_tAbc_TtStoreLoad (char *pFileName, int nVarNum)
 
void Abc_TtStoreLoadSave (char *pFileName)
 
void Abc_TtStoreDump (char *pFileName, Vec_Mem_t *vTtMem, int nBytes)
 
void Abc_TtStoreLoadSaveBin (char *pFileName)
 
void Abc_TtStoreTest (char *pFileName)
 
void Abc_TruthDecPerform (Abc_TtStore_t *p, int DecType, int fVerbose)
 
void Abc_TruthDecTest (char *pFileName, int DecType, int nVarNum, int fVerbose)
 
Vec_Mem_tAbc_TruthDecRead (char *pFileName, int nVarNum)
 
int Abc_DecTest (char *pFileName, int DecType, int nVarNum, int fVerbose)
 

Typedef Documentation

◆ Abc_TtStore_t

typedef typedefABC_NAMESPACE_IMPL_START struct Abc_TtStore_t_ Abc_TtStore_t

DECLARATIONS ///.

CFile****************************************************************

FileName [abcDec.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Procedures for testing and comparing decomposition algorithms.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
abcDec.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

CFile****************************************************************

FileName [abcNpn.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Procedures for testing and comparing semi-canonical forms.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
abcNpn.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 45 of file abcDec.c.

Function Documentation

◆ Abc_DecTest()

int Abc_DecTest ( char * pFileName,
int DecType,
int nVarNum,
int fVerbose )

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

Synopsis [Testbench for decomposition algorithms.]

Description []

SideEffects []

SeeAlso []

Definition at line 781 of file abcDec.c.

782{
783 if ( fVerbose )
784 printf( "Using truth tables from file \"%s\"...\n", pFileName );
785 if ( DecType == 0 )
786 { if ( nVarNum < 0 ) Abc_TtStoreTest( pFileName ); }
787 else if ( DecType >= 1 && DecType <= 6 )
788 Abc_TruthDecTest( pFileName, DecType, nVarNum, fVerbose );
789 else
790 printf( "Unknown decomposition type value (%d).\n", DecType );
791 fflush( stdout );
792 return 0;
793}
void Abc_TruthDecTest(char *pFileName, int DecType, int nVarNum, int fVerbose)
Definition abcDec.c:721
void Abc_TtStoreTest(char *pFileName)
Definition abcDec.c:545
Here is the call graph for this function:

◆ Abc_FileRead()

char * Abc_FileRead ( char * pFileName)

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

Synopsis [Read file contents.]

Description []

SideEffects []

SeeAlso []

Definition at line 223 of file abcDec.c.

224{
225 FILE * pFile;
226 char * pBuffer;
227 int nFileSize, RetValue;
228 pFile = fopen( pFileName, "rb" );
229 if ( pFile == NULL )
230 {
231 printf( "Cannot open file \"%s\" for reading.\n", pFileName );
232 return NULL;
233 }
234 // get the file size, in bytes
235 fseek( pFile, 0, SEEK_END );
236 nFileSize = ftell( pFile );
237 // move the file current reading position to the beginning
238 rewind( pFile );
239 // load the contents of the file into memory
240 pBuffer = (char *)malloc( nFileSize + 3 );
241 RetValue = fread( pBuffer, nFileSize, 1, pFile );
242 // add several empty lines at the end
243 // (these will be used to signal the end of parsing)
244 pBuffer[ nFileSize + 0] = '\n';
245 pBuffer[ nFileSize + 1] = '\n';
246 // terminate the string with '\0'
247 pBuffer[ nFileSize + 2] = '\0';
248 fclose( pFile );
249 return pBuffer;
250}
VOID_HACK rewind()
char * malloc()
#define SEEK_END
Definition zconf.h:392
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_FileSize()

int Abc_FileSize ( char * pFileName)

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

Synopsis [Read file contents.]

Description []

SideEffects []

SeeAlso []

Definition at line 195 of file abcDec.c.

196{
197 FILE * pFile;
198 int nFileSize;
199 pFile = fopen( pFileName, "rb" );
200 if ( pFile == NULL )
201 {
202 printf( "Cannot open file \"%s\" for reading.\n", pFileName );
203 return -1;
204 }
205 // get the file size, in bytes
206 fseek( pFile, 0, SEEK_END );
207 nFileSize = ftell( pFile );
208 fclose( pFile );
209 return nFileSize;
210}
Here is the caller graph for this function:

◆ Abc_TruthDecPerform()

void Abc_TruthDecPerform ( Abc_TtStore_t * p,
int DecType,
int fVerbose )

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

Synopsis [Apply decomposition to the truth table.]

Description [Returns the number of AIG nodes.]

SideEffects []

SeeAlso []

Definition at line 575 of file abcDec.c.

576{
577 abctime clk = Abc_Clock();
578 int i, nNodes = 0;
579
580 char * pAlgoName = NULL;
581 if ( DecType == 1 )
582 pAlgoName = "factoring";
583 else if ( DecType == 2 )
584 pAlgoName = "bi-decomp";
585 else if ( DecType == 3 )
586 pAlgoName = "DSD";
587 else if ( DecType == 4 )
588 pAlgoName = "fast DSD";
589 else if ( DecType == 5 )
590 pAlgoName = "analysis";
591 else if ( DecType == 6 )
592 pAlgoName = "DSD ICCD'15";
593
594 if ( pAlgoName )
595 printf( "Applying %-10s to %8d func%s of %2d vars... ",
596 pAlgoName, p->nFuncs, (p->nFuncs == 1 ? "":"s"), p->nVars );
597 if ( fVerbose )
598 printf( "\n" );
599
600 if ( DecType == 1 )
601 {
602 // perform algebraic factoring and count AIG nodes
603 Dec_Graph_t * pFForm;
604 Vec_Int_t * vCover;
605 Vec_Str_t * vStr;
606 char * pSopStr;
607 vStr = Vec_StrAlloc( 10000 );
608 vCover = Vec_IntAlloc( 1 << 16 );
609 for ( i = 0; i < p->nFuncs; i++ )
610 {
611// extern int Abc_IsopTest( word * pFunc, int nVars, Vec_Int_t * vCover );
612// if ( i == 0 ) printf( "\n" );
613// Abc_IsopTest( p->pFuncs[i], p->nVars, vCover );
614// continue;
615 if ( fVerbose )
616 printf( "%7d : ", i );
617 pSopStr = Kit_PlaFromTruthNew( (unsigned *)p->pFuncs[i], p->nVars, vCover, vStr );
618 pFForm = Dec_Factor( pSopStr );
619 nNodes += Dec_GraphNodeNum( pFForm );
620 if ( fVerbose )
621 Dec_GraphPrint( stdout, pFForm, NULL, NULL );
622 Dec_GraphFree( pFForm );
623 }
624 Vec_IntFree( vCover );
625 Vec_StrFree( vStr );
626 }
627 else if ( DecType == 2 )
628 {
629 // perform bi-decomposition and count AIG nodes
630 Bdc_Man_t * pManDec;
631 Bdc_Par_t Pars = {0}, * pPars = &Pars;
632 pPars->nVarsMax = p->nVars;
633 pManDec = Bdc_ManAlloc( pPars );
634 for ( i = 0; i < p->nFuncs; i++ )
635 {
636 if ( fVerbose )
637 printf( "%7d : ", i );
638 Bdc_ManDecompose( pManDec, (unsigned *)p->pFuncs[i], NULL, p->nVars, NULL, 1000 );
639 nNodes += Bdc_ManAndNum( pManDec );
640 if ( fVerbose )
641 Bdc_ManDecPrint( pManDec );
642 }
643 Bdc_ManFree( pManDec );
644 }
645 else if ( DecType == 3 )
646 {
647 // perform disjoint-support decomposition and count AIG nodes
648 // (non-DSD blocks are decomposed into 2:1 MUXes, each counting as 3 AIG nodes)
649 Kit_DsdNtk_t * pNtk;
650 for ( i = 0; i < p->nFuncs; i++ )
651 {
652 if ( fVerbose )
653 printf( "%7d : ", i );
654 pNtk = Kit_DsdDecomposeMux( (unsigned *)p->pFuncs[i], p->nVars, 3 );
655 if ( fVerbose )
656 Kit_DsdPrintExpanded( pNtk ), printf( "\n" );
657 nNodes += Kit_DsdCountAigNodes( pNtk );
658 Kit_DsdNtkFree( pNtk );
659 }
660 }
661 else if ( DecType == 4 )
662 {
663 char pDsd[DAU_MAX_STR];
664 for ( i = 0; i < p->nFuncs; i++ )
665 {
666 if ( fVerbose )
667 printf( "%7d : ", i );
668 Dau_DsdDecompose( p->pFuncs[i], p->nVars, 0, 1, pDsd );
669 if ( fVerbose )
670 printf( "%s\n", pDsd );
671 nNodes += Dau_DsdCountAnds( pDsd );
672 }
673 }
674 else if ( DecType == 5 )
675 {
676 for ( i = 0; i < p->nFuncs; i++ )
677 {
678 extern void Dau_DecTrySets( word * pInit, int nVars, int fVerbose );
679 int nSuppSize = Abc_TtSupportSize( p->pFuncs[i], p->nVars );
680 if ( fVerbose )
681 printf( "%7d : ", i );
682 Dau_DecTrySets( p->pFuncs[i], nSuppSize, fVerbose );
683 if ( fVerbose )
684 printf( "\n" );
685 }
686 } else if ( DecType == 6 )
687 {
688 char pDsd[DSC_MAX_STR];
689 /* memory pool with a capacity of storing 3*nVars
690 truth-tables for negative and positive cofactors and
691 the boolean difference for each input variable */
692 word *mem_pool = Dsc_alloc_pool(p->nVars);
693 for ( i = 0; i < p->nFuncs; i++ )
694 {
695 if ( fVerbose )
696 printf( "%7d : ", i );
697 Dsc_Decompose(p->pFuncs[i], p->nVars, pDsd, mem_pool);
698 if ( fVerbose )
699 printf( "%s\n", pDsd[0] ? pDsd : "NULL");
700 nNodes += Dsc_CountAnds( pDsd );
701 }
702 Dsc_free_pool(mem_pool);
703 }
704 else assert( 0 );
705
706 printf( "AIG nodes =%9d ", nNodes );
707 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
708}
ABC_INT64_T abctime
Definition abc_global.h:332
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
struct Bdc_Par_t_ Bdc_Par_t
Definition bdc.h:44
struct Bdc_Man_t_ Bdc_Man_t
Definition bdc.h:43
void Bdc_ManDecPrint(Bdc_Man_t *p)
Definition bdcCore.c:260
void Bdc_ManFree(Bdc_Man_t *p)
Definition bdcCore.c:113
int Bdc_ManAndNum(Bdc_Man_t *p)
Definition bdcCore.c:49
int Bdc_ManDecompose(Bdc_Man_t *p, unsigned *puFunc, unsigned *puCare, int nVars, Vec_Ptr_t *vDivs, int nNodesMax)
Definition bdcCore.c:291
Bdc_Man_t * Bdc_ManAlloc(Bdc_Par_t *pPars)
MACRO DEFINITIONS ///.
Definition bdcCore.c:68
void Dau_DecTrySets(word *pInit, int nVars, int fVerbose)
Definition dauNonDsd.c:831
int Dau_DsdDecompose(word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes)
Definition dauDsd.c:1912
#define DAU_MAX_STR
Definition dau.h:43
int Dau_DsdCountAnds(char *pDsd)
Definition dauDsd.c:316
void Dec_GraphPrint(FILE *pFile, Dec_Graph_t *pGraph, char *pNamesIn[], char *pNameOut)
FUNCTION DEFINITIONS ///.
Definition decPrint.c:49
Dec_Graph_t * Dec_Factor(char *pSop)
FUNCTION DECLARATIONS ///.
Definition decFactor.c:58
struct Dec_Graph_t_ Dec_Graph_t
Definition dec.h:68
int Dsc_CountAnds(char *pDsd)
Definition dsc.c:513
void Dsc_free_pool(word *pool)
Definition dsc.c:297
int Dsc_Decompose(word *pTruth, const int nVarsInit, char *const pRes, word *pool)
Definition dsc.c:311
word * Dsc_alloc_pool(int nVars)
BASIC TYPES ///.
Definition dsc.c:290
#define DSC_MAX_STR
Definition dsc.h:41
Cube * p
Definition exorList.c:222
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
char * Kit_PlaFromTruthNew(unsigned *pTruth, int nVars, Vec_Int_t *vCover, Vec_Str_t *vStr)
Definition kitPla.c:406
void Kit_DsdNtkFree(Kit_DsdNtk_t *pNtk)
Definition kitDsd.c:164
int Kit_DsdCountAigNodes(Kit_DsdNtk_t *pNtk)
Definition kitDsd.c:1896
struct Kit_DsdNtk_t_ Kit_DsdNtk_t
Definition kit.h:124
Kit_DsdNtk_t * Kit_DsdDecomposeMux(unsigned *pTruth, int nVars, int nDecMux)
Definition kitDsd.c:2351
void Kit_DsdPrintExpanded(Kit_DsdNtk_t *pNtk)
Definition kitDsd.c:472
int nVarsMax
Definition bdc.h:48
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_TruthDecRead()

Vec_Mem_t * Abc_TruthDecRead ( char * pFileName,
int nVarNum )

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

Synopsis [Read truth tables from file.]

Description []

SideEffects []

SeeAlso []

Definition at line 748 of file abcDec.c.

749{
750 Abc_TtStore_t * p; int i;
751 if ( nVarNum < 6 )
752 nVarNum = 6;
753
754 // allocate data-structure
755 p = Abc_TtStoreLoad( pFileName, nVarNum );
756 if ( p == NULL ) return NULL;
757
758 // consider functions from the file
759 Vec_Mem_t * vTtMem = Vec_MemAllocForTTSimple( nVarNum );
760 for ( i = 0; i < p->nFuncs; i++ )
761 Vec_MemHashInsert( vTtMem, (word *)p->pFuncs[i] );
762
763 // delete data-structure
764 Abc_TtStoreFree( p, nVarNum );
765// printf( "Finished decomposing truth tables from file \"%s\".\n", pFileName );
766 return vTtMem;
767}
void Abc_TtStoreFree(Abc_TtStore_t *p, int nVarNum)
Definition abcDec.c:176
Abc_TtStore_t * Abc_TtStoreLoad(char *pFileName, int nVarNum)
Definition abcDec.c:396
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
Definition utilMem.c:35
Here is the call graph for this function:

◆ Abc_TruthDecTest()

void Abc_TruthDecTest ( char * pFileName,
int DecType,
int nVarNum,
int fVerbose )

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

Synopsis [Apply decomposition to truth tables.]

Description []

SideEffects []

SeeAlso []

Definition at line 721 of file abcDec.c.

722{
724
725 // allocate data-structure
726 p = Abc_TtStoreLoad( pFileName, nVarNum );
727 if ( p == NULL ) return;
728
729 // consider functions from the file
730 Abc_TruthDecPerform( p, DecType, fVerbose );
731
732 // delete data-structure
733 Abc_TtStoreFree( p, nVarNum );
734// printf( "Finished decomposing truth tables from file \"%s\".\n", pFileName );
735}
void Abc_TruthDecPerform(Abc_TtStore_t *p, int DecType, int fVerbose)
Definition abcDec.c:575
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_TruthGetParams()

void Abc_TruthGetParams ( char * pFileName,
int * pnVars,
int * pnTruths )

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

Synopsis [Determine the number of variables by reading the first line.]

Description [Determine the number of functions by counting the lines.]

SideEffects []

SeeAlso []

Definition at line 263 of file abcDec.c.

264{
265 char * pContents;
266 int i, nVars, nLines;
267 // prepare the output
268 if ( pnVars )
269 *pnVars = 0;
270 if ( pnTruths )
271 *pnTruths = 0;
272 // read data from file
273 pContents = Abc_FileRead( pFileName );
274 if ( pContents == NULL )
275 return;
276 // count the number of symbols before the first space or new-line
277 // (note that on Windows symbols '\r' can be inserted before each '\n')
278 for ( i = 0; pContents[i]; i++ )
279 if ( pContents[i] == ' ' || pContents[i] == '\n' || pContents[i] == '\r' )
280 break;
281 if ( pContents[i] == 0 )
282 printf( "Strange, the input file does not have spaces and new-lines...\n" );
283
284 // acount for the fact that truth tables may have "0x" at the beginning of each line
285 if ( pContents[0] == '0' && pContents[1] == 'x' )
286 i = i - 2;
287
288 // determine the number of variables
289 for ( nVars = 0; nVars < 32; nVars++ )
290 if ( 4 * i == (1 << nVars) ) // the number of bits equal to the size of truth table
291 break;
292 if ( nVars < 2 || nVars > 16 )
293 {
294 printf( "Does not look like the input file contains truth tables...\n" );
295 return;
296 }
297 if ( pnVars )
298 *pnVars = nVars;
299
300 // determine the number of functions by counting the lines
301 nLines = 0;
302 for ( i = 0; pContents[i]; i++ )
303 nLines += (pContents[i] == '\n');
304 if ( pnTruths )
305 *pnTruths = nLines;
306 ABC_FREE( pContents );
307}
char * Abc_FileRead(char *pFileName)
Definition abcDec.c:223
#define ABC_FREE(obj)
Definition abc_global.h:267
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_TruthReadHex()

void Abc_TruthReadHex ( word * pTruth,
char * pString,
int nVars )

Definition at line 92 of file abcDec.c.

93{
94 int nWords = (nVars < 7)? 1 : (1 << (nVars-6));
95 int k, Digit, nDigits = (nVars < 7) ? (1 << (nVars-2)) : (nWords << 4);
96 char EndSymbol;
97 // skip the first 2 symbols if they are "0x"
98 if ( pString[0] == '0' && pString[1] == 'x' )
99 pString += 2;
100 // get the last symbol
101 EndSymbol = pString[nDigits];
102 // the end symbol of the TT (the one immediately following hex digits)
103 // should be one of the following: space, a new-line, or a zero-terminator
104 // (note that on Windows symbols '\r' can be inserted before each '\n')
105 assert( EndSymbol == ' ' || EndSymbol == '\n' || EndSymbol == '\r' || EndSymbol == '\0' );
106 // read hexadecimal digits in the reverse order
107 // (the last symbol in the string is the least significant digit)
108 for ( k = 0; k < nDigits; k++ )
109 {
110 Digit = Abc_TruthReadHexDigit( pString[nDigits - 1 - k] );
111 assert( Digit >= 0 && Digit < 16 );
112 Abc_TruthSetHex( pTruth, k, Digit );
113 }
114}
int nWords
Definition abcNpn.c:127
Here is the caller graph for this function:

◆ Abc_TruthStoreAlloc()

Abc_TtStore_t * Abc_TruthStoreAlloc ( int nVars,
int nFuncs )

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

Synopsis [Allocate/Deallocate storage for truth tables..]

Description []

SideEffects []

SeeAlso []

Definition at line 141 of file abcDec.c.

142{
144 int i;
145 p = (Abc_TtStore_t *)malloc( sizeof(Abc_TtStore_t) );
146 p->nVars = nVars;
147 p->nWords = (nVars < 7) ? 1 : (1 << (nVars-6));
148 p->nFuncs = nFuncs;
149 // alloc storage for 'nFuncs' truth tables as one chunk of memory
150 p->pFuncs = (word **)malloc( (sizeof(word *) + sizeof(word) * p->nWords) * p->nFuncs );
151 // assign and clean the truth table storage
152 p->pFuncs[0] = (word *)(p->pFuncs + p->nFuncs);
153 memset( p->pFuncs[0], 0, sizeof(word) * p->nWords * p->nFuncs );
154 // split it up into individual truth tables
155 for ( i = 1; i < p->nFuncs; i++ )
156 p->pFuncs[i] = p->pFuncs[i-1] + p->nWords;
157 return p;
158}
for(p=first;p->value< newval;p=p->next)
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_TruthStoreAlloc2()

Abc_TtStore_t * Abc_TruthStoreAlloc2 ( int nVars,
int nFuncs,
word * pBuffer )

Definition at line 159 of file abcDec.c.

160{
162 int i;
163 p = (Abc_TtStore_t *)malloc( sizeof(Abc_TtStore_t) );
164 p->nVars = nVars;
165 p->nWords = (nVars < 7) ? 1 : (1 << (nVars-6));
166 p->nFuncs = nFuncs;
167 // alloc storage for 'nFuncs' truth tables as one chunk of memory
168 p->pFuncs = (word **)malloc( sizeof(word *) * p->nFuncs );
169 // assign and clean the truth table storage
170 p->pFuncs[0] = pBuffer;
171 // split it up into individual truth tables
172 for ( i = 1; i < p->nFuncs; i++ )
173 p->pFuncs[i] = p->pFuncs[i-1] + p->nWords;
174 return p;
175}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_TruthStoreRead()

void Abc_TruthStoreRead ( char * pFileName,
Abc_TtStore_t * p )

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

Synopsis [Read truth tables from file.]

Description []

SideEffects []

SeeAlso []

Definition at line 321 of file abcDec.c.

322{
323 char * pContents;
324 int i, nLines;
325 pContents = Abc_FileRead( pFileName );
326 if ( pContents == NULL )
327 return;
328 // here it is assumed (without checking!) that each line of the file
329 // begins with a string of hexadecimal chars followed by space
330
331 // the file will be read till the first empty line (pContents[i] == '\n')
332 // (note that Abc_FileRead() added several empty lines at the end of the file contents)
333 for ( nLines = i = 0; pContents[i] != '\n'; )
334 {
335 // read one line
336 Abc_TruthReadHex( p->pFuncs[nLines++], &pContents[i], p->nVars );
337 // skip till after the end-of-line symbol
338 // (note that end-of-line symbol is also skipped)
339 while ( pContents[i++] != '\n' );
340 }
341 // adjust the number of functions read
342 // (we may have allocated more storage because some lines in the file were empty)
343 assert( p->nFuncs >= nLines );
344 p->nFuncs = nLines;
345 ABC_FREE( pContents );
346}
void Abc_TruthReadHex(word *pTruth, char *pString, int nVars)
Definition abcDec.c:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_TruthWriteHex()

void Abc_TruthWriteHex ( FILE * pFile,
word * pTruth,
int nVars )

Definition at line 117 of file abcDec.c.

118{
119 int nDigits, Digit, k;
120 nDigits = (1 << (nVars-2));
121 for ( k = 0; k < nDigits; k++ )
122 {
123 Digit = Abc_TruthGetHex( pTruth, k );
124 assert( Digit >= 0 && Digit < 16 );
125 Abc_TruthWriteHexDigit( pFile, Digit );
126 }
127}
Here is the caller graph for this function:

◆ Abc_TtStoreDump()

void Abc_TtStoreDump ( char * pFileName,
Vec_Mem_t * vTtMem,
int nBytes )

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

Synopsis [Read truth tables from input file and write them into output file.]

Description []

SideEffects []

SeeAlso []

Definition at line 472 of file abcDec.c.

473{
474 word * pTruth; int i;
475 FILE * pFile = fopen( pFileName, "wb" );
476 if ( pFile == NULL )
477 {
478 printf( "Cannot open file \"%s\" for writing.\n", pFileName );
479 return;
480 }
481 Vec_MemForEachEntry( vTtMem, pTruth, i )
482 fwrite( pTruth, nBytes, 1, pFile );
483 fclose( pFile );
484}
#define Vec_MemForEachEntry(p, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecMem.h:68

◆ Abc_TtStoreFree()

void Abc_TtStoreFree ( Abc_TtStore_t * p,
int nVarNum )

Definition at line 176 of file abcDec.c.

177{
178 if ( nVarNum >= 0 )
179 ABC_FREE( p->pFuncs[0] );
180 ABC_FREE( p->pFuncs );
181 ABC_FREE( p );
182}
Here is the caller graph for this function:

◆ Abc_TtStoreLoad()

Abc_TtStore_t * Abc_TtStoreLoad ( char * pFileName,
int nVarNum )

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

Synopsis [Read truth tables from input file and write them into output file.]

Description []

SideEffects []

SeeAlso []

Definition at line 396 of file abcDec.c.

397{
399 if ( nVarNum < 0 )
400 {
401 int nVars, nTruths;
402 // figure out how many truth table and how many variables
403 Abc_TruthGetParams( pFileName, &nVars, &nTruths );
404 if ( nVars < 2 || nVars > 16 || nTruths == 0 )
405 return NULL;
406 // allocate data-structure
407 p = Abc_TruthStoreAlloc( nVars, nTruths );
408 // read info from file
409 Abc_TruthStoreRead( pFileName, p );
410 }
411 else
412 {
413 char * pBuffer;
414 int nFileSize = Abc_FileSize( pFileName );
415 int nBytes = (1 << (nVarNum-3));
416 int nTruths = nFileSize / nBytes;
417 if ( nFileSize == -1 )
418 return NULL;
419 assert( nVarNum >= 6 );
420 if ( nFileSize % nBytes != 0 )
421 Abc_Print( 0, "The file size (%d) is divided by the truth table size (%d) with remainder (%d).\n",
422 nFileSize, nBytes, nFileSize % nBytes );
423 // read file contents
424 pBuffer = Abc_FileRead( pFileName );
425 // allocate data-structure
426 p = Abc_TruthStoreAlloc2( nVarNum, nTruths, (word *)pBuffer );
427 }
428 return p;
429}
void Abc_TruthStoreRead(char *pFileName, Abc_TtStore_t *p)
Definition abcDec.c:321
int Abc_FileSize(char *pFileName)
Definition abcDec.c:195
Abc_TtStore_t * Abc_TruthStoreAlloc2(int nVars, int nFuncs, word *pBuffer)
Definition abcDec.c:159
void Abc_TruthGetParams(char *pFileName, int *pnVars, int *pnTruths)
Definition abcDec.c:263
Abc_TtStore_t * Abc_TruthStoreAlloc(int nVars, int nFuncs)
Definition abcDec.c:141
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_TtStoreLoadSave()

void Abc_TtStoreLoadSave ( char * pFileName)

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

Synopsis [Read truth tables from input file and write them into output file.]

Description []

SideEffects []

SeeAlso []

Definition at line 442 of file abcDec.c.

443{
445 char * pFileInput = pFileName;
446 char * pFileOutput = Extra_FileNameGenericAppend(pFileName, "_binary.data");
447
448 // read info from file
449 p = Abc_TtStoreLoad( pFileInput, -1 );
450 if ( p == NULL )
451 return;
452
453 // write into another file
454 Abc_TtStoreWrite( pFileOutput, p, 1 );
455
456 // delete data-structure
457 Abc_TtStoreFree( p, -1 );
458 printf( "Input file \"%s\" was copied into output file \"%s\".\n", pFileInput, pFileOutput );
459}
void Abc_TtStoreWrite(char *pFileName, Abc_TtStore_t *p, int fBinary)
Definition abcDec.c:359
char * Extra_FileNameGenericAppend(char *pBase, char *pSuffix)
Here is the call graph for this function:

◆ Abc_TtStoreLoadSaveBin()

void Abc_TtStoreLoadSaveBin ( char * pFileName)

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

Synopsis [Read truth tables in binary text form and write them into file as binary data.]

Description []

SideEffects []

SeeAlso []

Definition at line 497 of file abcDec.c.

498{
499 unsigned * pTruth = ABC_CALLOC( unsigned, (1 << 11) );
500 char * pBuffer = ABC_CALLOC( char, (1 << 16) );
501 char * pFileInput = pFileName;
502 char * pFileOutput = Extra_FileNameGenericAppend(pFileName, "_binary.data");
503 FILE * pFileI = fopen( pFileInput, "rb" );
504 FILE * pFileO = fopen( pFileOutput, "wb" );
505 int i, Value, nVarsAll = -1;
506 if ( pFileI == NULL )
507 return;
508 while ( fgets(pBuffer, (1 << 16), pFileI) )
509 {
510 int Len = strlen(pBuffer)-1; // subtract 1 for end-of-line
511 int nVars = Abc_Base2Log(Len);
512 int nInts = Abc_BitWordNum(Len);
513 assert( Len == (1 << nVars) );
514 if ( nVarsAll == -1 )
515 nVarsAll = nVars;
516 else
517 assert( nVarsAll == nVars );
518 memset( pTruth, 0, sizeof(int)*nInts );
519 for ( i = 0; i < Len; i++ )
520 if ( pBuffer[i] == '1' )
521 Abc_InfoSetBit( pTruth, i );
522 else
523 assert( pBuffer[i] == '0' );
524 Value = fwrite( pTruth, 1, sizeof(int) * nInts, pFileO );
525 assert( Value == (int)sizeof(int) * nInts );
526 }
527 ABC_FREE( pTruth );
528 ABC_FREE( pBuffer );
529 fclose( pFileI );
530 fclose( pFileO );
531 printf( "Input file \"%s\" was copied into output file \"%s\".\n", pFileInput, pFileOutput );
532}
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define Len
Definition deflate.h:78
int strlen()
Here is the call graph for this function:

◆ Abc_TtStoreTest()

void Abc_TtStoreTest ( char * pFileName)

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

Synopsis [Read truth tables from input file and write them into output file.]

Description []

SideEffects []

SeeAlso []

Definition at line 545 of file abcDec.c.

546{
548 char * pFileInput = pFileName;
549 char * pFileOutput = "out.txt";
550
551 // read info from file
552 p = Abc_TtStoreLoad( pFileInput, -1 );
553 if ( p == NULL )
554 return;
555
556 // write into another file
557 Abc_TtStoreWrite( pFileOutput, p, 0 );
558
559 // delete data-structure
560 Abc_TtStoreFree( p, -1 );
561 printf( "Input file \"%s\" was copied into output file \"%s\".\n", pFileInput, pFileOutput );
562}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_TtStoreWrite()

void Abc_TtStoreWrite ( char * pFileName,
Abc_TtStore_t * p,
int fBinary )

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

Synopsis [Write truth tables into file.]

Description []

SideEffects []

SeeAlso []

Definition at line 359 of file abcDec.c.

360{
361 FILE * pFile;
362 char pBuffer[1000];
363 int i, nBytes = 8 * Abc_Truth6WordNum( p->nVars );
364 pFile = fopen( pFileName, "wb" );
365 if ( pFile == NULL )
366 {
367 printf( "Cannot open file \"%s\" for writing.\n", pFileName );
368 return;
369 }
370 for ( i = 0; i < p->nFuncs; i++ )
371 {
372 if ( fBinary )
373 fwrite( p->pFuncs[i], nBytes, 1, pFile );
374 else
375 {
376 Abc_TruthWriteHex( pFile, p->pFuncs[i], p->nVars ), fprintf( pFile, " " );
377 Dau_DsdDecompose( p->pFuncs[i], p->nVars, 0, (int)(p->nVars <= 10), pBuffer );
378 fprintf( pFile, "%s\n", pBuffer );
379 }
380 }
381 fclose( pFile );
382}
void Abc_TruthWriteHex(FILE *pFile, word *pTruth, int nVars)
Definition abcDec.c:117
Here is the call graph for this function:
Here is the caller graph for this function: