|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: Statement List Language Conversion |
| 4 | +
|
| 5 | +Author: Matthias Weiss, [email protected] |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +/// \file |
| 10 | +/// Statement List Language Conversion |
| 11 | + |
| 12 | +#include "convert_int_literal.h" |
| 13 | + |
| 14 | +#include <algorithm> |
| 15 | +#include <util/std_types.h> |
| 16 | + |
| 17 | +/// Hex literals in STL are preceded by '16#' |
| 18 | +#define HEX_PREFIX_LENGTH 3 |
| 19 | +/// Binary literals in STL are preceded by '2#' |
| 20 | +#define BINARY_PREFIX_LENGTH 2 |
| 21 | + |
| 22 | +constant_exprt convert_int_dec_literal(const std::string &src) |
| 23 | +{ |
| 24 | + std::string value(src); |
| 25 | + value.erase(std::remove(begin(value), end(value), '+'), end(value)); |
| 26 | + |
| 27 | + signedbv_typet type{16}; |
| 28 | + type.set(ID_statement_list_type, ID_statement_list_int); |
| 29 | + |
| 30 | + return constant_exprt(value, type); |
| 31 | +} |
| 32 | + |
| 33 | +constant_exprt convert_int_hex_literal(const std::string &src) |
| 34 | +{ |
| 35 | + const std::string hex_literal( |
| 36 | + src.substr(HEX_PREFIX_LENGTH, std::string::npos)); |
| 37 | + int value = std::stoi(hex_literal, nullptr, 16); |
| 38 | + |
| 39 | + signedbv_typet type{16}; |
| 40 | + type.set(ID_statement_list_type, ID_statement_list_int); |
| 41 | + |
| 42 | + return constant_exprt(std::to_string(value), type); |
| 43 | +} |
| 44 | + |
| 45 | +constant_exprt convert_int_bit_literal(const std::string &src) |
| 46 | +{ |
| 47 | + const std::string bit_literal( |
| 48 | + src.substr(BINARY_PREFIX_LENGTH, std::string::npos)); |
| 49 | + int value = std::stoi(bit_literal, nullptr, 2); |
| 50 | + |
| 51 | + signedbv_typet type{16}; |
| 52 | + type.set(ID_statement_list_type, ID_statement_list_int); |
| 53 | + |
| 54 | + return constant_exprt{std::to_string(value), type}; |
| 55 | +} |
0 commit comments