ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
msatRead.c
Go to the documentation of this file.
1
20
21#include "msatInt.h"
22
24
25
29
30static char * Msat_FileRead( FILE * pFile );
31
35
47char * Msat_FileRead( FILE * pFile )
48{
49 int nFileSize;
50 char * pBuffer;
51 int RetValue;
52 // get the file size, in bytes
53 fseek( pFile, 0, SEEK_END );
54 nFileSize = ftell( pFile );
55 // move the file current reading position to the beginning
56 rewind( pFile );
57 // load the contents of the file into memory
58 pBuffer = ABC_ALLOC( char, nFileSize + 3 );
59 RetValue = fread( pBuffer, nFileSize, 1, pFile );
60 // terminate the string with '\0'
61 pBuffer[ nFileSize + 0] = '\n';
62 pBuffer[ nFileSize + 1] = '\0';
63 return pBuffer;
64}
65
77static void Msat_ReadWhitespace( char ** pIn )
78{
79 while ((**pIn >= 9 && **pIn <= 13) || **pIn == 32)
80 (*pIn)++;
81}
82
94static void Msat_ReadNotWhitespace( char ** pIn )
95{
96 while ( !((**pIn >= 9 && **pIn <= 13) || **pIn == 32) )
97 (*pIn)++;
98}
99
111static void skipLine( char ** pIn )
112{
113 while ( 1 )
114 {
115 if (**pIn == 0)
116 return;
117 if (**pIn == '\n')
118 {
119 (*pIn)++;
120 return;
121 }
122 (*pIn)++;
123 }
124}
125
137static int Msat_ReadInt( char ** pIn )
138{
139 int val = 0;
140 int neg = 0;
141
142 Msat_ReadWhitespace( pIn );
143 if ( **pIn == '-' )
144 neg = 1,
145 (*pIn)++;
146 else if ( **pIn == '+' )
147 (*pIn)++;
148 if ( **pIn < '0' || **pIn > '9' )
149 fprintf(stderr, "PARSE ERROR! Unexpected char: %c\n", **pIn),
150 exit(1);
151 while ( **pIn >= '0' && **pIn <= '9' )
152 val = val*10 + (**pIn - '0'),
153 (*pIn)++;
154 return neg ? -val : val;
155}
156
168static void Msat_ReadClause( char ** pIn, Msat_Solver_t * p, Msat_IntVec_t * pLits )
169{
170 int nVars = Msat_SolverReadVarNum( p );
171 int parsed_lit, var, sign;
172
173 Msat_IntVecClear( pLits );
174 while ( 1 )
175 {
176 parsed_lit = Msat_ReadInt(pIn);
177 if ( parsed_lit == 0 )
178 break;
179 var = abs(parsed_lit) - 1;
180 sign = (parsed_lit > 0);
181 if ( var >= nVars )
182 {
183 printf( "Variable %d is larger than the number of allocated variables (%d).\n", var+1, nVars );
184 exit(1);
185 }
186 Msat_IntVecPush( pLits, MSAT_VAR2LIT(var, !sign) );
187 }
188}
189
201static int Msat_ReadDimacs( char * pText, Msat_Solver_t ** pS, int fVerbose )
202{
203 Msat_Solver_t * p = NULL; // Suppress "might be used uninitialized"
204 Msat_IntVec_t * pLits = NULL; // Suppress "might be used uninitialized"
205 char * pIn = pText;
206 int nVars, nClas;
207 while ( 1 )
208 {
209 Msat_ReadWhitespace( &pIn );
210 if ( *pIn == 0 )
211 break;
212 else if ( *pIn == 'c' )
213 skipLine( &pIn );
214 else if ( *pIn == 'p' )
215 {
216 pIn++;
217 Msat_ReadWhitespace( &pIn );
218 Msat_ReadNotWhitespace( &pIn );
219
220 nVars = Msat_ReadInt( &pIn );
221 nClas = Msat_ReadInt( &pIn );
222 skipLine( &pIn );
223 // start the solver
224 p = Msat_SolverAlloc( nVars, 1, 1, 1, 1, 0 );
225 Msat_SolverClean( p, nVars );
226 Msat_SolverSetVerbosity( p, fVerbose );
227 // allocate the vector
228 pLits = Msat_IntVecAlloc( nVars );
229 }
230 else
231 {
232 if ( p == NULL )
233 {
234 printf( "There is no parameter line.\n" );
235 exit(1);
236 }
237 Msat_ReadClause( &pIn, p, pLits );
238 if ( !Msat_SolverAddClause( p, pLits ) )
239 return 0;
240 }
241 }
242 Msat_IntVecFree( pLits );
243 *pS = p;
244 return Msat_SolverSimplifyDB( p );
245}
246
258int Msat_SolverParseDimacs( FILE * pFile, Msat_Solver_t ** p, int fVerbose )
259{
260 char * pText;
261 int Value;
262 pText = Msat_FileRead( pFile );
263 Value = Msat_ReadDimacs( pText, p, fVerbose );
264 ABC_FREE( pText );
265 return Value;
266}
267
271
272
274
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Cube * p
Definition exorList.c:222
int Msat_SolverParseDimacs(FILE *pFile, Msat_Solver_t **p, int fVerbose)
GLOBAL VARIABLES ///.
Definition msatRead.c:258
int Msat_SolverAddClause(Msat_Solver_t *p, Msat_IntVec_t *pLits)
void Msat_SolverSetVerbosity(Msat_Solver_t *p, int fVerbose)
struct Msat_IntVec_t_ Msat_IntVec_t
Definition msat.h:45
#define MSAT_VAR2LIT(v, s)
Definition msat.h:56
int Msat_SolverReadVarNum(Msat_Solver_t *p)
FUNCTION DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Msat_Solver_t_ Msat_Solver_t
INCLUDES ///.
Definition msat.h:42
int Msat_SolverSimplifyDB(Msat_Solver_t *p)
Msat_IntVec_t * Msat_IntVecAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition msatVec.c:48
Msat_Solver_t * Msat_SolverAlloc(int nVars, double dClaInc, double dClaDecay, double dVarInc, double dVarDecay, int fVerbose)
void Msat_SolverClean(Msat_Solver_t *p, int nVars)
void Msat_IntVecFree(Msat_IntVec_t *p)
Definition msatVec.c:160
void Msat_IntVecClear(Msat_IntVec_t *p)
Definition msatVec.c:335
void Msat_IntVecPush(Msat_IntVec_t *p, int Entry)
Definition msatVec.c:351
bool sign(Lit p)
Definition SolverTypes.h:63
unsigned short var
Definition giaNewBdd.h:35
VOID_HACK rewind()
VOID_HACK exit()
#define SEEK_END
Definition zconf.h:392