@@ -31,12 +31,6 @@ private ParseGenerateAndReparse() {}
3131
3232 public static void main (String [] args )
3333 throws InvalidConfigurationException , InterruptedException , SolverException {
34- String expectedResult =
35- "(declare-const a (_ FloatingPoint 8 24))\n "
36- + "(declare-const b (_ FloatingPoint 8 24))\n "
37- + "(declare-const min (_ FloatingPoint 8 24))\n "
38- + "(assert (fp.eq (fp.min a b) min))\n " ;
39- System .out .println (nativeZ3ParseAndIsUnsat (expectedResult ));
4034 if (args .length < 3 ) {
4135 System .err .println ("Usage: java ParseGenerateAndReparseTest <smt2-file> <solver> <mode>" );
4236 System .exit (1 );
@@ -84,15 +78,15 @@ public static void main(String[] args)
8478 Generator .assembleConstraint (formula );
8579 String regenerated = Generator .getSMTLIB2String ();
8680 // NATIVE PARSE
87- checkResult (nativeZ3ParseAndIsUnsat ( regenerated ));
81+ checkResult (checkNativeParseAndIsUnsat ( solver , regenerated ));
8882 } catch (Exception pE ) {
8983 printError (pE );
9084 }
9185 }
9286 if (mode .equals ("NATIVE" )) {
9387 try {
9488 // NATIVE PARSE
95- checkResult (nativeZ3ParseAndIsUnsat ( smt2FilePath ));
89+ checkResult (checkNativeParseAndIsUnsat ( solver , smt2FilePath ));
9690 } catch (Exception pE ) {
9791 printError (pE );
9892 }
@@ -121,6 +115,14 @@ public static void checkResult(boolean isUnsat) {
121115 System .out .println ("SUCCESS: isUnsat = " + isUnsat );
122116 System .exit (0 );
123117 }
118+ public static boolean checkNativeParseAndIsUnsat (Solvers solver , String smt2 )
119+ throws SolverException , InterruptedException , InvalidConfigurationException {
120+ switch (solver ){
121+ case Z3 : return nativeZ3ParseAndIsUnsat (smt2 );
122+ case MATHSAT5 : return nativeMathSatParseAndIsUnsat (smt2 );
123+ }
124+ throw new SolverException ("Unsupported solver: " + solver );
125+ }
124126
125127 public static boolean nativeZ3ParseAndIsUnsat (String smt2 ) {
126128 try (Context ctx = new Context ()) {
@@ -131,6 +133,14 @@ public static boolean nativeZ3ParseAndIsUnsat(String smt2) {
131133 }
132134 }
133135
136+ public static boolean nativeMathSatParseAndIsUnsat (String smt2 )
137+ throws InvalidConfigurationException , InterruptedException , SolverException {
138+ SolverContext mathsat = SolverContextFactory .createSolverContext (Solvers .MATHSAT5 );
139+ ProverEnvironment prover = mathsat .newProverEnvironment (ProverOptions .GENERATE_MODELS );
140+ prover .addConstraint (mathsat .getFormulaManager ().parse (smt2 ));
141+ return prover .isUnsat ();
142+ }
143+
134144 public static void printError (Exception pE ) {
135145 System .out .println ("ERROR: " );
136146 pE .printStackTrace ();
0 commit comments