Skip to content

Commit e6ac21b

Browse files
committed
Move some of the tool state to an api initialisation function
1 parent 99fecce commit e6ac21b

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

cpp_api/api.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22
#include <goto-programs/initialize_goto_model.h>
33

44
#include <util/message.h>
5+
#include <util/options.h>
6+
7+
#include "api.h"
8+
9+
api_depst api_deps;
10+
11+
// Initialise API dependencies
12+
void initialize_api() {
13+
// Initialise a null-message handler (we don't print anything yet)
14+
api_deps.msg_handler = new null_message_handlert();
15+
// Initialise default options
16+
api_deps.opts = new optionst();
17+
}
518

619
goto_modelt load_model_from_files(
720
const std::vector<std::string> &files,
821
const optionst &options)
922
{
10-
null_message_handlert null_msg_hnd;
11-
return initialize_goto_model(files, null_msg_hnd, options);
23+
return initialize_goto_model(files, *api_deps.msg_handler, options);
1224
}

cpp_api/api.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
#include <goto-programs/goto_model.h>
44

5+
#include <util/message.h>
6+
#include <util/options.h>
7+
8+
struct api_depst {
9+
message_handlert *msg_handler;
10+
optionst *opts;
11+
};
12+
13+
void initialize_api();
14+
515
goto_modelt load_model_from_files(
616
const std::vector<std::string> &files,
717
const optionst &options);

cpp_api/call_bmc.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
#include <util/config.h>
1313
#include <util/cmdline.h>
1414
#include <util/message.h>
15-
#include <util/options.h>
1615

1716
#include "api.h"
1817

18+
extern api_depst api_deps;
19+
1920
int main(int argc, char *argv[])
2021
{
2122
try {
@@ -24,10 +25,6 @@ int main(int argc, char *argv[])
2425
// Convert argv to vector of strings for initialize_goto_model
2526
std::vector<std::string> arguments(argv + 1, argv + argc);
2627

27-
// Initialise a null-message handler (we don't print anything yet)
28-
null_message_handlert null_msg_hnd;
29-
// Default options
30-
optionst opts;
3128
// Needed to initialise the language options correctly
3229
cmdlinet cmdline;
3330

@@ -37,7 +34,7 @@ int main(int argc, char *argv[])
3734
// Initialise C language mode
3835
register_language(new_ansi_c_language);
3936

40-
auto model = load_model_from_files(arguments, opts);
37+
auto model = load_model_from_files(arguments, *api_deps.opts);
4138

4239
std::cout << "Successfully initialised goto_model" << std::endl;
4340
return 0;

0 commit comments

Comments
 (0)