-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
167 lines (139 loc) · 5.96 KB
/
main.cpp
File metadata and controls
167 lines (139 loc) · 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
// This file is part of the PlaJA code base.
// Copyright (c) (2019 - 2019) Marcel Vinzent.
// See README.md in the top-level directory for licensing information.
//
#include <memory>
#include "exception/not_supported_exception.h"
#include "exception/option_parser_exception.h"
#include "exception/semantics_exception.h"
#include "option_parser/option_parser.h"
#include "option_parser/plaja_options.h"
#include "parser/ast/model.h"
#include "parser/ast/property.h"
#include "search/factories/search_engine_factory.h"
#include "search/factories/configuration.h"
#include "search/fd_adaptions/timer.h"
#include "search/fd_adaptions/search_engine.h"
#include "search/information/property_information.h"
#include "utils/fd_imports/system.h"
#include "globals.h"
// extern:
namespace PARSER { extern std::unique_ptr<Model> parse(const std::string* filename, const PLAJA::OptionParser* option_parser); }
namespace SEMANTICS_CHECKER { extern void check_semantics(AstElement* ast_element); }
// for timing statistics:
double pre_processing_time { 0 }; // set by main, read by run_engine
// To make main function more readable and to reduce code redundancy:
inline void run_engine(const SearchEngineFactory& engine_factory, const PropertyInformation& property_info) {
auto offset = (*PLAJA_GLOBAL::timer)();
engine_factory.supports_property(property_info);
auto config = engine_factory.init_configuration(*PLAJA_GLOBAL::optionParser, &property_info);
auto engine = engine_factory.construct_engine(*config);
engine->set_construction_time((*PLAJA_GLOBAL::timer)() - offset);
engine->set_preprocessing_time(pre_processing_time);
// set globals:
PLAJA_GLOBAL::currentEngine = engine.get();
engine->search();
engine->update_statistics();
engine->print_statistics_frame(true);
engine->generate_csv();
PLAJA_GLOBAL::currentEngine = nullptr;
}
int main(int argc, char** argv) {
utils::register_event_handlers();
auto time_offset = (*PLAJA_GLOBAL::timer)();
PLAJA_LOG("Parsing commandline ...")
PLAJA::OptionParser option_parser;
PLAJA_GLOBAL::optionParser = &option_parser; // set globally
std::unique_ptr<SearchEngineFactory> engine_factory; // factory ptr
try {
option_parser.load_commandline(argc, argv);
option_parser.pre_load_engine();
engine_factory = SearchEngineFactory::construct_factory(option_parser);
engine_factory->add_options(option_parser);
option_parser.parse_options();
} catch (OptionParserException& e) {
PLAJA_LOG(e.what())
PLAJA_LOG("Use --help to show usage information.")
return 1;
}
PLAJA_LOG("... parsing commandline finished.\n")
if (option_parser.is_flag_set(PLAJA_OPTION::help)) {
PLAJA::OptionParser::get_help();
// engine-specific option (if not using default engine):
if (option_parser.has_value_option(PLAJA_OPTION::engine)) { engine_factory->print_options(); }
else { PLAJA_LOG("Set --engine <engine_type> to additionally include engine-specific options.\n"); }
return 0;
}
// Parsing ...
PLAJA_LOG("Parsing model ...")
std::unique_ptr<Model> model = PARSER::parse(nullptr, &option_parser);
if (!model) {
PLAJA_LOG("... parsing failed.\n")
return 1; // parsing failed
}
PLAJA_LOG("... parsing model finished.\n")
// Store model globally for easy runtime checks and (debugging) outputs.
// This field should be updated w.r.t to the currently considered model, e.g., when using abstractions.
PLAJA_GLOBAL::currentModel = model.get();
PLAJA_LOG("Executing static semantic checks ...")
#ifdef NDEBUG
try {
#endif
SEMANTICS_CHECKER::check_semantics(model.get());
// compute further model information
model->compute_model_information();
#ifdef NDEBUG
} catch (SemanticsException& e) {
PLAJA_LOG(PLAJA_UTILS::string_f("%s\n", e.what()))
return 1;
} catch (NotSupportedException& e) { // some are easier to catch here than at parse time
PLAJA_LOG(PLAJA_UTILS::string_f("%s\n", e.what()))
return 1;
}
#endif
PLAJA_LOG("... semantic checks passed.\n")
// engine supports model?:
try { engine_factory->supports_model(*model); }
catch (NotSupportedException& e) {
PLAJA_LOG(PLAJA_UTILS::string_f("%s\n", e.what()))
return 1;
}
pre_processing_time = (*PLAJA_GLOBAL::timer)() - time_offset;
// Some engines do not consider properties ...
if (model->get_number_properties() == 0 && !engine_factory->is_property_based()) {
const auto dummy = PropertyInformation::construct_property_information(PropertyInformation::NONE, nullptr, model.get());
try { run_engine(*engine_factory, *dummy); }
catch (PlajaException& e) {
PLAJA_LOG(PLAJA_UTILS::string_f("%s\n", e.what()))
return 1;
}
return 0;
}
// else:
// Iterate over properties:
const std::size_t l = model->get_number_properties();
PLAJA_LOG_IF(l == 0, "Warning: 0 properties to check")
for (std::size_t i = 0; i < l; ++i) { // for each property ...
#ifdef NEDBUG
try {
#endif
if (option_parser.has_value_option(PLAJA_OPTION::prop) and option_parser.get_option_value<int>(PLAJA_OPTION::prop, 0) != i) {
PLAJA_LOG(PLAJA_UTILS::string_f("Skipping property %s.", model->get_property(i)->get_name().c_str()))
continue;
}
// Check property:
JANI_ASSERT(model->get_property(i))
const auto property_info = PropertyInformation::analyse_property(*model->get_property(i), *model);
PLAJA_LOG(PLAJA_UTILS::string_f("Checking property: %s ...", model->get_property(i)->get_name().c_str()))
run_engine(*engine_factory, *property_info);
PLAJA_LOG(PLAJA_UTILS::emptyString)
#ifdef NEDBUG
} catch (PlajaException& e) {
PLAJA_LOG( PLAJA_UTILS::string_f("%s\n", e.what()) )
continue; // just try next property
}
#endif
}
return 0;
}