Skip to content

Commit c35c9f3

Browse files
committed
use ebmc_languaget API in ebmc_parse_optionst
This replaces the direct call to get_transition_system(...) by a call to an implementation of ebmc_languaget, which wraps get_transition_system.
1 parent 4e87354 commit c35c9f3

File tree

11 files changed

+124
-96
lines changed

11 files changed

+124
-96
lines changed

regression/verilog/preprocessor/unknown_directive.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ CORE
22
unknown_directive.v
33
--preprocess
44
^file unknown_directive\.v line 1: unknown preprocessor directive "something"$
5-
^PREPROCESSING FAILED$
65
^EXIT=1$
76
^SIGNAL=0$
87
--

src/ebmc/build_transition_system.cpp

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,29 @@ Author: Daniel Kroening, [email protected]
3030
#include <fstream>
3131
#include <iostream>
3232

33-
int preprocess(const cmdlinet &cmdline, message_handlert &message_handler)
33+
void preprocess(const cmdlinet &cmdline, message_handlert &message_handler)
3434
{
3535
messaget message(message_handler);
3636

3737
if(cmdline.args.size() != 1)
38-
{
39-
message.error() << "please give exactly one file to preprocess"
40-
<< messaget::eom;
41-
return 1;
42-
}
38+
throw ebmc_errort{}.with_exit_code(1)
39+
<< "please give exactly one file to preprocess";
4340

4441
const auto &filename = cmdline.args.front();
4542
std::ifstream infile(widen_if_needed(filename));
4643

4744
if(!infile)
48-
{
49-
message.error() << "failed to open input file `" << filename << "'"
50-
<< messaget::eom;
51-
return 1;
52-
}
45+
throw ebmc_errort{}.with_exit_code(1)
46+
<< "failed to open input file `" << filename << "'";
5347

5448
auto language = get_language_from_filename(filename);
5549

5650
if(language == nullptr)
5751
{
5852
source_locationt location;
5953
location.set_file(filename);
60-
message.error().source_location = location;
61-
message.error() << "failed to figure out type of file" << messaget::eom;
62-
return 1;
54+
throw ebmc_errort{}.with_location(location).with_exit_code(1)
55+
<< "failed to figure out type of file";
6356
}
6457

6558
optionst options;
@@ -77,12 +70,7 @@ int preprocess(const cmdlinet &cmdline, message_handlert &message_handler)
7770
language->set_language_options(options, message_handler);
7871

7972
if(language->preprocess(infile, filename, std::cout, message_handler))
80-
{
81-
message.error() << "PREPROCESSING FAILED" << messaget::eom;
82-
return 1;
83-
}
84-
85-
return 0;
73+
throw ebmc_errort{}.with_exit_code(1);
8674
}
8775

