/** * Delegate cancellation request to the instance * * @param flag */ public void setCanceledFlag(boolean flag) { if (this.instance != null) { this.instance.setCancelFlag(flag); DebugPrinter.print("Cancel flag set to " + flag); } }
// SZ Feb 23, 2009: added return status to indicate the error in parsing public boolean handleParameters(String[] args) { // SZ Feb 20, 2009: extracted this method to separate the // parameter handling from the actual processing int index = 0; while (index < args.length) { if (args[index].equals("-simulate")) { isSimulate = true; index++; } else if (args[index].equals("-modelcheck")) { isSimulate = false; index++; } else if (args[index].equals("-difftrace")) { index++; TLCGlobals.printDiffsOnly = true; } else if (args[index].equals("-deadlock")) { index++; deadlock = false; } else if (args[index].equals("-cleanup")) { index++; cleanup = true; } else if (args[index].equals("-nowarning")) { index++; TLCGlobals.warn = false; } else if (args[index].equals("-gzip")) { index++; TLCGlobals.useGZIP = false; } else if (args[index].equals("-terse")) { index++; Value.expand = false; } else if (args[index].equals("-continue")) { index++; TLCGlobals.continuation = true; } else if (args[index].equals("-view")) { index++; TLCGlobals.useView = true; } else if (args[index].equals("-debug")) { index++; TLCGlobals.debug = true; } else if (args[index].equals("-tool")) { index++; TLCGlobals.tool = true; } else if (args[index].equals("-help")) { printUsage(); return false; } else if (args[index].equals("-config")) { index++; if (index < args.length) { configFile = args[index]; int len = configFile.length(); if (configFile.startsWith(".cfg", len - 4)) { configFile = configFile.substring(0, len - 4); } index++; } else { printErrorMsg("Error: expect a file name for -config option."); return false; } } else if (args[index].equals("-dump")) { index++; if (index < args.length) { dumpFile = args[index]; int len = dumpFile.length(); if (!(dumpFile.startsWith(".dump", len - 5))) { dumpFile = dumpFile + ".dump"; } index++; } else { printErrorMsg("Error: A file name for dumping states required."); return false; } } else if (args[index].equals("-coverage")) { index++; if (index < args.length) { try { TLCGlobals.coverageInterval = Integer.parseInt(args[index]) * 60 * 1000; if (TLCGlobals.coverageInterval < 0) { printErrorMsg("Error: expect a nonnegative integer for -coverage option."); return false; } index++; } catch (NumberFormatException e) { printErrorMsg( "Error: An integer for coverage report interval required." + " But encountered " + args[index]); return false; } } else { printErrorMsg("Error: coverage report interval required."); return false; } } else if (args[index].equals("-checkpoint")) { index++; if (index < args.length) { try { TLCGlobals.chkptDuration = Integer.parseInt(args[index]) * 1000 * 60; if (TLCGlobals.chkptDuration < 0) { printErrorMsg("Error: expect a nonnegative integer for -checkpoint option."); return false; } index++; } catch (Exception e) { printErrorMsg( "Error: An integer for checkpoint interval is required. But encountered " + args[index]); return false; } } else { printErrorMsg("Error: checkpoint interval required."); return false; } } else if (args[index].equals("-depth")) { index++; if (index < args.length) { try { traceDepth = Integer.parseInt(args[index]); index++; } catch (Exception e) { printErrorMsg( "Error: An integer for trace length required. But encountered " + args[index]); return false; } } else { printErrorMsg("Error: trace length required."); return false; } } else if (args[index].equals("-seed")) { index++; if (index < args.length) { try { seed = Long.parseLong(args[index]); index++; noSeed = false; } catch (Exception e) { printErrorMsg("Error: An integer for seed required. But encountered " + args[index]); return false; } } else { printErrorMsg("Error: seed required."); return false; } } else if (args[index].equals("-aril")) { index++; if (index < args.length) { try { aril = Long.parseLong(args[index]); index++; } catch (Exception e) { printErrorMsg("Error: An integer for aril required. But encountered " + args[index]); return false; } } else { printErrorMsg("Error: aril required."); return false; } } else if (args[index].equals("-maxSetSize")) { index++; if (index < args.length) { try { int bound = Integer.parseInt(args[index]); // make sure it's in valid range if (!TLCGlobals.isValidSetSize(bound)) { int maxValue = Integer.MAX_VALUE; printErrorMsg( "Error: Value in interval [0, " + maxValue + "] for maxSetSize required. But encountered " + args[index]); return false; } TLCGlobals.setBound = bound; index++; } catch (Exception e) { printErrorMsg( "Error: An integer for maxSetSize required. But encountered " + args[index]); return false; } } else { printErrorMsg("Error: maxSetSize required."); return false; } } else if (args[index].equals("-recover")) { index++; if (index < args.length) { fromChkpt = args[index++] + FileUtil.separator; } else { printErrorMsg("Error: need to specify the metadata directory for recovery."); return false; } } else if (args[index].equals("-metadir")) { index++; if (index < args.length) { TLCGlobals.metaDir = args[index++] + FileUtil.separator; } else { printErrorMsg("Error: need to specify the metadata directory."); return false; } } else if (args[index].equals("-workers")) { index++; if (index < args.length) { try { int num = Integer.parseInt(args[index]); if (num < 1) { printErrorMsg("Error: at least one worker required."); return false; } TLCGlobals.setNumWorkers(num); index++; } catch (Exception e) { printErrorMsg("Error: worker number required. But encountered " + args[index]); return false; } } else { printErrorMsg("Error: expect an integer for -workers option."); return false; } } else if (args[index].equals("-dfid")) { index++; if (index < args.length) { try { TLCGlobals.DFIDMax = Integer.parseInt(args[index]); if (TLCGlobals.DFIDMax < 0) { printErrorMsg("Error: expect a nonnegative integer for -dfid option."); return false; } index++; } catch (Exception e) { printErrorMsg( "Errorexpect a nonnegative integer for -dfid option. " + "But encountered " + args[index]); return false; } } else { printErrorMsg("Error: expect a nonnegative integer for -dfid option."); return false; } } else if (args[index].equals("-fp")) { index++; if (index < args.length) { try { fpIndex = Integer.parseInt(args[index]); if (fpIndex < 0 || fpIndex >= FP64.Polys.length) { printErrorMsg( "Error: The number for -fp must be between 0 and " + (FP64.Polys.length - 1) + " (inclusive)."); return false; } index++; } catch (Exception e) { printErrorMsg("Error: A number for -fp is required. But encountered " + args[index]); return false; } } else { printErrorMsg("Error: expect an integer for -workers option."); return false; } } else if (args[index].equals("-fpmem")) { index++; if (index < args.length) { try { // -fpmem can be used in two ways: // a) to set the relative memory to be used for fingerprints (being machine independent) // b) to set the absolute memory to be used for fingerprints // // In order to set memory relatively, a value in the domain [0.0, 1.0] is interpreted as // a fraction. // A value in the [2, Double.MaxValue] domain allocates memory absolutely. // // Independently of relative or absolute mem allocation, // a user cannot allocate more than JVM heap space // available. Conversely there is the lower hard limit TLC#MinFpMemSize. fpMemSize = Double.parseDouble(args[index]); if (fpMemSize < 0) { printErrorMsg( "Error: An positive integer or a fraction for fpset memory size/percentage required. But encountered " + args[index]); return false; } else if (fpMemSize > 1) { fpMemSize = (long) fpMemSize; } index++; } catch (Exception e) { printErrorMsg( "Error: An positive integer or a fraction for fpset memory size/percentage required. But encountered " + args[index]); return false; } } else { printErrorMsg("Error: fpset memory size required."); return false; } } else if (args[index].equals("-fpbits")) { index++; if (index < args.length) { try { fpBits = Integer.parseInt(args[index]); // make sure it's in valid range if (!FPSet.isValid(fpBits)) { printErrorMsg( "Error: Value in interval [0, 30] for fpbits required. But encountered " + args[index]); return false; } index++; } catch (Exception e) { printErrorMsg("Error: An integer for fpbits required. But encountered " + args[index]); return false; } } else { printErrorMsg("Error: fpbits required."); return false; } } else { if (args[index].charAt(0) == '-') { printErrorMsg("Error: unrecognized option: " + args[index]); return false; } if (mainFile != null) { printErrorMsg("Error: more than one input files: " + mainFile + " and " + args[index]); return false; } mainFile = args[index++]; int len = mainFile.length(); if (mainFile.startsWith(".tla", len - 4)) { mainFile = mainFile.substring(0, len - 4); } } } fpMemSize = TLCRuntime.getInstance().getFPMemSize(fpMemSize); if (mainFile == null) { printErrorMsg("Error: Missing input TLA+ module."); return false; } if (configFile == null) { configFile = mainFile; } if (TLCGlobals.debug) { StringBuffer buffer = new StringBuffer("TLC argumens:"); for (int i = 0; i < args.length; i++) { buffer.append(args[i]); if (i < args.length - 1) { buffer.append(" "); } } buffer.append("\n"); DebugPrinter.print(buffer.toString()); } // if no errors, print welcome message printWelcome(); return true; }