-
Notifications
You must be signed in to change notification settings - Fork 274
Add binary representation to all bitvector values in the xml trace #5425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
33d9e32
4db7ed0
98f139d
e6174e4
9827dc9
a1eeb59
d744e2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <assert.h> | ||
#include <inttypes.h> | ||
#include <math.h> | ||
#include <stdbool.h> | ||
#include <stddef.h> | ||
#include <stdlib.h> | ||
|
||
int main() | ||
{ | ||
int8_t i1 = 2; | ||
int16_t i2 = 3; | ||
int32_t i3 = 4; | ||
int64_t i4 = 5; | ||
|
||
int8_t in1 = -2; | ||
int16_t in2 = -3; | ||
int32_t in3 = -4; | ||
int64_t in4 = -5; | ||
|
||
uint8_t u8 = 'a'; | ||
uint16_t u16 = 8; | ||
uint32_t u32 = 16; | ||
uint64_t u64 = 32; | ||
|
||
void *ptr = malloc(1); | ||
|
||
assert(false); | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CORE | ||
test.c | ||
--trace --xml-ui | ||
activate-multi-line-match | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
VERIFICATION FAILED | ||
<full_lhs>u8</full_lhs>\s*<full_lhs_value binary="01100001">97</full_lhs_value> | ||
<full_lhs>u16</full_lhs>\s*<full_lhs_value binary="0{12}1000">8</full_lhs_value> | ||
<full_lhs>u32</full_lhs>\s*<full_lhs_value binary="0{27}10000">16ul?</full_lhs_value> | ||
<full_lhs>u64</full_lhs>\s*<full_lhs_value binary="0{58}100000">32ull?</full_lhs_value> | ||
<full_lhs>i1</full_lhs>\s*<full_lhs_value binary="0{6}10">2</full_lhs_value> | ||
<full_lhs>i2</full_lhs>\s*<full_lhs_value binary="0{14}11">3</full_lhs_value> | ||
<full_lhs>i3</full_lhs>\s*<full_lhs_value binary="0{29}100">4</full_lhs_value> | ||
<full_lhs>i4</full_lhs>\s*<full_lhs_value binary="0{61}101">5ll?</full_lhs_value> | ||
<full_lhs>in1</full_lhs>\s*<full_lhs_value binary="1{6}10">-2</full_lhs_value> | ||
<full_lhs>in2</full_lhs>\s*<full_lhs_value binary="1{14}01">-3</full_lhs_value> | ||
<full_lhs>in3</full_lhs>\s*<full_lhs_value binary="1{29}100">-4</full_lhs_value> | ||
<full_lhs>in4</full_lhs>\s*<full_lhs_value binary="1{61}011">-5ll?</full_lhs_value> | ||
-- | ||
-- | ||
Checks that the binary value is printed for integral types. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,31 +25,34 @@ Author: Daniel Kroening | |
#include "structured_trace_util.h" | ||
#include "xml_expr.h" | ||
|
||
bool full_lhs_value_includes_binary( | ||
const goto_trace_stept &step, | ||
const namespacet &ns) | ||
{ | ||
return can_cast_type<floatbv_typet>(step.full_lhs_value.type()); | ||
} | ||
|
||
xmlt full_lhs_value(const goto_trace_stept &step, const namespacet &ns) | ||
{ | ||
xmlt full_lhs_value{"full_lhs_value"}; | ||
xmlt value_xml{"full_lhs_value"}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if I agree with the reasoning of this rename. I’d probably have gone for |
||
|
||
const exprt &value = step.full_lhs_value; | ||
if(value.is_nil()) | ||
return value_xml; | ||
|
||
const auto &lhs_object = step.get_lhs_object(); | ||
const irep_idt identifier = | ||
lhs_object.has_value() ? lhs_object->get_identifier() : irep_idt(); | ||
value_xml.data = from_expr(ns, identifier, value); | ||
|
||
if(step.full_lhs_value.is_not_nil()) | ||
full_lhs_value.data = from_expr(ns, identifier, step.full_lhs_value); | ||
if(full_lhs_value_includes_binary(step, ns)) | ||
const auto &bv_type = type_try_dynamic_cast<bitvector_typet>(value.type()); | ||
const auto &constant = expr_try_dynamic_cast<constant_exprt>(value); | ||
if(bv_type && constant) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did like the |
||
{ | ||
const auto width = to_floatbv_type(step.full_lhs_value.type()).get_width(); | ||
const auto binary_representation = integer2binary( | ||
bvrep2integer(step.full_lhs_value.get(ID_value), width, false), width); | ||
full_lhs_value.set_attribute("binary", binary_representation); | ||
const auto width = bv_type->get_width(); | ||
// It is fine to pass `false` into the `is_signed` parameter, even for | ||
// signed values, because the subsequent conversion to binary will result | ||
// in the same value either way. E.g. if the value is `-1` for a signed 8 | ||
// bit value, this will convert to `255` which is `11111111` in binary, | ||
// which is the desired result. | ||
const auto binary_representation = | ||
integer2binary(bvrep2integer(constant->get_value(), width, false), width); | ||
value_xml.set_attribute("binary", binary_representation); | ||
} | ||
return full_lhs_value; | ||
return value_xml; | ||
} | ||
|
||
void convert( | ||
|
Uh oh!
There was an error while loading. Please reload this page.