Skip to content

Commit 5bbad53

Browse files
committed
assembler_parsert: construct with message handler
This both avoids an object of static lifetime as well as it fixes the (transitive) use of the deprecated messaget() constructor.
1 parent 56da874 commit 5bbad53

File tree

11 files changed

+58
-39
lines changed

11 files changed

+58
-39
lines changed

src/assembler/assembler_parser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Author: Daniel Kroening, [email protected]
88

99
#include "assembler_parser.h"
1010

11-
assembler_parsert assembler_parser;
12-
1311
extern char *yyassemblertext;
1412

15-
int yyassemblererror(const std::string &error)
13+
int yyassemblererror(
14+
assembler_parsert &assembler_parser,
15+
const std::string &error)
1616
{
1717
assembler_parser.parse_error(error, yyassemblertext);
1818
return 0;

src/assembler/assembler_parser.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include <list>
1616

17-
int yyassemblerlex();
18-
int yyassemblererror(const std::string &error);
19-
void assembler_scanner_init();
17+
class assembler_parsert;
18+
int yyassemblerlex(assembler_parsert &);
19+
int yyassemblererror(assembler_parsert &, const std::string &error);
2020

2121
class assembler_parsert:public parsert
2222
{
@@ -37,24 +37,22 @@ class assembler_parsert:public parsert
3737
instructions.push_back(instructiont());
3838
}
3939

40-
assembler_parsert()
40+
explicit assembler_parsert(message_handlert &message_handler)
41+
: parsert(message_handler)
4142
{
4243
}
4344

4445
virtual bool parse()
4546
{
46-
yyassemblerlex();
47+
yyassemblerlex(*this);
4748
return false;
4849
}
4950

5051
virtual void clear()
5152
{
5253
parsert::clear();
5354
instructions.clear();
54-
// assembler_scanner_init();
5555
}
5656
};
5757

58-
extern assembler_parsert assembler_parser;
59-
6058
#endif // CPROVER_ASSEMBLER_ASSEMBLER_PARSER_H

