ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
literal.h
Go to the documentation of this file.
1
20
21#ifndef ABC__bool__rpo__literal_h
22#define ABC__bool__rpo__literal_h
23
27
28#include <stdio.h>
29#include <stdlib.h>
30#include "bool/kit/kit.h"
31#include "misc/vec/vec.h"
33
35
36
40
41// associations
42typedef 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)
48
49
50typedef struct Literal_t_ Literal_t;
51
52struct Literal_t_ {
53 unsigned * transition;
54 unsigned * function;
56};
57
58
62
74
75static 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
102
103static 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
130
131static 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
177
178static 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
236
237static 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
249static 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
260static 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
267static inline void Lit_PrintExp(Literal_t* lit) {
268 Abc_Print(-2, "%s", lit->expression->pArray);
269}
270
282
283static 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
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
struct Literal_t_ Literal_t
Definition literal.h:50
Operator_t
INCLUDES ///.
Definition literal.h:42
@ LIT_OR
Definition literal.h:45
@ LIT_XOR
Definition literal.h:46
@ LIT_NONE
Definition literal.h:43
@ LIT_AND
Definition literal.h:44
void Kit_TruthCofactor1New(unsigned *pOut, unsigned *pIn, int nVars, int iVar)
Definition kitTruth.c:573
void Kit_TruthCofactor0New(unsigned *pOut, unsigned *pIn, int nVars, int iVar)
Definition kitTruth.c:521
int lit
Definition satVec.h:130
unsigned * function
Definition literal.h:54
unsigned * transition
Definition literal.h:53
Vec_Str_t * expression
Definition literal.h:55
int nSize
Definition bblif.c:50
char * pArray
Definition bblif.c:51
#define assert(ex)
Definition util_old.h:213