33#define AMAP_EQN_SYM_OPEN '('
34#define AMAP_EQN_SYM_CLOSE ')'
35#define AMAP_EQN_SYM_CONST0 '0'
36#define AMAP_EQN_SYM_CONST1 '1'
37#define AMAP_EQN_SYM_NEG '!'
38#define AMAP_EQN_SYM_NEGAFT '\''
39#define AMAP_EQN_SYM_AND '*'
40#define AMAP_EQN_SYM_AND2 '&'
41#define AMAP_EQN_SYM_XOR '^'
42#define AMAP_EQN_SYM_OR '+'
43#define AMAP_EQN_SYM_OR2 '|'
46#define AMAP_EQN_OPER_NEG 10
47#define AMAP_EQN_OPER_AND 9
48#define AMAP_EQN_OPER_XOR 8
49#define AMAP_EQN_OPER_OR 7
50#define AMAP_EQN_OPER_MARK 1
53#define AMAP_EQN_FLAG_START 1
54#define AMAP_EQN_FLAG_VAR 2
55#define AMAP_EQN_FLAG_OPER 3
56#define AMAP_EQN_FLAG_ERROR 4
77 gArg2 = (
Hop_Obj_t *)Vec_PtrPop( pStackFn );
78 gArg1 = (
Hop_Obj_t *)Vec_PtrPop( pStackFn );
80 gFunc =
Hop_And( pMan, gArg1, gArg2 );
82 gFunc =
Hop_Or( pMan, gArg1, gArg2 );
84 gFunc =
Hop_Exor( pMan, gArg1, gArg2 );
90 Vec_PtrPush( pStackFn, gFunc );
112 char * pTemp, * pName;
113 int nParans, fFound, Flag;
114 int Oper, Oper1, Oper2;
119 for ( pTemp = pFormInit; *pTemp; pTemp++ )
122 else if ( *pTemp ==
')' )
126 fprintf( pOutput,
"Amap_ParseFormula(): Different number of opening and closing parentheses ().\n" );
132 sprintf( pFormula,
"(%s)", pFormInit );
135 pStackFn = Vec_PtrAlloc( 100 );
136 pStackOp = Vec_IntAlloc( 100 );
139 for ( pTemp = pFormula; *pTemp; pTemp++ )
150 Vec_PtrPush( pStackFn, Hop_ManConst0(pMan) );
153 fprintf( pOutput,
"Amap_ParseFormula(): No operation symbol before constant 0.\n" );
160 Vec_PtrPush( pStackFn, Hop_ManConst1(pMan) );
163 fprintf( pOutput,
"Amap_ParseFormula(): No operation symbol before constant 1.\n" );
180 fprintf( pOutput,
"Amap_ParseFormula(): No variable is specified before the negation suffix.\n" );
185 Vec_PtrPush( pStackFn, Hop_Not( (
Hop_Obj_t *)Vec_PtrPop(pStackFn) ) );
194 fprintf( pOutput,
"Amap_ParseFormula(): There is no variable before AND, EXOR, or OR.\n" );
219 if ( Vec_IntSize( pStackOp ) != 0 )
223 if ( Vec_IntSize( pStackOp ) == 0 )
225 fprintf( pOutput,
"Amap_ParseFormula(): There is no opening parenthesis\n" );
229 Oper = Vec_IntPop( pStackOp );
236 fprintf( pOutput,
"Amap_ParseFormula(): Unknown operation\n" );
238 Vec_PtrFreeP( &pStackFn );
239 Vec_IntFreeP( &pStackOp );
246 fprintf( pOutput,
"Amap_ParseFormula(): There is no opening parenthesis\n" );
257 for ( i = 0; pTemp[i] &&
258 pTemp[i] !=
' ' && pTemp[i] !=
'\t' && pTemp[i] !=
'\r' && pTemp[i] !=
'\n' &&
265 fprintf( pOutput,
"Amap_ParseFormula(): The negation sign or an opening parenthesis inside the variable name.\n" );
273 if (
strncmp(pTemp, pName, i) == 0 &&
strlen(pName) == (
unsigned)i )
281 fprintf( pOutput,
"Amap_ParseFormula(): The parser cannot find var \"%s\" in the input var list of gate \"%s\".\n", pTemp, pGateName );
296 Vec_PtrPush( pStackFn,
Hop_IthVar( pMan, v ) );
308 if ( Vec_IntSize( pStackOp ) == 0 )
310 Oper = Vec_IntPop( pStackOp );
313 Vec_IntPush( pStackOp, Oper );
318 Vec_PtrPush( pStackFn, Hop_Not((
Hop_Obj_t *)Vec_PtrPop(pStackFn)) );
325 Oper1 = Vec_IntPop( pStackOp );
326 if ( Vec_IntSize( pStackOp ) == 0 )
328 Vec_IntPush( pStackOp, Oper1 );
331 Oper2 = Vec_IntPop( pStackOp );
332 if ( Oper2 >= Oper1 )
336 fprintf( pOutput,
"Amap_ParseFormula(): Unknown operation\n" );
338 Vec_PtrFreeP( &pStackFn );
339 Vec_IntFreeP( &pStackOp );
342 Vec_IntPush( pStackOp, Oper1 );
346 Vec_IntPush( pStackOp, Oper2 );
347 Vec_IntPush( pStackOp, Oper1 );
355 if ( Vec_PtrSize(pStackFn) != 0 )
357 gFunc = (
Hop_Obj_t *)Vec_PtrPop(pStackFn);
358 if ( Vec_PtrSize(pStackFn) == 0 )
359 if ( Vec_IntSize( pStackOp ) == 0 )
363 Vec_PtrFreeP( &pStackFn );
364 Vec_IntFreeP( &pStackOp );
368 fprintf( pOutput,
"Amap_ParseFormula(): Something is left in the operation stack\n" );
370 fprintf( pOutput,
"Amap_ParseFormula(): Something is left in the function stack\n" );
373 fprintf( pOutput,
"Amap_ParseFormula(): The input string is empty\n" );
376 Vec_PtrFreeP( &pStackFn );
377 Vec_IntFreeP( &pStackOp );
405 printf(
"Gates with more than %d inputs will be ignored.\n",
AMAP_MAXINS );
406 vTruth = Vec_IntAlloc( 1 << 16 );
407 vNames = Vec_PtrAlloc( 100 );
412 if ( pGate->
nPins == 0 )
418 pGate->
pFunc[0] = ~0;
421 printf(
"Cannot parse formula \"%s\" of gate \"%s\" with no pins.\n", pGate->
pForm, pGate->
pName );
428 Vec_PtrClear( vNames );
430 Vec_PtrPush( vNames, pPin->
pName );
438 printf(
"Skipping gate \"%s\" because its output \"%s\" does not depend on all input variables.\n", pGate->
pName, pGate->
pForm );
442 memcpy( pGate->
pFunc, pTruth,
sizeof(
unsigned)*Abc_TruthWordNum(pGate->
nPins) );
444 Vec_PtrFree( vNames );
445 Vec_IntFree( vTruth );
447 return i == Vec_PtrSize(
p->vGates);
471 ABC_PRT(
"Total time", Abc_Clock() - clk );
#define ABC_ALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
char * Aig_MmFlexEntryFetch(Aig_MmFlex_t *p, int nBytes)
#define Amap_GateForEachPin(pGate, pPin)
int Amap_LibNumPinsMax(Amap_Lib_t *p)
Amap_Lib_t * Amap_LibReadFile(char *pFileName, int fVerbose)
#define AMAP_STRING_CONST1
struct Amap_Gat_t_ Amap_Gat_t
#define AMAP_STRING_CONST0
#define AMAP_MAXINS
INCLUDES ///.
struct Amap_Pin_t_ Amap_Pin_t
BASIC TYPES ///.
Hop_Obj_t * Amap_ParseFormula(FILE *pOutput, char *pFormInit, Vec_Ptr_t *vVarNames, Hop_Man_t *pMan, char *pGateName)
#define AMAP_EQN_SYM_NEGAFT
#define AMAP_EQN_SYM_CONST0
#define AMAP_EQN_FLAG_ERROR
Hop_Obj_t * Amap_ParseFormulaOper(Hop_Man_t *pMan, Vec_Ptr_t *pStackFn, int Oper)
FUNCTION DEFINITIONS ///.
#define AMAP_EQN_FLAG_START
#define AMAP_EQN_SYM_OPEN
DECLARATIONS ///.
int Amap_LibParseEquations(Amap_Lib_t *p, int fVerbose)
#define AMAP_EQN_OPER_MARK
#define AMAP_EQN_OPER_XOR
#define AMAP_EQN_FLAG_OPER
#define AMAP_EQN_FLAG_VAR
#define AMAP_EQN_OPER_NEG
void Amap_LibParseTest(char *pFileName)
#define AMAP_EQN_OPER_AND
#define AMAP_EQN_SYM_CLOSE
#define AMAP_EQN_SYM_AND2
#define AMAP_EQN_SYM_CONST1
typedefABC_NAMESPACE_HEADER_START struct Amap_Lib_t_ Amap_Lib_t
INCLUDES ///.
void Amap_LibFree(Amap_Lib_t *p)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Hop_Obj_t * Hop_Exor(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
void Hop_ManStop(Hop_Man_t *p)
unsigned * Hop_ManConvertAigToTruth(Hop_Man_t *p, Hop_Obj_t *pRoot, int nVars, Vec_Int_t *vTruth, int fMsbFirst)
Hop_Obj_t * Hop_Or(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Hop_Man_t * Hop_ManStart()
DECLARATIONS ///.
struct Hop_Obj_t_ Hop_Obj_t
int Kit_TruthSupportSize(unsigned *pTruth, int nVars)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.