SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
execute_smtlib.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../parser/ParserWrapper.h"
4 
5 #include "../CLIStatistics.h"
6 
7 #include <string>
8 
9 namespace smtrat {
10 
11 
12 
13 
14 template<typename Executor>
15 bool parseInput(const std::string& pathToInputFile, Executor& e, bool& queueInstructions) {
16  if (pathToInputFile == "-") {
17  queueInstructions = false;
18  SMTRAT_LOG_DEBUG("smtrat", "Starting to parse from stdin");
19  return smtrat::parseSMT2File(e, queueInstructions, std::cin);
20  }
21 
22  std::ifstream infile(pathToInputFile);
23  if (!infile.good()) {
24  std::cerr << "Could not open file: " << pathToInputFile << std::endl;
26  }
27  SMTRAT_LOG_DEBUG("smtrat", "Starting to parse " << pathToInputFile);
28  return smtrat::parseSMT2File(e, queueInstructions, infile);
29 }
30 
31 /**
32  * Parse the file and save it in formula.
33  * @param pathToInputFile The path to the input smt2 file.
34  * @param formula A pointer to the formula object which holds the parsed input afterwards.
35  * @param options Save options from the smt2 file here.
36  */
37 template<typename Executor>
38 int executeFile(const std::string& pathToInputFile, Executor& e) {
39 #ifdef __WIN
40 //TODO: do not use magical number
41 #pragma comment(linker, "/STACK:10000000")
42 #else
43  // Increase stack size to the maximum.
44  rlimit rl;
45  getrlimit(RLIMIT_STACK, &rl);
46  rl.rlim_cur = rl.rlim_max;
47  setrlimit(RLIMIT_STACK, &rl);
48 #endif
49 
50  SMTRAT_TIME_START(start);
51  bool queueInstructions = true;
52  if (!parseInput(pathToInputFile, e, queueInstructions)) {
53  std::cerr << "Parse error" << std::endl;
55  }
56  if (queueInstructions) {
57  if (e.hasInstructions()) {
58  SMTRAT_LOG_WARN("smtrat", "Running queued instructions.");
59  e.runInstructions();
60  } else {
61  SMTRAT_LOG_WARN("smtrat", "Did not parse any instructions.");
62  }
63  }
64  SMTRAT_TIME_FINISH(cli::statistics().parsing, start);
65  return e.getExitCode();
66 }
67 
68 }
constexpr int SMTRAT_EXIT_NOSUCHFILE
Definition: ExitCodes.h:20
constexpr int SMTRAT_EXIT_PARSERFAILURE
Definition: ExitCodes.h:21
int getExitCode() const
Definition: Executor.h:328
Class to create the formulas for axioms.
bool parseSMT2File(parser::InstructionHandler &handler, bool queueInstructions, std::istream &input)
bool parseInput(const std::string &pathToInputFile, Executor &e, bool &queueInstructions)
int executeFile(const std::string &pathToInputFile, Executor &e)
Parse the file and save it in formula.
#define SMTRAT_LOG_WARN(channel, msg)
Definition: logging.h:33
#define SMTRAT_LOG_DEBUG(channel, msg)
Definition: logging.h:35
#define SMTRAT_TIME_START(variable)
Definition: Statistics.h:24
#define SMTRAT_TIME_FINISH(timer, start)
Definition: Statistics.h:25