abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
literal.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [literal.h]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [RPO]
8 
9  Synopsis [Literal structure]
10 
11  Author [Mayler G. A. Martins / Vinicius Callegaro]
12 
13  Affiliation [UFRGS]
14 
15  Date [Ver. 1.0. Started - May 08, 2013.]
16 
17  Revision [$Id: literal.h,v 1.00 2013/05/08 00:00:00 mgamartins Exp $]
18 
19  ***********************************************************************/
20 
21 #ifndef ABC__bool__rpo__literal_h
22 #define ABC__bool__rpo__literal_h
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// INCLUDES ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include "bool/kit/kit.h"
31 #include "misc/vec/vec.h"
32 #include "misc/util/abc_global.h"
33 
35 
36 
37 ////////////////////////////////////////////////////////////////////////
38 /// PARAMETERS ///
39 ////////////////////////////////////////////////////////////////////////
40 
41 // associations
42 typedef enum {
43  LIT_NONE = 0, // 0: unknown
44  LIT_AND, // 1: AND association
45  LIT_OR, // 2: OR association
46  LIT_XOR // 3: XOR association (not used yet)
47 } Operator_t;
48 
49 
50 typedef struct Literal_t_ Literal_t;
51 
52 struct Literal_t_ {
53  unsigned * transition;
54  unsigned * function;
56 };
57 
58 
59 ////////////////////////////////////////////////////////////////////////
60 /// FUNCTION DEFINITIONS ///
61 ////////////////////////////////////////////////////////////////////////
62 
63 /**Function*************************************************************
64 
65  Synopsis [Compute the positive transition]
66 
67  Description [The inputs are a function, the number of variables and a variable index and the output is a function]
68 
69  SideEffects [Should this function be in kitTruth.c ?]
70 
71  SeeAlso []
72 //
73 ***********************************************************************/
74 
75 static inline void Lit_TruthPositiveTransition( unsigned * pIn, unsigned * pOut, int nVars, int varIdx )
76 {
77  unsigned * cof0 = ABC_ALLOC (unsigned, Kit_TruthWordNum(nVars) );
78  unsigned * cof1 = ABC_ALLOC (unsigned, Kit_TruthWordNum(nVars) );
79  unsigned * ncof0;
80  Kit_TruthCofactor0New(cof0, pIn,nVars,varIdx);
81  Kit_TruthCofactor1New(cof1, pIn,nVars,varIdx);
82  ncof0 = ABC_ALLOC (unsigned, Kit_TruthWordNum(nVars) );
83  Kit_TruthNot(ncof0,cof0,nVars);
84  Kit_TruthAnd(pOut,ncof0,cof1, nVars);
85  ABC_FREE(cof0);
86  ABC_FREE(ncof0);
87  ABC_FREE(cof1);
88 }
89 
90 
91 /**Function*************************************************************
92 
93  Synopsis [Compute the negative transition]
94 
95  Description [The inputs are a function, the number of variables and a variable index and the output is a function]
96 
97  SideEffects [Should this function be in kitTruth.c ?]
98 
99  SeeAlso []
100 
101 ***********************************************************************/
102 
103 static inline void Lit_TruthNegativeTransition( unsigned * pIn, unsigned * pOut, int nVars, int varIdx )
104 {
105  unsigned * cof0 = ABC_ALLOC (unsigned, Kit_TruthWordNum(nVars) );
106  unsigned * cof1 = ABC_ALLOC (unsigned, Kit_TruthWordNum(nVars) );
107  unsigned * ncof1;
108  Kit_TruthCofactor0New(cof0, pIn,nVars,varIdx);
109  Kit_TruthCofactor1New(cof1, pIn,nVars,varIdx);
110  ncof1 = ABC_ALLOC (unsigned, Kit_TruthWordNum(nVars) );
111  Kit_TruthNot(ncof1,cof1,nVars);
112  Kit_TruthAnd(pOut,ncof1,cof0,nVars);
113  ABC_FREE(cof0);
114  ABC_FREE(cof1);
115  ABC_FREE(ncof1);
116 }
117 
118 
119 /**Function*************************************************************
120 
121  Synopsis [Create a literal given a polarity ]
122 
123  Description [The inputs are the function, index and its polarity and a the output is a literal]
124 
125  SideEffects []
126 
127  SeeAlso []
128 
129  ***********************************************************************/
130 
131 static inline Literal_t* Lit_Alloc(unsigned* pTruth, int nVars, int varIdx, char pol) {
132  unsigned * transition;
133  unsigned * function;
134  Vec_Str_t * exp;
135  Literal_t* lit;
136  assert(pol == '+' || pol == '-');
137  transition = ABC_ALLOC(unsigned, Kit_TruthWordNum(nVars));
138  if (pol == '+') {
139  Lit_TruthPositiveTransition(pTruth, transition, nVars, varIdx);
140  } else {
141  Lit_TruthNegativeTransition(pTruth, transition, nVars, varIdx);
142  }
143  if (!Kit_TruthIsConst0(transition,nVars)) {
144  function = ABC_ALLOC(unsigned, Kit_TruthWordNum(nVars));
145  Kit_TruthIthVar(function, nVars, varIdx);
146  //Abc_Print(-2, "Allocating function %X %d %c \n", *function, varIdx, pol);
147  exp = Vec_StrAlloc(5);
148  if (pol == '-') {
149  Kit_TruthNot(function, function, nVars);
150  Vec_StrPutC(exp, '!');
151  }
152  Vec_StrPutC(exp, (char)('a' + varIdx));
153  Vec_StrPutC(exp, '\0');
154  lit = ABC_ALLOC(Literal_t, 1);
155  lit->function = function;
156  lit->transition = transition;
157  lit->expression = exp;
158  return lit;
159  } else {
160  ABC_FREE(transition); // free the function.
161  return NULL;
162  }
163 }
164 
165 
166 /**Function*************************************************************
167 
168  Synopsis [Group 2 literals using AND or OR]
169 
170  Description []
171 
172  SideEffects []
173 
174  SeeAlso []
175 
176  ***********************************************************************/
177 
178 static inline Literal_t* Lit_GroupLiterals(Literal_t* lit1, Literal_t* lit2, Operator_t op, int nVars) {
179  unsigned * newFunction = ABC_ALLOC(unsigned, Kit_TruthWordNum(nVars));
180  unsigned * newTransition = ABC_ALLOC(unsigned, Kit_TruthWordNum(nVars));
181  Vec_Str_t * newExp = Vec_StrAlloc(lit1->expression->nSize + lit2->expression->nSize + 3);
182  Literal_t* newLiteral;
183  char opChar = '%';
184  switch (op) {
185  case LIT_AND:
186  {
187  //Abc_Print(-2, "Grouping AND %X %X \n", *lit1->function, *lit2->function);
188  Kit_TruthAnd(newFunction, lit1->function, lit2->function, nVars);
189  opChar = '*';
190  break;
191  }
192  case LIT_OR:
193  {
194  //Abc_Print(-2, "Grouping OR %X %X \n", *lit1->function, *lit2->function);
195  Kit_TruthOr(newFunction, lit1->function, lit2->function, nVars);
196  opChar = '+';
197  break;
198  }
199  default:
200  {
201  Abc_Print(-2, "Lit_GroupLiterals with op not defined.");
202  //TODO Call ABC Abort
203  }
204  }
205 
206  Kit_TruthOr(newTransition, lit1->transition, lit2->transition, nVars);
207  // create a new expression.
208  Vec_StrPutC(newExp, '(');
209  Vec_StrAppend(newExp, lit1->expression->pArray);
210  //Vec_StrPop(newExp); // pop the \0
211  Vec_StrPutC(newExp, opChar);
212  Vec_StrAppend(newExp, lit2->expression->pArray);
213  //Vec_StrPop(newExp); // pop the \0
214  Vec_StrPutC(newExp, ')');
215  Vec_StrPutC(newExp, '\0');
216 
217  newLiteral = ABC_ALLOC(Literal_t, 1);
218  newLiteral->function = newFunction;
219  newLiteral->transition = newTransition;
220  newLiteral->expression = newExp;
221  return newLiteral;
222 }
223 
224 
225 /**Function*************************************************************
226 
227  Synopsis [Create a const literal ]
228 
229  Description []
230 
231  SideEffects []
232 
233  SeeAlso []
234 
235  ***********************************************************************/
236 
237 static inline Literal_t* Lit_CreateLiteralConst(unsigned* pTruth, int nVars, int constant) {
238  Vec_Str_t * exp = Vec_StrAlloc(3);
239  Literal_t* lit;
240  Vec_StrPutC(exp, (char)('0' + constant));
241  Vec_StrPutC(exp, '\0');
242  lit = ABC_ALLOC(Literal_t, 1);
243  lit->expression = exp;
244  lit->function = pTruth;
245  lit->transition = pTruth; // wrong but no effect ###
246  return lit;
247 }
248 
249 static inline Literal_t* Lit_Copy(Literal_t* lit, int nVars) {
250  Literal_t* newLit = ABC_ALLOC(Literal_t,1);
251  newLit->function = ABC_ALLOC(unsigned, Kit_TruthWordNum(nVars));
252  Kit_TruthCopy(newLit->function,lit->function,nVars);
253  newLit->transition = ABC_ALLOC(unsigned, Kit_TruthWordNum(nVars));
254  Kit_TruthCopy(newLit->transition,lit->transition,nVars);
255  newLit->expression = Vec_StrDup(lit->expression);
256 // Abc_Print(-2,"Copying: %s\n",newLit->expression->pArray);
257  return newLit;
258 }
259 
260 static inline void Lit_PrintTT(unsigned* tt, int nVars) {
261  int w;
262  for(w=nVars-1; w>=0; w--) {
263  Abc_Print(-2, "%08X", tt[w]);
264  }
265 }
266 
267 static inline void Lit_PrintExp(Literal_t* lit) {
268  Abc_Print(-2, "%s", lit->expression->pArray);
269 }
270 
271 /**Function*************************************************************
272 
273  Synopsis [Delete the literal ]
274 
275  Description []
276 
277  SideEffects []
278 
279  SeeAlso []
280 
281  ***********************************************************************/
282 
283 static inline void Lit_Free(Literal_t * lit) {
284  if(lit == NULL) {
285  return;
286  }
287 // Abc_Print(-2,"Freeing: %s\n",lit->expression->pArray);
288  ABC_FREE(lit->function);
289  ABC_FREE(lit->transition);
290  Vec_StrFree(lit->expression);
291  ABC_FREE(lit);
292 }
293 
295 
296 #endif /* LITERAL_H */
297 
static void Lit_TruthNegativeTransition(unsigned *pIn, unsigned *pOut, int nVars, int varIdx)
Definition: literal.h:103
Definition: literal.h:45
static int Kit_TruthWordNum(int nVars)
Definition: kit.h:224
static void Lit_TruthPositiveTransition(unsigned *pIn, unsigned *pOut, int nVars, int varIdx)
FUNCTION DEFINITIONS ///.
Definition: literal.h:75
static Literal_t * Lit_Alloc(unsigned *pTruth, int nVars, int varIdx, char pol)
Definition: literal.h:131
static void Vec_StrPutC(Vec_Str_t *vOut, char c)
Definition: vecStr.h:910
static Literal_t * Lit_Copy(Literal_t *lit, int nVars)
Definition: literal.h:249
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int Kit_TruthIsConst0(unsigned *pIn, int nVars)
Definition: kit.h:315
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
Vec_Str_t * expression
Definition: literal.h:55
static void Lit_PrintExp(Literal_t *lit)
Definition: literal.h:267
static void Lit_Free(Literal_t *lit)
Definition: literal.h:283
int lit
Definition: satVec.h:130
static void Kit_TruthAnd(unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: kit.h:379
void Kit_TruthCofactor0New(unsigned *pOut, unsigned *pIn, int nVars, int iVar)
Definition: kitTruth.c:521
static void Vec_StrAppend(Vec_Str_t *p, const char *pString)
Definition: vecStr.h:645
char * pArray
Definition: bblif.c:51
static Literal_t * Lit_CreateLiteralConst(unsigned *pTruth, int nVars, int constant)
Definition: literal.h:237
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
static Literal_t * Lit_GroupLiterals(Literal_t *lit1, Literal_t *lit2, Operator_t op, int nVars)
Definition: literal.h:178
void Kit_TruthCofactor1New(unsigned *pOut, unsigned *pIn, int nVars, int iVar)
Definition: kitTruth.c:573
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
static void Kit_TruthNot(unsigned *pOut, unsigned *pIn, int nVars)
Definition: kit.h:373
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
static void Kit_TruthIthVar(unsigned *pTruth, int nVars, int iVar)
Definition: kit.h:473
unsigned * function
Definition: literal.h:54
unsigned * transition
Definition: literal.h:53
#define ABC_FREE(obj)
Definition: abc_global.h:232
int nSize
Definition: bblif.c:50
static void Lit_PrintTT(unsigned *tt, int nVars)
Definition: literal.h:260
static void Kit_TruthCopy(unsigned *pOut, unsigned *pIn, int nVars)
Definition: kit.h:355
#define assert(ex)
Definition: util_old.h:213
static Vec_Str_t * Vec_StrDup(Vec_Str_t *pVec)
Definition: vecStr.h:158
Operator_t
INCLUDES ///.
Definition: literal.h:42
static void Kit_TruthOr(unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: kit.h:385