Skip to content

Commit 5c83c53

Browse files
authored
Merge pull request #1422 from diffblue/use_ebmc_language_api
Use EBMC language API
2 parents 01ca94a + fcc77b6 commit 5c83c53

13 files changed

+176
-91
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/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SRC = \
1313
diatest.cpp \
1414
dimacs_writer.cpp \
1515
ebmc_base.cpp \
16+
ebmc_language.cpp \
1617
ebmc_language_file.cpp \
1718
ebmc_languages.cpp \
1819
ebmc_parse_options.cpp \

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.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*******************************************************************\
2+
3+
Module: Abstract interface to support a modeling language
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include "ebmc_language.h"
10+
11+
ebmc_languaget::~ebmc_languaget()
12+
{
13+
}

src/ebmc/ebmc_language.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*******************************************************************\
2+
3+
Module: Abstract interface to support a modeling language
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Abstract interface to support a modeling language
11+
12+
#ifndef EBMC_LANGUAGE_H
13+
#define EBMC_LANGUAGE_H
14+
15+
#include <iosfwd>
16+
#include <optional>
17+
18+
class cmdlinet;
19+
class message_handlert;
20+
class transition_systemt;
21+
22+
class ebmc_languaget
23+
{
24+
public:
25+
// constructor / destructor
26+
ebmc_languaget(cmdlinet &_cmdline, message_handlert &_message_handler)
27+
: cmdline(_cmdline), message_handler(_message_handler)
28+
{
29+
}
30+
31+
virtual ~ebmc_languaget();
32+
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;
36+
37+
protected:
38+
cmdlinet &cmdline;
39+
message_handlert &message_handler;
40+
};
41+
42+
#endif // EBMC_LANGUAGE_H

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

0 commit comments

Comments
 (0)