00001 package edu.ksu.cis.bandera.spin;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 import java.util.*;
00081 import edu.ksu.cis.bandera.checker.*;
00082
00083 public class SpinOptions extends CheckerOption {
00084 boolean Safety = false;
00085 boolean AcceptanceCycles = true;
00086 boolean ApplyNeverClaim = true;
00087 public static final int Exhaustive = 0;
00088 public static final int SuperTrace = 1;
00089 public static final int HashCompact = 2;
00090 int SearchMode = Exhaustive;
00091 int StopAtError = 1;
00092 boolean SaveAllTrails = true;
00093 boolean FindShortestTrail = false;
00094 int MemoryLimit = 128;
00095 int MemoryCount = 31;
00096 int VectorSize = 1024;
00097 int SpaceEstimate = 500;
00098 int SearchDepth = 10000;
00099 boolean POReduction = false;
00100 boolean Compression = false;
00101 boolean ResourceBounded = true;
00102 public SpinOptions() {
00103 }
00104 public SpinOptions(String opt) {
00105 parseOptions(opt);
00106 }
00107 public String compileOptions() {
00108 String co = compileOptions2();
00109 if (!ResourceBounded) co = co + " -DNORESOURCEBOUNDED";
00110 return co;
00111 }
00112 public String compileOptions2() {
00113 String co;
00114 switch (SearchMode) {
00115 case SuperTrace :
00116 co = "-DBITSTATE -DMEMCNT=" + MemoryCount + " -DVECTORSZ=" + VectorSize;
00117 break;
00118 case HashCompact :
00119 co = "-DHC -DMEMCNT=" + MemoryCount + " -DVECTORSZ=" + VectorSize;
00120 break;
00121 default :
00122 co = "-DMEMCNT=" + MemoryCount + " -DVECTORSZ=" + VectorSize;
00123 break;
00124 }
00125 if (Safety) co = co + " -DSAFETY";
00126 if (!ApplyNeverClaim) co = co + " -DNOCLAIM";
00127 if (!POReduction) co = co + " -DNOREDUCE";
00128 if (Compression) co = co + " -DCOLLAPSE";
00129 return co;
00130 }
00131
00132
00133
00134
00135 public int getMemoryCount() {
00136 return MemoryCount;
00137 }
00138
00139
00140
00141
00142 public int getMemoryLimit() {
00143 return MemoryLimit;
00144 }
00145
00146
00147
00148
00149 public boolean getResourceBounded() {
00150 return ResourceBounded;
00151 }
00152
00153
00154
00155
00156 public int getSearchDepth() {
00157 return SearchDepth;
00158 }
00159
00160
00161
00162
00163 public int getSpaceEstimate() {
00164 return SpaceEstimate;
00165 }
00166
00167
00168
00169
00170 public int getStopAtError() {
00171 return StopAtError;
00172 }
00173
00174
00175
00176
00177 public int getVectorSize() {
00178 return VectorSize;
00179 }
00180 int log2(int x) {
00181 int log = 0;
00182 for (int total = 1; total < x; log++) {
00183 total = total * 2;
00184 }
00185 return log-1;
00186 }
00187 public static void main (String argv[]) {
00188 SpinOptions so = new SpinOptions();
00189 System.out.println("Default compile options :" + so.compileOptions());
00190 System.out.println("Default pan options :" + so.panOptions());
00191 (so = new SpinOptions()).setSearchMode(SuperTrace);
00192 System.out.println("Supertrace compile options :" + so.compileOptions());
00193 System.out.println("Supertrace pan options :" + so.panOptions());
00194 (so = new SpinOptions()).setSearchMode(HashCompact);
00195 System.out.println("Hash-compact compile options :" + so.compileOptions());
00196 System.out.println("Hash-compact pan options :" + so.panOptions());
00197 (so = new SpinOptions()).setSafety(true);
00198 System.out.println("Safety compile options :" + so.compileOptions());
00199 System.out.println("Safety pan options :" + so.panOptions());
00200 (so = new SpinOptions()).setMemoryLimit(1000);
00201 so.setSearchDepth(50000);
00202 so.setSpaceEstimate(2050);
00203 System.out.println("Limits compile options :" + so.compileOptions());
00204 System.out.println("Limits pan options :" + so.panOptions());
00205 (so = new SpinOptions()).setApplyNeverClaim(false);
00206 so.setPOReduction(true);
00207 so.setCompression(true);
00208 System.out.println("No never, po, compress compile options :" + so.compileOptions());
00209 System.out.println("No never, po, compress pan options :" + so.panOptions());
00210 }
00211 public String panOptions() {
00212 String po;
00213 po = "-n -m" + SearchDepth + " -w" + (10 + log2(SpaceEstimate));
00214 if (AcceptanceCycles) po = po + " -a";
00215 if (StopAtError>1) po = po + " -c" + StopAtError;
00216 if (SaveAllTrails) po = po + " -e";
00217 if (FindShortestTrail) po = po + " -I";
00218 return po;
00219 }
00220
00221
00222
00223
00224 private void parseCompileOptions(String param) {
00225 Vector vector = new Vector();
00226 StringTokenizer st = new StringTokenizer(param);
00227 while (st.hasMoreTokens()) {
00228 vector.add(st.nextToken());
00229 }
00230 for (int i = 0; i < vector.size(); i++) {
00231 String s = ((String) vector.elementAt(i));
00232 if (s.equals("-DBITSTATE"))
00233 setSearchMode(SuperTrace);
00234 else if (s.equals("-DHC"))
00235 setSearchMode(HashCompact);
00236 else if (s.startsWith("-DVECTORSZ")) {
00237 String temp = s.substring(11);
00238 try {
00239 setVectorSize(Integer.parseInt(temp));
00240 } catch (Exception e) {
00241 System.out.println("Vector size error in DVECTORSZ " + getVectorSize());
00242 }
00243 } else if (s.startsWith("-DMEMCNT")) {
00244 String temp = s.substring(9);
00245 try {
00246 setMemoryCount(Integer.parseInt(temp));
00247 } catch (Exception e) {
00248 System.out.println("Memory limit error in DMEMCNT " + getMemoryCount());
00249 }
00250 } else if (s.startsWith("-DMEMLIM")) {
00251 String temp = s.substring(9);
00252 try {
00253 setMemoryLimit(Integer.parseInt(temp));
00254 } catch (Exception e) {
00255 System.out.println("Memory limit error in DMEMLIM " + getMemoryLimit());
00256 }
00257 } else if (s.equals("-DSAFETY")) {
00258 setAcceptanceCycles(false);
00259 setSafety(true);
00260 } else if (s.equals("-DNOREDUCE")) {
00261 } else if (s.equals("-DCOLLAPSE")) {
00262 setCompression(true);
00263 } else if (s.equals("-DNORESOURCEBOUNDED")) {
00264 setResourceBounded(false);
00265 } else if (s.equals("-DNOCLAIM")) {
00266 setApplyNeverClaim(false);
00267 }
00268 }
00269 }
00270
00271
00272
00273 public void parseOptions(String opt)
00274 {
00275 Safety = false;
00276 AcceptanceCycles = true;
00277 ApplyNeverClaim = true;
00278
00279 SearchMode = Exhaustive;
00280
00281 StopAtError = 1;
00282 SaveAllTrails = true;
00283 FindShortestTrail = false;
00284
00285 MemoryLimit = 128;
00286 MemoryCount = 31;
00287 VectorSize = 1024;
00288 SpaceEstimate = 500;
00289 SearchDepth = 10000;
00290
00291 POReduction = false;
00292 Compression = false;
00293
00294 ResourceBounded = true;
00295
00296 StringTokenizer t = new StringTokenizer(opt, "+");
00297 parseCompileOptions(t.nextToken());
00298 parsepaneOptions(t.nextToken());
00299 }
00300
00301
00302
00303
00304
00305 private void parsepaneOptions(String para) {
00306 Vector vector = new Vector();
00307 StringTokenizer st = new StringTokenizer(para);
00308 while(st.hasMoreTokens()){
00309 vector.add(st.nextToken());
00310 }
00311 for(int i =0; i < vector.size(); i++){
00312 if(((String)vector.elementAt(i)).equals("-n")){
00313 i++;
00314 if( i==vector.size() || !((String)(vector.elementAt(i))).startsWith("-m")){
00315 System.out.println("Your input should be -n -mSearchDepth");
00316
00317 }
00318 else{
00319 String temp = ((String)vector.elementAt(i)).substring(2);
00320 try{
00321 setSearchDepth(Integer.parseInt(temp));
00322 }catch(Exception e){
00323 System.out.println("Error search depth option: "+getSearchDepth());
00324 }
00325 }
00326 }
00327 if(((String)vector.elementAt(i)).equals("-a")){
00328 setAcceptanceCycles(true);
00329 }
00330 if(((String)vector.elementAt(i)).equals("-c")){
00331 i++;
00332 if( i==vector.size()){
00333 System.out.println("Your input should be -c StopAtErrors");
00334
00335 }
00336 else{
00337 String temp = (String)vector.elementAt(i);
00338 try{
00339 setStopAtError(Integer.parseInt(temp));
00340 }catch(Exception e){
00341 System.out.println("Error "+getStopAtError());
00342 }
00343 }
00344 }
00345 if(((String)vector.elementAt(i)).equals("-e")){
00346 setSaveAllTrails(true);
00347 }
00348 if(((String)vector.elementAt(i)).equals("-I")){
00349 setFindShortestTrail(true);
00350 }
00351 }
00352 }
00353 public void setAcceptanceCycles(boolean ac) {
00354 AcceptanceCycles = ac;
00355 Safety = !ac;
00356 }
00357 public void setApplyNeverClaim(boolean nc) { ApplyNeverClaim = nc; }
00358 public void setCompression(boolean c) { Compression = c;}
00359 public void setFindShortestTrail(boolean st) { FindShortestTrail = st; }
00360 public void setMemoryCount(int c) { MemoryCount = c;}
00361 public void setMemoryLimit(int l) { MemoryLimit = l;}
00362 public void setPOReduction(boolean po) { POReduction = po;}
00363
00364
00365
00366
00367 public void setResourceBounded(boolean b) {
00368 ResourceBounded = b;
00369 }
00370 public void setSafety(boolean s) {
00371 Safety = s;
00372 AcceptanceCycles = !s;
00373 ApplyNeverClaim = !s;
00374 }
00375 public void setSaveAllTrails(boolean at) { SaveAllTrails = at; }
00376 public void setSearchDepth(int d) { SearchDepth = d;}
00377 public void setSearchMode(int m) { SearchMode = m; }
00378 public void setSpaceEstimate(int e) { SpaceEstimate = e;}
00379 public void setStopAtError(int e) { StopAtError = 1; }
00380 public void setVectorSize(int s) { VectorSize = s;}
00381 }