SMTStabilizer API
Public API documentation for SMTStabilizer
Loading...
Searching...
No Matches
stabilizer_api.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 XiangZhang
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19// SOFTWARE.
20
21#include "api/stabilizer_api.h"
22
23#include <stdexcept>
24#include <utility>
25
26#include "kernel/kernel.h"
27#include "node/node_manager.h"
28#include "parser/parser.h"
29
30namespace stabilizer::api {
31
32SMTStabilizer::SMTStabilizer(SMTStabilizerOptions options) : d_options(std::move(options)) {}
33
34const SMTStabilizerOptions &SMTStabilizer::options() const noexcept { return d_options; }
35
36void SMTStabilizer::set_options(const SMTStabilizerOptions &options) noexcept { d_options = options; }
37
39 auto global_options = parser.getOptions();
40 global_options->setKeepLet(false);
41 global_options->setExpandFunctions(false);
42 global_options->setRewrite(options.get_rewrite());
43}
44
47
48 stabilizer::node::NodeManager nm(parser);
49 nm.simplify_assertions();
50
52 kernel.apply(nm);
53
54 return nm.to_string();
55}
56
57std::string SMTStabilizer::apply_file(const std::string &file_path) const {
58 if (file_path.empty()) {
59 throw std::invalid_argument("file_path must not be empty");
60 }
61
63 parser.parse(file_path);
64 return run_pipeline(parser, d_options);
65}
66
67std::string SMTStabilizer::apply_text(const std::string &smt2_text) const {
68 if (smt2_text.empty()) {
69 throw std::invalid_argument("smt2_text must not be empty");
70 }
71
73 parser.parseStr(smt2_text);
74 return run_pipeline(parser, d_options);
75}
76
77} // namespace stabilizer::api
Public options for the SMTStabilizer API.
bool get_subgraph_pruning() const noexcept
bool get_context_propagation() const noexcept
std::string apply_file(const std::string &file_path) const
Apply the full pipeline to an SMT-LIB2 file.
SMTStabilizer(SMTStabilizerOptions options={})
std::string apply_text(const std::string &smt2_text) const
Apply the full pipeline to an SMT-LIB2 script provided as text.
const SMTStabilizerOptions & options() const noexcept
static std::string run_pipeline(stabilizer::parser::Parser &parser, const SMTStabilizerOptions &options)
static void configure_parser(stabilizer::parser::Parser &parser, const SMTStabilizerOptions &options)
void set_options(const SMTStabilizerOptions &options) noexcept
SMTStabilizerOptions d_options
Internal canonicalization kernel for SMTStabilizer.
Definition kernel.h:39
void apply(node::NodeManager &nm)
Run the full stabilization pass and mutate node manager state.
Definition kernel.cpp:575
bool parse(const std::string &filename)
Parse SMT-LIB2 file.
std::shared_ptr< GlobalOptions > getOptions() const
Get global options.
bool parseStr(const std::string &constraint)
Parse a constraint.
Definition hash.h:27