Go to the documentation of this file.
79 irep_idt function_identifier = function_base_name;
88 if(it->operands().size() == 2)
98 if(it->operands().size() == 2)
119 symbol.
name = function_identifier;
120 symbol.
type = fkt_type;
133 "function types should match");
149 irep_idt function_identifier = function_base_name;
167 symbol.
name = function_identifier;
168 symbol.
type = fkt_type;
181 "function types should match");
201 else if(flavor == ID_msc)
218 std::istringstream str(
id2string(i_str));
224 bool unknown =
false;
225 bool x86_32_locked_atomic =
false;
229 if(instruction.empty())
233 std::cout <<
"A ********************\n";
234 for(
const auto &ins : instruction)
236 std::cout <<
"XX: " << ins.pretty() <<
'\n';
239 std::cout <<
"B ********************\n";
247 instruction.front().id() == ID_symbol &&
248 instruction.front().get(ID_identifier) ==
"lock")
250 x86_32_locked_atomic =
true;
255 if(
pos == instruction.size())
258 if(instruction[
pos].
id() == ID_symbol)
260 command = instruction[
pos].get(ID_identifier);
264 if(command ==
"xchg" || command ==
"xchgl")
265 x86_32_locked_atomic =
true;
267 if(x86_32_locked_atomic)
271 codet code_fence(ID_fence);
273 code_fence.
set(ID_WWfence,
true);
274 code_fence.
set(ID_RRfence,
true);
275 code_fence.
set(ID_RWfence,
true);
276 code_fence.
set(ID_WRfence,
true);
282 if(command ==
"fstcw" || command ==
"fnstcw" || command ==
"fldcw")
287 command ==
"mfence" || command ==
"lfence" || command ==
"sfence")
291 else if(command == ID_sync)
293 codet code_fence(ID_fence);
295 code_fence.
set(ID_WWfence,
true);
296 code_fence.
set(ID_RRfence,
true);
297 code_fence.
set(ID_RWfence,
true);
298 code_fence.
set(ID_WRfence,
true);
299 code_fence.
set(ID_WWcumul,
true);
300 code_fence.
set(ID_RWcumul,
true);
301 code_fence.
set(ID_RRcumul,
true);
302 code_fence.
set(ID_WRcumul,
true);
307 else if(command == ID_lwsync)
309 codet code_fence(ID_fence);
311 code_fence.
set(ID_WWfence,
true);
312 code_fence.
set(ID_RRfence,
true);
313 code_fence.
set(ID_RWfence,
true);
314 code_fence.
set(ID_WWcumul,
true);
315 code_fence.
set(ID_RWcumul,
true);
316 code_fence.
set(ID_RRcumul,
true);
321 else if(command == ID_isync)
323 codet code_fence(ID_fence);
331 else if(command ==
"dmb" || command ==
"dsb")
333 codet code_fence(ID_fence);
335 code_fence.
set(ID_WWfence,
true);
336 code_fence.
set(ID_RRfence,
true);
337 code_fence.
set(ID_RWfence,
true);
338 code_fence.
set(ID_WRfence,
true);
339 code_fence.
set(ID_WWcumul,
true);
340 code_fence.
set(ID_RWcumul,
true);
341 code_fence.
set(ID_RRcumul,
true);
342 code_fence.
set(ID_WRcumul,
true);
347 else if(command ==
"isb")
349 codet code_fence(ID_fence);
360 if(x86_32_locked_atomic)
364 x86_32_locked_atomic =
false;
387 std::istringstream str(
id2string(i_str));
393 bool unknown =
false;
394 bool x86_32_locked_atomic =
false;
398 if(instruction.empty())
402 std::cout <<
"A ********************\n";
403 for(
const auto &ins : instruction)
405 std::cout <<
"XX: " << ins.pretty() <<
'\n';
408 std::cout <<
"B ********************\n";
416 instruction.front().id() == ID_symbol &&
417 instruction.front().get(ID_identifier) ==
"lock")
419 x86_32_locked_atomic =
true;
424 if(
pos == instruction.size())
427 if(instruction[
pos].
id() == ID_symbol)
429 command = instruction[
pos].get(ID_identifier);
433 if(command ==
"xchg" || command ==
"xchgl")
434 x86_32_locked_atomic =
true;
436 if(x86_32_locked_atomic)
440 codet code_fence(ID_fence);
442 code_fence.
set(ID_WWfence,
true);
443 code_fence.
set(ID_RRfence,
true);
444 code_fence.
set(ID_RWfence,
true);
445 code_fence.
set(ID_WRfence,
true);
451 if(command ==
"fstcw" || command ==
"fnstcw" || command ==
"fldcw")
456 command ==
"mfence" || command ==
"lfence" || command ==
"sfence")
463 if(x86_32_locked_atomic)
467 x86_32_locked_atomic =
false;
486 bool did_something =
false;
490 if(it->is_other() && it->get_other().get_statement() == ID_asm)
494 it->turn_into_skip();
495 did_something =
true;
500 goto_function.body.destructive_insert(next, tmp_dest);
#define Forall_goto_program_instructions(it, program)
static instructiont make_other(const goto_instruction_codet &_code, const source_locationt &l=source_locationt::nil())
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
codet representation of an inline assembler statement, for the gcc flavor.
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
codet representation of an inline assembler statement.
const goto_instruction_codet & get_other() const
Get the statement for OTHER.
The type of an expression, extends irept.
goto_functionst & goto_functions
typet type
Type of symbol.
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
const string_constantt & to_string_constant(const exprt &expr)
targett add(instructiont &&instruction)
Adds a given instruction at the end.
irep_idt base_name
Base (non-scoped) name.
void process_instruction_msc(const code_asmt &, goto_programt &dest)
Translates the given inline assembly code (in msc style) to non-assembly goto program instructions.
function_mapt function_map
Expression to hold a symbol (variable)
assembler_parsert assembler_parser
void process_function(goto_functionst::goto_functiont &)
Replaces inline assembly instructions in the goto function by non-assembly goto program instructions.
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
static instructiont make_function_call(const code_function_callt &_code, const source_locationt &l=source_locationt::nil())
Create a function call instruction.
goto_instruction_codet representation of a function call statement.
irep_idt mode
Language mode.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
const std::string & id2string(const irep_idt &d)
#define forall_operands(it, expr)
void set(const irep_idt &name, const irep_idt &value)
remove_asmt(symbol_tablet &_symbol_table, goto_functionst &_goto_functions)
void gcc_asm_function_call(const irep_idt &function_base_name, const code_asm_gcct &code, goto_programt &dest)
Adds a call to a library function that implements the given gcc-style inline assembly statement.
pointer_typet pointer_type(const typet &subtype)
static instructiont make_atomic_begin(const source_locationt &l=source_locationt::nil())
void process_instruction_gcc(const code_asm_gcct &, goto_programt &dest)
Translates the given inline assembly code (in gcc style) to non-assembly goto program instructions.
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
exprt::operandst argumentst
code_asm_gcct & to_code_asm_gcc(codet &code)
std::list< instructiont > instructions
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
::goto_functiont goto_functiont
code_asmt & to_code_asm(codet &code)
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
A collection of goto functions.
exprt value
Initial value of symbol.
goto_functionst goto_functions
GOTO functions.
void remove_asm(goto_functionst &goto_functions, symbol_tablet &symbol_table)
Replaces inline assembly instructions in the goto program (i.e., instructions of kind OTHER with a co...
A generic container class for the GOTO intermediate representation of one function.
Operator to return the address of an object.
source_locationt & add_source_location()
void msc_asm_function_call(const irep_idt &function_base_name, const code_asmt &code, goto_programt &dest)
Adds a call to a library function that implements the given msc-style inline assembly statement.
const irep_idt & get_flavor() const
Semantic type conversion.
symbol_tablet & symbol_table
This class represents an instruction in the GOTO intermediate representation.
const source_locationt & source_location() const
symbol_tablet symbol_table
Symbol table.
irep_idt name
The unique identifier.
const irep_idt & get_value() const
instructionst::iterator targett
static instructiont make_atomic_end(const source_locationt &l=source_locationt::nil())
void process_instruction(goto_programt::instructiont &instruction, goto_programt &dest)
Translates the given inline assembly code (which must be in either gcc or msc style) to non-assembly ...
Data structure for representing an arbitrary statement in a program.