8876
static bool parse(
@@ -211,9 +199,6 @@ int get_transition_system(
211199
{
212200
messaget message(message_handler);
213201

214-
if(cmdline.isset("preprocess"))
215-
return preprocess(cmdline, message_handler);
216-
217202
//
218203
// parsing
219204
//
@@ -349,3 +334,40 @@ int show_symbol_table(
349334
return get_transition_system(
350335
cmdline, message_handler, dummy_transition_system);
351336
}
337+
338+
std::optional<transition_systemt> ebmc_languagest::transition_system()
339+
{
340+
if(cmdline.isset("preprocess"))
341+
{
342+
preprocess(cmdline, message_handler);
343+
return {};
344+
}
345+
346+
if(cmdline.isset("show-parse"))
347+
{
348+
show_parse(cmdline, message_handler);
349+
return {};
350+
}
351+
352+
if(
353+
cmdline.isset("show-modules") || cmdline.isset("modules-xml") ||
354+
cmdline.isset("json-modules"))
355+
{
356+
show_modules(cmdline, message_handler);
357+
return {};
358+
}
359+
360+
if(cmdline.isset("show-module-hierarchy"))
361+
{
362+
show_module_hierarchy(cmdline, message_handler);
363+
return {};
364+
}
365+
366+
if(cmdline.isset("show-symbol-table"))
367+
{
368+
show_symbol_table(cmdline, message_handler);
369+
return {};
370+
}
371+
372+
return get_transition_system(cmdline, message_handler);
373+
}

src/ebmc/build_transition_system.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,25 @@ Author: Daniel Kroening, [email protected]
99
#ifndef CPROVER_EBMC_BUILD_TRANSITION_SYSTEM_H
1010
#define CPROVER_EBMC_BUILD_TRANSITION_SYSTEM_H
1111

12-
class cmdlinet;
13-
class message_handlert;
14-
class transition_systemt;
12+
#include "ebmc_language.h"
1513

1614
transition_systemt get_transition_system(const cmdlinet &, message_handlert &);
1715

18-
int preprocess(const cmdlinet &, message_handlert &);
16+
void preprocess(const cmdlinet &, message_handlert &);
1917
int show_parse(const cmdlinet &, message_handlert &);
2018
int show_modules(const cmdlinet &, message_handlert &);
2119
int show_module_hierarchy(const cmdlinet &, message_handlert &);
2220
int show_symbol_table(const cmdlinet &, message_handlert &);
2321

22+
class ebmc_languagest : public ebmc_languaget
23+
{
24+
public:
25+
ebmc_languagest(cmdlinet &_cmdline, message_handlert &_message_handler)
26+
: ebmc_languaget{_cmdline, _message_handler}
27+
{
28+
}
29+
30+
std::optional<transition_systemt> transition_system() override;
31+
};
32+
2433
#endif // CPROVER_EBMC_BUILD_TRANSITION_SYSTEM_H

src/ebmc/ebmc_language.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#define EBMC_LANGUAGE_H
1414

1515
#include <iosfwd>
16+
#include <optional>
1617

1718
class cmdlinet;
1819
class message_handlert;
@@ -29,11 +30,9 @@ class ebmc_languaget
2930

3031
virtual ~ebmc_languaget();
3132

32-
/// produce diagnostic output as specified on the command line
33-
virtual void diagnostics() = 0;
34-
35-
/// produce the transition system, and return it
36-
virtual transition_systemt transition_system() = 0;
33+
/// Produce the transition system, and return it;
34+
/// returns {} when diagnostic output was produced instead.
35+
virtual std::optional<transition_systemt> transition_system() = 0;
3736

3837
protected:
3938
cmdlinet &cmdline;

src/ebmc/ebmc_parse_options.cpp

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Author: Daniel Kroening, [email protected]
1919
#include "diatest.h"
2020
#include "ebmc_base.h"
2121
#include "ebmc_error.h"
22+
#include "ebmc_language.h"
2223
#include "ebmc_version.h"
2324
#include "format_hooks.h"
2425
#include "instrument_buechi.h"
@@ -108,23 +109,6 @@ int ebmc_parse_optionst::doit()
108109
return 0;
109110
}
110111

111-
if(cmdline.isset("preprocess"))
112-
return preprocess(cmdline, ui_message_handler);
113-
114-
if(cmdline.isset("show-parse"))
115-
return show_parse(cmdline, ui_message_handler);
116-
117-
if(
118-
cmdline.isset("show-modules") || cmdline.isset("modules-xml") ||
119-
cmdline.isset("json-modules"))
120-
return show_modules(cmdline, ui_message_handler);
121-
122-
if(cmdline.isset("show-module-hierarchy"))
123-
return show_module_hierarchy(cmdline, ui_message_handler);
124-
125-
if(cmdline.isset("show-symbol-table"))
126-
return show_symbol_table(cmdline, ui_message_handler);
127-
128112
if(cmdline.isset("coverage"))
129113
{
130114
throw ebmc_errort() << "This option is currently disabled";
@@ -140,18 +124,6 @@ int ebmc_parse_optionst::doit()
140124
#endif
141125
}
142126

143-
if(cmdline.isset("random-traces"))
144-
return random_traces(cmdline, ui_message_handler);
145-
146-
if(cmdline.isset("random-trace") || cmdline.isset("random-waveform"))
147-
return random_trace(cmdline, ui_message_handler);
148-
149-
if(cmdline.isset("neural-liveness"))
150-
return do_neural_liveness(cmdline, ui_message_handler);
151-
152-
if(cmdline.isset("ranking-function"))
153-
return do_ranking_function(cmdline, ui_message_handler);
154-
155127
if(cmdline.isset("interpolation-word"))
156128
{
157129
throw ebmc_errort() << "This option is currently disabled";
@@ -208,7 +180,28 @@ int ebmc_parse_optionst::doit()
208180
}
209181

210182
// get the transition system
211-
auto transition_system = get_transition_system(cmdline, ui_message_handler);
183+
ebmc_languagest ebmc_languages{cmdline, ui_message_handler};
184+
185+
auto transition_system_opt = ebmc_languages.transition_system();
186+
187+
// Did we produce diagnostics instead?
188+
if(!transition_system_opt.has_value())
189+
return 0;
190+
191+
auto &transition_system = transition_system_opt.value();
192+
193+
if(cmdline.isset("random-traces"))
194+
return random_traces(transition_system, cmdline, ui_message_handler);
195+
196+
if(cmdline.isset("random-trace") || cmdline.isset("random-waveform"))
197+
return random_trace(transition_system, cmdline, ui_message_handler);
198+
199+
if(cmdline.isset("neural-liveness"))
200+
return do_neural_liveness(transition_system, cmdline, ui_message_handler);
201+
202+
if(cmdline.isset("ranking-function"))
203+
return do_ranking_function(
204+
transition_system, cmdline, ui_message_handler);
212205

213206
// get the properties
214207
auto properties = ebmc_propertiest::from_command_line(

src/ebmc/neural_liveness.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Author: Daniel Kroening, [email protected]
1717
#include <temporal-logic/temporal_expr.h>
1818
#include <verilog/sva_expr.h>
1919

20-
#include "build_transition_system.h"
2120
#include "ebmc_error.h"
2221
#include "ebmc_solver_factory.h"
2322
#include "live_signal.h"
@@ -42,10 +41,14 @@ Author: Daniel Kroening, [email protected]
4241
class neural_livenesst
4342
{
4443
public:
45-
neural_livenesst(const cmdlinet &_cmdline, message_handlert &_message_handler)
44+
neural_livenesst(
45+
transition_systemt &_transition_system,
46+
const cmdlinet &_cmdline,
47+
message_handlert &_message_handler)
4648
: cmdline(_cmdline),
4749
message(_message_handler),
48-
solver_factory(ebmc_solver_factory(_cmdline))
50+
solver_factory(ebmc_solver_factory(_cmdline)),
51+
transition_system(_transition_system)
4952
{
5053
}
5154

@@ -55,7 +58,7 @@ class neural_livenesst
5558
const cmdlinet &cmdline;
5659
messaget message;
5760
ebmc_solver_factoryt solver_factory;
58-
transition_systemt transition_system;
61+
transition_systemt &transition_system;
5962
ebmc_propertiest properties;
6063

6164
int show_traces();
@@ -75,9 +78,6 @@ int neural_livenesst::operator()()
7578
if(!cmdline.isset("neural-engine"))
7679
throw ebmc_errort() << "give a neural engine";
7780

78-
transition_system =
79-
get_transition_system(cmdline, message.get_message_handler());
80-
8181
// Get the properties
8282
properties = ebmc_propertiest::from_command_line(
8383
cmdline, transition_system, message.get_message_handler());
@@ -127,9 +127,6 @@ int neural_livenesst::operator()()
127127

128128
int neural_livenesst::show_traces()
129129
{
130-
transition_system =
131-
get_transition_system(cmdline, message.get_message_handler());
132-
133130
properties = ebmc_propertiest::from_command_line(
134131
cmdline, transition_system, message.get_message_handler());
135132

@@ -317,8 +314,9 @@ tvt neural_livenesst::verify(
317314
}
318315

319316
int do_neural_liveness(
317+
transition_systemt &transition_system,
320318
const cmdlinet &cmdline,
321-
ui_message_handlert &ui_message_handler)
319+
message_handlert &message_handler)
322320
{
323-
return neural_livenesst(cmdline, ui_message_handler)();
321+
return neural_livenesst{transition_system, cmdline, message_handler}();
324322
}

src/ebmc/neural_liveness.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ Author: Daniel Kroening, [email protected]
99
#ifndef EBMC_NEURAL_LIVENESS_H
1010
#define EBMC_NEURAL_LIVENESS_H
1111

12-
#include <util/cmdline.h>
13-
#include <util/ui_message.h>
12+
class cmdlinet;
13+
class message_handlert;
14+
class transition_systemt;
1415

15-
int do_neural_liveness(const cmdlinet &, ui_message_handlert &);
16+
int do_neural_liveness(
17+
transition_systemt &,
18+
const cmdlinet &,
19+
message_handlert &);
1620

1721
#endif // EBMC_NEURAL_LIVENESS_H

src/ebmc/random_traces.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Author: Daniel Kroening, [email protected]
2020
#include <trans-word-level/trans_trace_word_level.h>
2121
#include <trans-word-level/unwind.h>
2222

23-
#include "build_transition_system.h"
2423
#include "ebmc_base.h"
2524
#include "ebmc_error.h"
2625
#include "output_file.h"
@@ -113,7 +112,10 @@ Function: random_traces
113112
114113
\*******************************************************************/
115114

116-
int random_traces(const cmdlinet &cmdline, message_handlert &message_handler)
115+
int random_traces(
116+
const transition_systemt &transition_system,
117+
const cmdlinet &cmdline,
118+
message_handlert &message_handler)
117119
{
118120
const auto number_of_traces = [&cmdline]() -> std::size_t {
119121
if(cmdline.isset("traces"))
@@ -172,9 +174,6 @@ int random_traces(const cmdlinet &cmdline, message_handlert &message_handler)
172174
return {};
173175
}();
174176

175-
transition_systemt transition_system =
176-
get_transition_system(cmdline, message_handler);
177-
178177
if(cmdline.isset("waveform") && cmdline.isset("vcd"))
179178
throw ebmc_errort() << "cannot do VCD and ASCII waveform simultaneously";
180179

@@ -232,7 +231,10 @@ Function: random_trace
232231
233232
\*******************************************************************/
234233

235-
int random_trace(const cmdlinet &cmdline, message_handlert &message_handler)
234+
int random_trace(
235+
const transition_systemt &transition_system,
236+
const cmdlinet &cmdline,
237+
message_handlert &message_handler)
236238
{
237239
if(cmdline.isset("traces"))
238240
throw ebmc_errort() << "must not give number of traces";
@@ -276,9 +278,6 @@ int random_trace(const cmdlinet &cmdline, message_handlert &message_handler)
276278
return 10; // default
277279
}();
278280

279-
transition_systemt transition_system =
280-
get_transition_system(cmdline, message_handler);
281-
282281
auto consumer = [&](trans_tracet trace) -> void {
283282
namespacet ns(transition_system.symbol_table);
284283
if(cmdline.isset("random-waveform") || cmdline.isset("waveform"))

0 commit comments

Comments
 (0)