Skip to content

Commit dc3b0ae

Browse files
committed
Implemented timeout set via command line
1 parent 019ca55 commit dc3b0ae

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/bin/opensmt.cc

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3333
#include <getopt.h>
3434
#include <iostream>
3535
#include <unistd.h>
36+
#include <string>
3637

3738
#define opensmt_error_() { std::cerr << "# Error (triggered at " << __FILE__ << ", " << __LINE__ << ")" << std::endl; assert(false); ::exit( 1 ); }
3839
#define opensmt_error( S ) { std::cerr << "; Error: " << S << " (triggered at " << __FILE__ << ", " << __LINE__ << ")" << std::endl; ::exit( 1 ); }
@@ -49,7 +50,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4950

5051
namespace opensmt {
5152

52-
inline bool pipeExecution = false;
53+
using namespace std::string_literals;
54+
55+
namespace {
56+
bool pipeExecution = false;
57+
}
5358

5459
SMTConfig parseCMDLineArgs(int argc, char * argv[ ]);
5560

@@ -66,7 +71,7 @@ void interpretInteractive(Interpret & interpret);
6671
}
6772

6873
int main( int argc, char * argv[] )
69-
{
74+
try {
7075
using namespace opensmt;
7176

7277
signal( SIGTERM, catcher );
@@ -123,6 +128,10 @@ int main( int argc, char * argv[] )
123128

124129
return 0;
125130
}
131+
catch (std::exception const & e) {
132+
std::cerr << "Terminated with exception:\n" << e.what() << std::endl;
133+
return 1;
134+
}
126135

127136
namespace opensmt {
128137

@@ -225,6 +234,7 @@ void printHelp()
225234
" --minimal-unsat-cores produced unsat cores must be irreducible\n"
226235
" --print-cores-full produced unsat cores are agnostic to the smt2 attribute ':named'\n"
227236
" --produce-interpolants [-i] enables interpolant computation\n"
237+
" --time-limit [-t] <ms> sets wall-clock time limit in milliseconds\n"
228238
" --pipe [-p] for execution within a pipe\n";
229239
std::cerr << help_string;
230240
}
@@ -247,14 +257,16 @@ SMTConfig parseCMDLineArgs( int argc, char * argv[ ] )
247257
{"minimal-unsat-cores", no_argument, &selectedLongOpt, minUcoreLongOpt},
248258
{"print-cores-full", no_argument, &selectedLongOpt, fullUcoreLongOpt},
249259
{"produce-interpolants", no_argument, nullptr, 'i'},
260+
{"time-limit", required_argument, nullptr, 't'},
250261
{"pipe", no_argument, nullptr, 'p'},
251262
{0, 0, 0, 0}
252263
};
253264

254265
const char* msg;
255-
while (true) {
266+
bool ok = true;
267+
while (ok) {
256268
int option_index = 0;
257-
int c = getopt_long(argc, argv, "r:hdivp", long_options, &option_index);
269+
int c = getopt_long(argc, argv, "r:hdivpt:", long_options, &option_index);
258270
if (c == -1) { break; }
259271

260272
switch (c) {
@@ -289,6 +301,17 @@ SMTConfig parseCMDLineArgs( int argc, char * argv[ ] )
289301
case 'i':
290302
res.setOption(SMTConfig::o_produce_inter, SMTOption(true), msg);
291303
break;
304+
case 't': {
305+
int64_t timeLimit;
306+
try {
307+
timeLimit = std::stoll(optarg);
308+
} catch (std::logic_error const & e) {
309+
throw std::invalid_argument{"Invalid argument of time-limit: "s + e.what()};
310+
}
311+
312+
ok &= res.setOption(SMTConfig::o_time_limit, SMTOption(timeLimit), msg);
313+
break;
314+
}
292315
case 'p':
293316
pipeExecution = true;
294317
break;
@@ -298,6 +321,10 @@ SMTConfig parseCMDLineArgs( int argc, char * argv[ ] )
298321
}
299322
}
300323

324+
if (not ok) {
325+
throw std::invalid_argument{"Invalid command-line argument: "s + msg};
326+
}
327+
301328
return res;
302329
}
303330

src/options/SMTConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ namespace opensmt {
146146
SMTOption(ASTNode const & n);
147147
SMTOption() {}
148148
SMTOption(int i) : value(i) {}
149+
//+ Should also support long representation
150+
SMTOption(long i) : SMTOption(static_cast<int>(i)) {}
149151
SMTOption(double i): value(i) {}
150152
SMTOption(const char* s) : value(s) {}
151153
inline bool isEmpty() const { return value.type == O_EMPTY; }

0 commit comments

Comments
 (0)