src/assembler/remove_asm.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ Date: December 2014
3030
class remove_asmt
3131
{
3232
public:
33-
remove_asmt(symbol_tablet &_symbol_table, goto_functionst &_goto_functions)
34-
: symbol_table(_symbol_table), goto_functions(_goto_functions)
33+
remove_asmt(
34+
symbol_tablet &_symbol_table,
35+
goto_functionst &_goto_functions,
36+
message_handlert &message_handler)
37+
: symbol_table(_symbol_table),
38+
goto_functions(_goto_functions),
39+
message_handler(message_handler)
3540
{
3641
}
3742

@@ -44,6 +49,7 @@ class remove_asmt
4449
protected:
4550
symbol_tablet &symbol_table;
4651
goto_functionst &goto_functions;
52+
message_handlert &message_handler;
4753

4854
void process_function(const irep_idt &, goto_functionst::goto_functiont &);
4955

@@ -228,7 +234,7 @@ void remove_asmt::process_instruction_gcc(
228234
const irep_idt &i_str = to_string_constant(code.asm_text()).value();
229235

230236
std::istringstream str(id2string(i_str));
231-
assembler_parser.clear();
237+
assembler_parsert assembler_parser{message_handler};
232238
assembler_parser.in = &str;
233239
assembler_parser.parse();
234240

@@ -399,7 +405,7 @@ void remove_asmt::process_instruction_msc(
399405
const irep_idt &i_str = to_string_constant(code.op0()).value();
400406

401407
std::istringstream str(id2string(i_str));
402-
assembler_parser.clear();
408+
assembler_parsert assembler_parser{message_handler};
403409
assembler_parser.in = &str;
404410
assembler_parser.parse();
405411

@@ -544,13 +550,17 @@ void remove_asmt::process_function(
544550
remove_skip(goto_function.body);
545551
}
546552

547-
/// \copybrief remove_asm(goto_modelt &)
553+
/// \copybrief remove_asm(goto_modelt &, message_handlert &)
548554
///
549555
/// \param goto_functions: The goto functions
550556
/// \param symbol_table: The symbol table
551-
void remove_asm(goto_functionst &goto_functions, symbol_tablet &symbol_table)
557+
/// \param message_handler: Message handler
558+
void remove_asm(
559+
goto_functionst &goto_functions,
560+
symbol_tablet &symbol_table,
561+
message_handlert &message_handler)
552562
{
553-
remove_asmt rem(symbol_table, goto_functions);
563+
remove_asmt rem(symbol_table, goto_functions, message_handler);
554564
rem();
555565
}
556566

@@ -561,9 +571,11 @@ void remove_asm(goto_functionst &goto_functions, symbol_tablet &symbol_table)
561571
/// Unrecognised assembly instructions are ignored.
562572
///
563573
/// \param goto_model: The goto model
564-
void remove_asm(goto_modelt &goto_model)
574+
/// \param message_handler: Message handler
575+
void remove_asm(goto_modelt &goto_model, message_handlert &message_handler)
565576
{
566-
remove_asm(goto_model.goto_functions, goto_model.symbol_table);
577+
remove_asm(
578+
goto_model.goto_functions, goto_model.symbol_table, message_handler);
567579
}
568580

569581
bool has_asm(const goto_functionst &goto_functions)

src/assembler/remove_asm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ Date: December 2014
5454

5555
class goto_functionst;
5656
class goto_modelt;
57+
class message_handlert;
5758
class symbol_tablet;
5859

59-
void remove_asm(goto_functionst &, symbol_tablet &);
60+
void remove_asm(goto_functionst &, symbol_tablet &, message_handlert &);
6061

61-
void remove_asm(goto_modelt &);
62+
void remove_asm(goto_modelt &, message_handlert &);
6263

6364
/// returns true iff the given goto functions use asm instructions
6465
bool has_asm(const goto_functionst &);

src/assembler/scanner.l

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#pragma warning(disable:4005)
1414
#endif
1515

16-
#define PARSER assembler_parser
16+
#define PARSER (*assembler_parser)
1717
#define YYSTYPE unsigned
1818
#undef ECHO
1919
#define ECHO
@@ -61,10 +61,18 @@ string_lit ("L"|"u"|"U"|"u8")?["]{s_char}*["]
6161
%x LINE_COMMENT
6262

6363
%{
64-
void assemlber_scanner_init()
64+
static assembler_parsert *assembler_parser;
65+
66+
int yyassemblerlex(void);
67+
68+
int yyassemblerlex(assembler_parsert &_assembler_parser)
6569
{
66-
YY_FLUSH_BUFFER;
67-
BEGIN(0);
70+
// our scanner is not reentrant
71+
PRECONDITION(!assembler_parser);
72+
assembler_parser = &_assembler_parser;
73+
int result = yyassemblerlex();
74+
assembler_parser = nullptr;
75+
return result;
6876
}
6977
%}
7078

src/cbmc/cbmc_parse_options.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ bool cbmc_parse_optionst::process_goto_program(
882882
{
883883
// Remove inline assembler; this needs to happen before
884884
// adding the library.
885-
remove_asm(goto_model);
885+
remove_asm(goto_model, log.get_message_handler());
886886

887887
// add the library
888888
log.status() << "Adding CPROVER library (" << config.ansi_c.arch << ")"
@@ -894,7 +894,7 @@ bool cbmc_parse_optionst::process_goto_program(
894894
// library functions may introduce inline assembler
895895
while(has_asm(goto_model))
896896
{
897-
remove_asm(goto_model);
897+
remove_asm(goto_model, log.get_message_handler());
898898
link_to_library(
899899
goto_model, log.get_message_handler(), cprover_cpp_library_factory);
900900
link_to_library(

src/goto-analyzer/goto_analyzer_parse_options.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ bool goto_analyzer_parse_optionst::process_goto_program(
698698
{
699699
// Remove inline assembler; this needs to happen before
700700
// adding the library.
701-
remove_asm(goto_model);
701+
remove_asm(goto_model, ui_message_handler);
702702

703703
// add the library
704704
log.status() << "Adding CPROVER library (" << config.ansi_c.arch << ")"
@@ -708,7 +708,7 @@ bool goto_analyzer_parse_optionst::process_goto_program(
708708
// library functions may introduce inline assembler
709709
while(has_asm(goto_model))
710710
{
711-
remove_asm(goto_model);
711+
remove_asm(goto_model, ui_message_handler);
712712
link_to_library(
713713
goto_model, ui_message_handler, cprover_cpp_library_factory);
714714
link_to_library(goto_model, ui_message_handler, cprover_c_library_factory);

src/goto-diff/goto_diff_parse_options.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ bool goto_diff_parse_optionst::process_goto_program(
176176
{
177177
// Remove inline assembler; this needs to happen before
178178
// adding the library.
179-
remove_asm(goto_model);
179+
remove_asm(goto_model, ui_message_handler);
180180

181181
// add the library
182182
log.status() << "Adding CPROVER library (" << config.ansi_c.arch << ")"
@@ -186,7 +186,7 @@ bool goto_diff_parse_optionst::process_goto_program(
186186
// library functions may introduce inline assembler
187187
while(has_asm(goto_model))
188188
{
189-
remove_asm(goto_model);
189+
remove_asm(goto_model, ui_message_handler);
190190
link_to_library(
191191
goto_model, ui_message_handler, cprover_cpp_library_factory);
192192
link_to_library(goto_model, ui_message_handler, cprover_c_library_factory);

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ void goto_instrument_parse_optionst::do_indirect_call_and_rtti_removal(
949949
log.status() << "Virtual function removal" << messaget::eom;
950950
remove_virtual_functions(goto_model);
951951
log.status() << "Cleaning inline assembler statements" << messaget::eom;
952-
remove_asm(goto_model);
952+
remove_asm(goto_model, log.get_message_handler());
953953
}
954954

955955
/// Remove function pointers that can be resolved by analysing const variables
@@ -1065,7 +1065,7 @@ void goto_instrument_parse_optionst::instrument_goto_program()
10651065

10661066
// remove inline assembler as that may yield further library function calls
10671067
// that need to be resolved
1068-
remove_asm(goto_model);
1068+
remove_asm(goto_model, ui_message_handler);
10691069

10701070
// add the library
10711071
log.status() << "Adding CPROVER library (" << config.ansi_c.arch << ")"
@@ -1076,7 +1076,7 @@ void goto_instrument_parse_optionst::instrument_goto_program()
10761076
// library functions may introduce inline assembler
10771077
while(has_asm(goto_model))
10781078
{
1079-
remove_asm(goto_model);
1079+
remove_asm(goto_model, ui_message_handler);
10801080
link_to_library(
10811081
goto_model, ui_message_handler, cprover_cpp_library_factory);
10821082
link_to_library(

src/goto-synthesizer/cegis_verifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ get_checked_pointer_from_null_pointer_check(const exprt &violation)
8484
void cegis_verifiert::preprocess_goto_model()
8585
{
8686
// Preprocess `goto_model`. Copied from `cbmc_parse_options.cpp`.
87-
remove_asm(goto_model);
87+
remove_asm(goto_model, log.get_message_handler());
8888
link_to_library(
8989
goto_model, log.get_message_handler(), cprover_cpp_library_factory);
9090
link_to_library(
9191
goto_model, log.get_message_handler(), cprover_c_library_factory);
9292
// library functions may introduce inline assembler
9393
while(has_asm(goto_model))
9494
{
95-
remove_asm(goto_model);
95+
remove_asm(goto_model, log.get_message_handler());
9696
link_to_library(
9797
goto_model, log.get_message_handler(), cprover_cpp_library_factory);
9898
link_to_library(

src/libcprover-cpp/api.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ bool api_sessiont::is_goto_binary(std::string &file) const
178178
bool api_sessiont::preprocess_model() const
179179
{
180180
// Remove inline assembler; this needs to happen before adding the library.
181-
remove_asm(*implementation->model);
181+
remove_asm(*implementation->model, *implementation->message_handler);
182182

183183
// add the library
184184
messaget log{*implementation->message_handler};
@@ -191,7 +191,7 @@ bool api_sessiont::preprocess_model() const
191191
// library functions may introduce inline assembler
192192
while(has_asm(*implementation->model))
193193
{
194-
remove_asm(*implementation->model);
194+
remove_asm(*implementation->model, *implementation->message_handler);
195195
link_to_library(
196196
*implementation->model,
197197
*implementation->message_handler,

0 commit comments

Comments
 (0)