@@ -597,16 +597,25 @@ exprt interpretert::get_value(
597
597
exprt result=array_exprt (to_array_type (real_type));
598
598
const exprt &size_expr=static_cast <const exprt &>(type.find (ID_size));
599
599
size_t subtype_size=get_size (type.subtype ());
600
- mp_integer mp_count;
601
- to_integer (size_expr, mp_count);
602
- unsigned count=integer2unsigned (mp_count);
600
+ std::size_t count;
601
+ if (size_expr.id ()!=ID_constant)
602
+ {
603
+ count=base_address_to_actual_size (offset)/subtype_size;
604
+ }
605
+ else
606
+ {
607
+ mp_integer mp_count;
608
+ to_integer (size_expr, mp_count);
609
+ count=integer2size_t (mp_count);
610
+ }
603
611
604
612
// Retrieve the value for each member in the array
605
613
result.reserve_operands (count);
606
614
for (unsigned i=0 ; i<count; i++)
607
615
{
608
- const exprt operand=get_value (type.subtype (),
609
- offset+i*subtype_size);
616
+ const exprt operand=get_value (
617
+ type.subtype (),
618
+ offset+i*subtype_size);
610
619
result.copy_to_operands (operand);
611
620
}
612
621
return result;
@@ -663,9 +672,17 @@ exprt interpretert::get_value(
663
672
664
673
// Get size of array
665
674
size_t subtype_size=get_size (type.subtype ());
666
- mp_integer mp_count;
667
- to_integer (size_expr, mp_count);
668
- unsigned count=integer2unsigned (mp_count);
675
+ unsigned count;
676
+ if (unbounded_size (type))
677
+ {
678
+ count=base_address_to_actual_size (offset)/subtype_size;
679
+ }
680
+ else
681
+ {
682
+ mp_integer mp_count;
683
+ to_integer (size_expr, mp_count);
684
+ count=integer2unsigned (mp_count);
685
+ }
669
686
670
687
// Retrieve the value for each member in the array
671
688
result.reserve_operands (count);
@@ -712,22 +729,24 @@ exprt interpretert::get_value(
712
729
if (rhs[offset]<memory.size ())
713
730
{
714
731
// We want the symbol pointed to
715
- memory_cellt &cell=memory[integer2unsigned (rhs[offset])];
716
- const typet type=get_type (cell.identifier );
732
+ std::size_t address=integer2size_t (rhs[offset]);
733
+ irep_idt identifier=address_to_identifier (address);
734
+ size_t offset=address_to_offset (address);
735
+ const typet type=get_type (identifier);
717
736
exprt symbol_expr (ID_symbol, type);
718
- symbol_expr.set (ID_identifier, cell. identifier );
737
+ symbol_expr.set (ID_identifier, identifier);
719
738
720
- if (cell. offset ==0 )
739
+ if (offset==0 )
721
740
return address_of_exprt (symbol_expr);
722
741
if (ns.follow (type).id ()==ID_struct)
723
742
{
724
- irep_idt member_id=get_component_id (cell. identifier , cell. offset );
743
+ irep_idt member_id=get_component_id (identifier, offset);
725
744
member_exprt member_expr (symbol_expr, member_id);
726
745
return address_of_exprt (member_expr);
727
746
}
728
747
index_exprt index_expr (
729
748
symbol_expr,
730
- from_integer (cell. offset , integer_typet ()));
749
+ from_integer (offset, integer_typet ()));
731
750
return index_expr;
732
751
}
733
752
@@ -828,12 +847,13 @@ void interpretert::assign(
828
847
{
829
848
if ((address+i)<memory.size ())
830
849
{
831
- memory_cellt &cell=memory[integer2unsigned (address+i)];
850
+ std::size_t address_val=integer2size_t (address+i);
851
+ memory_cellt &cell=memory[address_val];
832
852
if (show)
833
853
{
834
854
status () << total_steps << " ** assigning "
835
- << cell. identifier << " ["
836
- << cell. offset << " ]:=" << rhs[i]
855
+ << address_to_identifier (address_val) << " ["
856
+ << address_to_offset (address_val) << " ]:=" << rhs[i]
837
857
<< " \n " << eom;
838
858
}
839
859
cell.value =rhs[i];
@@ -913,8 +933,11 @@ void interpretert::execute_function_call()
913
933
// Retrieve the empty last trace step struct we pushed for this step
914
934
// of the interpreter run to fill it with the corresponding data
915
935
goto_trace_stept &trace_step=steps.get_last_step ();
916
- const memory_cellt &cell=memory[integer2size_t (a)];
917
- const irep_idt &identifier=cell.identifier ;
936
+ std::size_t address=integer2size_t (a);
937
+ #if 0
938
+ const memory_cellt &cell=memory[address];
939
+ #endif
940
+ const irep_idt &identifier=address_to_identifier (address);
918
941
trace_step.identifier =identifier;
919
942
920
943
const goto_functionst::function_mapt::const_iterator f_it=
@@ -1020,9 +1043,7 @@ void interpretert::build_memory_map()
1020
1043
{
1021
1044
// put in a dummy for NULL
1022
1045
memory.resize (1 );
1023
- memory[0 ].offset =0 ;
1024
- memory[0 ].identifier =" NULL-OBJECT" ;
1025
- memory[0 ].initialized =0 ;
1046
+ inverse_memory_map[0 ]=" NULL-OBJECT" ;
1026
1047
1027
1048
num_dynamic_objects=0 ;
1028
1049
dynamic_types.clear ();
@@ -1062,18 +1083,10 @@ void interpretert::build_memory_map(const symbolt &symbol)
1062
1083
1063
1084
if (size!=0 )
1064
1085
{
1065
- unsigned address=memory.size ();
1086
+ std:: size_t address=memory.size ();
1066
1087
memory.resize (address+size);
1067
1088
memory_map[symbol.name ]=address;
1068
-
1069
- for (size_t i=0 ; i<size; i++)
1070
- {
1071
- memory_cellt &cell=memory[address+i];
1072
- cell.identifier =symbol.name ;
1073
- cell.offset =i;
1074
- cell.value =0 ;
1075
- cell.initialized =0 ;
1076
- }
1089
+ inverse_memory_map[address]=symbol.name ;
1077
1090
}
1078
1091
}
1079
1092
@@ -1119,7 +1132,7 @@ Function: interpretert::build_memory_map
1119
1132
1120
1133
Inputs:
1121
1134
1122
- Outputs: Updtaes the memory map to include variable id if it does
1135
+ Outputs: Updates the memory map to include variable id if it does
1123
1136
not exist
1124
1137
1125
1138
Purpose: Populates dynamic entries of the memory map
@@ -1136,12 +1149,10 @@ mp_integer interpretert::build_memory_map(
1136
1149
1137
1150
if (it!=dynamic_types.end ())
1138
1151
{
1139
- unsigned offset=1 ;
1140
- unsigned address=memory_map[id];
1141
- while (memory[address+offset].offset >0 ) offset++;
1142
-
1152
+ std::size_t address=memory_map[id];
1153
+ std::size_t current_size=base_address_to_alloc_size (address);
1143
1154
// current size <= size already recorded
1144
- if (size<=offset )
1155
+ if (size<=current_size )
1145
1156
return memory_map[id];
1146
1157
}
1147
1158
@@ -1151,36 +1162,54 @@ mp_integer interpretert::build_memory_map(
1151
1162
if (size==0 )
1152
1163
size=1 ; // This is a hack to create existence
1153
1164
1154
- unsigned address=memory.size ();
1165
+ std:: size_t address=memory.size ();
1155
1166
memory.resize (address+size);
1156
1167
memory_map[id]=address;
1168
+ inverse_memory_map[address]=id;
1157
1169
dynamic_types.insert (std::pair<const irep_idt, typet>(id, alloc_type));
1158
1170
1159
- for (size_t i=0 ; i<size; i++)
1171
+ return address;
1172
+ }
1173
+
1174
+ bool interpretert::unbounded_size (const typet &type)
1175
+ {
1176
+ if (type.id ()==ID_array)
1160
1177
{
1161
- memory_cellt &cell=memory[address+i];
1162
- cell.identifier =id;
1163
- cell.offset =i;
1164
- cell.value =0 ;
1165
- cell.initialized =0 ;
1178
+ const exprt &size=to_array_type (type).size ();
1179
+ if (size.id ()==ID_infinity)
1180
+ return true ;
1181
+ return unbounded_size (type.subtype ());
1166
1182
}
1167
- return address;
1183
+ else if (type.id ()==ID_struct)
1184
+ {
1185
+ const auto &st=to_struct_type (type);
1186
+ if (st.components ().empty ())
1187
+ return false ;
1188
+ return unbounded_size (st.components ().back ().type ());
1189
+ }
1190
+ return false ;
1168
1191
}
1169
1192
1170
1193
/* ******************************************************************\
1171
1194
1172
1195
Function: interpretert::get_size
1173
1196
1174
1197
Inputs:
1198
+ type - a structured type
1175
1199
1176
- Outputs:
1200
+ Outputs: Size of the given type
1177
1201
1178
- Purpose: Retrieves the actual size of the provided structured type
1202
+ Purpose: Retrieves the actual size of the provided structured type.
1203
+ Unbounded objects get allocated 2^32 address space each
1204
+ (of a 2^64 sized space).
1179
1205
1180
1206
\*******************************************************************/
1181
1207
1182
1208
size_t interpretert::get_size (const typet &type)
1183
1209
{
1210
+ if (unbounded_size (type))
1211
+ return 2ULL << 32ULL ;
1212
+
1184
1213
if (type.id ()==ID_struct)
1185
1214
{
1186
1215
const struct_typet::componentst &components=
@@ -1268,7 +1297,7 @@ exprt interpretert::get_value(const irep_idt &id)
1268
1297
symbol_exprt symbol_expr (id, get_type);
1269
1298
mp_integer whole_lhs_object_address=evaluate_address (symbol_expr);
1270
1299
1271
- return get_value (get_type, integer2unsigned (whole_lhs_object_address));
1300
+ return get_value (get_type, integer2size_t (whole_lhs_object_address));
1272
1301
}
1273
1302
1274
1303
/* ******************************************************************\
@@ -1310,10 +1339,13 @@ Function: interpretert::print_memory
1310
1339
1311
1340
void interpretert::print_memory (bool input_flags)
1312
1341
{
1313
- for (size_t i= 0 ; i<memory. size (); i++ )
1342
+ for (const auto &cell_address : memory )
1314
1343
{
1315
- memory_cellt &cell=memory[i];
1316
- debug () << cell.identifier << " [" << cell.offset << " ]"
1344
+ std::size_t i=cell_address.first ;
1345
+ const memory_cellt &cell=cell_address.second ;
1346
+ const auto identifier=address_to_identifier (i);
1347
+ const auto offset=address_to_offset (i);
1348
+ debug () << identifier << " [" << offset << " ]"
1317
1349
<< " =" << cell.value << eom;
1318
1350
if (input_flags)
1319
1351
debug () << " (" << static_cast <int >(cell.initialized ) << " )"
0 commit comments