SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Z3.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Tool.h"
4 
5 namespace benchmax {
6 
7 /**
8  * Tool wrapper for Z3 for SMT-LIB.
9  */
10 class Z3: public Tool {
11 public:
12  /// New Z3 tool.
13  Z3(const fs::path& binary, const std::string& arguments): Tool("Z3", binary, arguments) {
14  if (settings_tools().collect_statistics) mArguments += " -st";
15  }
16  /// Only handle .smt2 files.
17  virtual bool canHandle(const fs::path& path) const override {
18  return is_extension(path, ".smt2");
19  }
20  /// Parse answer string from stdout.
21  virtual void additionalResults(const fs::path&, BenchmarkResult& result) const override {
22  if (result.stdout.find("unsat") != std::string::npos) result.answer = "unsat";
23  else if (result.stdout.find("sat") != std::string::npos) result.answer = "sat";
24  else if (result.stdout.find("unknown") != std::string::npos) result.answer = "unknown";
25  else if (result.stdout.find("out of memory") != std::string::npos) result.answer = "memout";
26  else result.answer = "invalid";
27 
28  std::regex topRegex("\\(\\s*((?:\\:\\S+\\s*\\S+\\s*)+)\\)");
29  std::regex subRegex("\\s*\\:(\\S+)\\s*(\\S+)");
30  auto topBegin = std::sregex_iterator(result.stdout.begin(), result.stdout.end(), topRegex);
31  auto topEnd = std::sregex_iterator();
32  for (auto i = topBegin; i != topEnd; ++i) {
33  const std::string& subStdout = (*i)[1];
34  auto subBegin = std::sregex_iterator(subStdout.begin(), subStdout.end(), subRegex);
35  auto subEnd = std::sregex_iterator();
36  for (auto j = subBegin; j != subEnd; ++j) {
37  result.additional.emplace((*j)[1], (*j)[2]);
38  }
39  }
40  result.stdout = "";
41  result.stderr = "";
42  }
43 };
44 
45 }
Base class for any tool.
Definition: Tool.h:38
fs::path binary() const
Full path to the binary.
Definition: Tool.h:67
std::string mArguments
Command line arguments that should be passed to the binary.
Definition: Tool.h:45
Tool wrapper for Z3 for SMT-LIB.
Definition: Z3.h:10
virtual bool canHandle(const fs::path &path) const override
Only handle .smt2 files.
Definition: Z3.h:17
Z3(const fs::path &binary, const std::string &arguments)
New Z3 tool.
Definition: Z3.h:13
virtual void additionalResults(const fs::path &, BenchmarkResult &result) const override
Parse answer string from stdout.
Definition: Z3.h:21
bool is_extension(const std::filesystem::path &path, const std::string &extension)
Checks whether the extension of the filename is as specified.
Definition: filesystem.h:60
const auto & settings_tools()
Returns the tool settings.
Definition: Tools.h:59
Results for a single benchmark run.