ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
plaCom.c
Go to the documentation of this file.
1
20
21#include "pla.h"
22#include "base/main/mainInt.h"
23
25
26
30
31static int Abc_CommandReadPla ( Abc_Frame_t * pAbc, int argc, char ** argv );
32static int Abc_CommandWritePla ( Abc_Frame_t * pAbc, int argc, char ** argv );
33static int Abc_CommandPs ( Abc_Frame_t * pAbc, int argc, char ** argv );
34static int Abc_CommandGen ( Abc_Frame_t * pAbc, int argc, char ** argv );
35static int Abc_CommandMerge ( Abc_Frame_t * pAbc, int argc, char ** argv );
36static int Abc_CommandTest ( Abc_Frame_t * pAbc, int argc, char ** argv );
37
38static inline Pla_Man_t * Pla_AbcGetMan( Abc_Frame_t * pAbc ) { return (Pla_Man_t *)pAbc->pAbcPla; }
39static inline void Pla_AbcFreeMan( Abc_Frame_t * pAbc ) { if ( pAbc->pAbcPla ) Pla_ManFree(Pla_AbcGetMan(pAbc)); }
40static inline void Pla_AbcUpdateMan( Abc_Frame_t * pAbc, Pla_Man_t * p ) { Pla_AbcFreeMan(pAbc); pAbc->pAbcPla = p; }
41
45
57void Pla_Init( Abc_Frame_t * pAbc )
58{
59 Cmd_CommandAdd( pAbc, "Two-level", "|read", Abc_CommandReadPla, 0 );
60 Cmd_CommandAdd( pAbc, "Two-level", "|write", Abc_CommandWritePla, 0 );
61 Cmd_CommandAdd( pAbc, "Two-level", "|ps", Abc_CommandPs, 0 );
62 Cmd_CommandAdd( pAbc, "Two-level", "|gen", Abc_CommandGen, 0 );
63 Cmd_CommandAdd( pAbc, "Two-level", "|merge", Abc_CommandMerge, 0 );
64 Cmd_CommandAdd( pAbc, "Two-level", "|test", Abc_CommandTest, 0 );
65}
66
78void Pla_End( Abc_Frame_t * pAbc )
79{
80 Pla_AbcFreeMan( pAbc );
81}
82
95{
96 Pla_AbcUpdateMan( pAbc, p );
97}
98
99
111int Abc_CommandReadPla( Abc_Frame_t * pAbc, int argc, char ** argv )
112{
113 FILE * pFile;
114 Pla_Man_t * p = NULL;
115 char * pFileName = NULL;
116 int c, fVerbose = 0;
118 while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
119 {
120 switch ( c )
121 {
122 case 'v':
123 fVerbose ^= 1;
124 break;
125 case 'h':
126 goto usage;
127 default:
128 goto usage;
129 }
130 }
131 if ( argc != globalUtilOptind + 1 )
132 {
133 printf( "Abc_CommandReadPla(): Input file name should be given on the command line.\n" );
134 return 0;
135 }
136 // get the file name
137 pFileName = argv[globalUtilOptind];
138 if ( (pFile = fopen( pFileName, "r" )) == NULL )
139 {
140 Abc_Print( 1, "Cannot open input file \"%s\". ", pFileName );
141 if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".pla", NULL, NULL, NULL, NULL )) )
142 Abc_Print( 1, "Did you mean \"%s\"?", pFileName );
143 Abc_Print( 1, "\n" );
144 return 0;
145 }
146 fclose( pFile );
147
148 // perform reading
149 if ( !strcmp( Extra_FileNameExtension(pFileName), "pla" ) )
150 p = Pla_ReadPla( pFileName );
151 else
152 {
153 printf( "Abc_CommandReadPla(): Unknown file extension.\n" );
154 return 0;
155 }
156 Pla_AbcUpdateMan( pAbc, p );
157 return 0;
158usage:
159 Abc_Print( -2, "usage: |read [-vh] <file_name>\n" );
160 Abc_Print( -2, "\t reads the SOP from a PLA file\n" );
161 Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
162 Abc_Print( -2, "\t-h : print the command usage\n");
163 return 1;
164}
165
177int Abc_CommandWritePla( Abc_Frame_t * pAbc, int argc, char ** argv )
178{
179 Pla_Man_t * p = Pla_AbcGetMan(pAbc);
180 char * pFileName = NULL;
181 int c, fVerbose = 0;
183 while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
184 {
185 switch ( c )
186 {
187 case 'v':
188 fVerbose ^= 1;
189 break;
190 case 'h':
191 goto usage;
192 default:
193 goto usage;
194 }
195 }
196 if ( p == NULL )
197 {
198 Abc_Print( 1, "Abc_CommandWritePla(): There is no current design.\n" );
199 return 0;
200 }
201 if ( argc == globalUtilOptind )
202 pFileName = Extra_FileNameGenericAppend( p->pName, "_out.v" );
203 else if ( argc == globalUtilOptind + 1 )
204 pFileName = argv[globalUtilOptind];
205 else
206 {
207 printf( "Output file name should be given on the command line.\n" );
208 return 0;
209 }
210 Pla_WritePla( p, pFileName );
211 return 0;
212usage:
213 Abc_Print( -2, "usage: |write [-vh]\n" );
214 Abc_Print( -2, "\t writes the SOP into a PLA file\n" );
215 Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
216 Abc_Print( -2, "\t-h : print the command usage\n");
217 return 1;
218}
219
220
232int Abc_CommandPs( Abc_Frame_t * pAbc, int argc, char ** argv )
233{
234 Pla_Man_t * p = Pla_AbcGetMan(pAbc);
235 int fShowMulti = 0;
236 int fShowAdder = 0;
237 int fDistrib = 0;
238 int c, fVerbose = 0;
240 while ( ( c = Extra_UtilGetopt( argc, argv, "madvh" ) ) != EOF )
241 {
242 switch ( c )
243 {
244 case 'm':
245 fShowMulti ^= 1;
246 break;
247 case 'a':
248 fShowAdder ^= 1;
249 break;
250 case 'd':
251 fDistrib ^= 1;
252 break;
253 case 'v':
254 fVerbose ^= 1;
255 break;
256 case 'h':
257 goto usage;
258 default:
259 goto usage;
260 }
261 }
262 if ( p == NULL )
263 {
264 Abc_Print( 1, "Abc_CommandPs(): There is no current design.\n" );
265 return 0;
266 }
267 Pla_ManPrintStats( p, fVerbose );
268 return 0;
269usage:
270 Abc_Print( -2, "usage: |ps [-madvh]\n" );
271 Abc_Print( -2, "\t prints statistics\n" );
272 Abc_Print( -2, "\t-m : toggle printing multipliers [default = %s]\n", fShowMulti? "yes": "no" );
273 Abc_Print( -2, "\t-a : toggle printing adders [default = %s]\n", fShowAdder? "yes": "no" );
274 Abc_Print( -2, "\t-d : toggle printing distrubition [default = %s]\n", fDistrib? "yes": "no" );
275 Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
276 Abc_Print( -2, "\t-h : print the command usage\n");
277 return 1;
278}
279
291int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv )
292{
293 extern void Pla_GenSorter( int nVars );
294 Pla_Man_t * p = NULL;
295 int nInputs = 8;
296 int nOutputs = 1;
297 int nCubes = 20;
298 int Seed = 0;
299 int fSorter = 0;
300 int fPrimes = 0;
301 int c, fVerbose = 0;
303 while ( ( c = Extra_UtilGetopt( argc, argv, "IOPSspvh" ) ) != EOF )
304 {
305 switch ( c )
306 {
307 case 'I':
308 if ( globalUtilOptind >= argc )
309 {
310 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
311 goto usage;
312 }
313 nInputs = atoi(argv[globalUtilOptind]);
315 if ( nInputs < 0 )
316 goto usage;
317 break;
318 case 'O':
319 if ( globalUtilOptind >= argc )
320 {
321 Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
322 goto usage;
323 }
324 nOutputs = atoi(argv[globalUtilOptind]);
326 if ( nOutputs < 0 )
327 goto usage;
328 break;
329 case 'P':
330 if ( globalUtilOptind >= argc )
331 {
332 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
333 goto usage;
334 }
335 nCubes = atoi(argv[globalUtilOptind]);
337 if ( nCubes < 0 )
338 goto usage;
339 break;
340 case 'S':
341 if ( globalUtilOptind >= argc )
342 {
343 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
344 goto usage;
345 }
346 Seed = atoi(argv[globalUtilOptind]);
348 if ( Seed < 0 )
349 goto usage;
350 break;
351 case 's':
352 fSorter ^= 1;
353 break;
354 case 'p':
355 fPrimes ^= 1;
356 break;
357 case 'v':
358 fVerbose ^= 1;
359 break;
360 case 'h':
361 goto usage;
362 default:
363 goto usage;
364 }
365 }
366 if ( fSorter )
367 Pla_GenSorter( nInputs );
368 else if ( fPrimes )
369 p = Pla_ManPrimesDetector( nInputs );
370 else
371 {
372 Gia_ManRandom( 1 );
373 for ( c = 0; c < Seed; c++ )
374 Gia_ManRandom( 0 );
375 p = Pla_ManGenerate( nInputs, nOutputs, nCubes, fVerbose );
376 }
377 Pla_AbcUpdateMan( pAbc, p );
378 return 0;
379usage:
380 Abc_Print( -2, "usage: |gen [-IOPS num] [-spvh]\n" );
381 Abc_Print( -2, "\t generate random or specialized SOP\n" );
382 Abc_Print( -2, "\t-I num : the number of inputs [default = %d]\n", nInputs );
383 Abc_Print( -2, "\t-O num : the number of outputs [default = %d]\n", nOutputs );
384 Abc_Print( -2, "\t-P num : the number of products [default = %d]\n", nCubes );
385 Abc_Print( -2, "\t-S num : ramdom seed (0 <= num <= 1000) [default = %d]\n", Seed );
386 Abc_Print( -2, "\t-s : toggle generating sorter as a PLA file [default = %s]\n", fSorter? "yes": "no" );
387 Abc_Print( -2, "\t-p : toggle generating prime detector [default = %s]\n", fPrimes? "yes": "no" );
388 Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
389 Abc_Print( -2, "\t-h : print the command usage\n");
390 return 1;
391}
392
404int Abc_CommandMerge( Abc_Frame_t * pAbc, int argc, char ** argv )
405{
406 Pla_Man_t * p = Pla_AbcGetMan(pAbc);
407 int c, fMulti = 0, fVerbose = 0;
409 while ( ( c = Extra_UtilGetopt( argc, argv, "mvh" ) ) != EOF )
410 {
411 switch ( c )
412 {
413 case 'm':
414 fMulti ^= 1;
415 break;
416 case 'v':
417 fVerbose ^= 1;
418 break;
419 case 'h':
420 goto usage;
421 default:
422 goto usage;
423 }
424 }
425 if ( p == NULL )
426 {
427 Abc_Print( 1, "Abc_CommandMerge(): There is no current design.\n" );
428 return 0;
429 }
430 // transform
432 return 0;
433usage:
434 Abc_Print( -2, "usage: |merge [-mvh]\n" );
435 Abc_Print( -2, "\t performs distance-1 merge using cube hashing\n" );
436 Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
437 Abc_Print( -2, "\t-h : print the command usage\n");
438 return 1;
439}
440
452int Abc_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv )
453{
454// Pla_Man_t * p = Pla_AbcGetMan(pAbc);
455 int c, nVars = 4, fVerbose = 0;
457 while ( ( c = Extra_UtilGetopt( argc, argv, "Nvh" ) ) != EOF )
458 {
459 switch ( c )
460 {
461 case 'N':
462 if ( globalUtilOptind >= argc )
463 {
464 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
465 goto usage;
466 }
467 nVars = atoi(argv[globalUtilOptind]);
469 if ( nVars < 0 )
470 goto usage;
471 break;
472 case 'v':
473 fVerbose ^= 1;
474 break;
475 case 'h':
476 goto usage;
477 default:
478 goto usage;
479 }
480 }
481/*
482 if ( p == NULL )
483 {
484 Abc_Print( 1, "Abc_CommandTest(): There is no current design.\n" );
485 return 0;
486 }
487*/
488 //Pla_ManFxPerformSimple( nVars );
489 //Pla_ManConvertFromBits( p );
490 //Pla_ManConvertToBits( p );
491 //Pla_ManPerformFxch( p );
492 return 0;
493usage:
494 Abc_Print( -2, "usage: |test [-N num] [-vh]\n" );
495 Abc_Print( -2, "\t experiments with SOPs\n" );
496 Abc_Print( -2, "\t-N num : the number of variables [default = %d]\n", nVars );
497 Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
498 Abc_Print( -2, "\t-h : print the command usage\n");
499 return 1;
500}
501
505
506
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
Definition abcapis.h:38
void Cmd_CommandAdd(Abc_Frame_t *pAbc, const char *sGroup, const char *sName, Cmd_CommandFuncType pFunc, int fChanges)
Definition cmdApi.c:63
Cube * p
Definition exorList.c:222
int globalUtilOptind
char * Extra_FileGetSimilarName(char *pFileNameWrong, char *pS1, char *pS2, char *pS3, char *pS4, char *pS5)
int Extra_UtilGetopt(int argc, char *argv[], const char *optstring)
ABC_DLL void Extra_UtilGetoptReset()
char * Extra_FileNameGenericAppend(char *pBase, char *pSuffix)
char * Extra_FileNameExtension(char *FileName)
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition giaUtil.c:49
usage()
Definition main.c:626
void Pla_End(Abc_Frame_t *pAbc)
Definition plaCom.c:78
void Pla_Init(Abc_Frame_t *pAbc)
FUNCTION DEFINITIONS ///.
Definition plaCom.c:57
void Pla_SetMan(Abc_Frame_t *pAbc, Pla_Man_t *p)
Definition plaCom.c:94
ABC_NAMESPACE_IMPL_START void Pla_GenSorter(int nVars)
DECLARATIONS ///.
Definition plaMan.c:44
int Pla_ManDist1Merge(Pla_Man_t *p)
DECLARATIONS ///.
Definition plaMerge.c:44
Pla_Man_t * Pla_ReadPla(char *pFileName)
Definition plaRead.c:186
struct Pla_Man_t_ Pla_Man_t
Definition pla.h:63
void Pla_WritePla(Pla_Man_t *p, char *pFileName)
Definition plaWrite.c:88
Pla_Man_t * Pla_ManGenerate(int nIns, int nOuts, int nCubes, int fVerbose)
Definition plaMan.c:168
Pla_Man_t * Pla_ManPrimesDetector(int nVars)
Definition plaMan.c:128
int strcmp()