22#define WASM_SYMVAL_FACTORY_HPP
33
44#include " heap_mem_bookkeeper.hpp"
5- #include " symval_decl.hpp"
65#include " symbolic_decl.hpp"
6+ #include " symval_decl.hpp"
77
88namespace SVFactory {
99
@@ -116,7 +116,7 @@ struct UnaryOpKeyHash {
116116
117117// Caches.
118118static std::unordered_map<int , SymVal> SymbolStore;
119- static std::unordered_map<int64_t , SymVal> concrete_pool ;
119+ static std::unordered_map<int64_t , SymVal> FPStore ;
120120static std::unordered_map<SmallBVKey, SymVal, SmallBVKeyHash> SmallBVStore;
121121static std::unordered_map<ExtractKey, SymVal, ExtractKeyHash>
122122 ExtractOperationStore;
@@ -126,26 +126,27 @@ static std::unordered_map<UnaryOpKey, SymVal, UnaryOpKeyHash>
126126
127127// Factory implementations.
128128inline SymVal make_concrete_bv (Num num, int width) {
129- auto it = concrete_pool.find (num.toInt ());
130- if (it != concrete_pool.end ()) {
129+ auto key = SmallBVKey (width, num.toInt64 ());
130+ auto it = SmallBVStore.find (key);
131+ if (it != SmallBVStore.end ()) {
131132 return it->second ;
132133 }
133134
134135 auto new_val =
135136 SymVal (SymBookKeeper.allocate <SymConcrete>(num, KindBV, width));
136- concrete_pool .insert ({num. toInt () , new_val});
137+ SmallBVStore .insert ({key , new_val});
137138 return new_val;
138139}
139140
140141inline SymVal make_concrete_fp (Num num, int width) {
141- auto it = concrete_pool .find (num.toInt ());
142- if (it != concrete_pool .end ()) {
142+ auto it = FPStore .find (num.toInt64 ());
143+ if (it != FPStore .end ()) {
143144 return it->second ;
144145 }
145146
146147 auto new_val =
147148 SymVal (SymBookKeeper.allocate <SymConcrete>(num, KindFP, width));
148- concrete_pool .insert ({num.toInt (), new_val});
149+ FPStore .insert ({num.toInt64 (), new_val});
149150 return new_val;
150151}
151152
@@ -205,7 +206,8 @@ inline SymVal make_extract(const SymVal &value, int high, int low) {
205206
206207 if (auto concrete = std::dynamic_pointer_cast<SymConcrete>(value.symptr )) {
207208 if (concrete->kind != KindBV) {
208- throw std::runtime_error (" Extract only supports bitvector concrete values" );
209+ throw std::runtime_error (
210+ " Extract only supports bitvector concrete values" );
209211 }
210212 // extract from concrete bitvector value
211213 int64_t val = concrete->value .value ;
@@ -520,7 +522,8 @@ inline SymVal make_binary(BinOperation op, const SymVal &lhs,
520522 }
521523 }
522524
523- auto result = SymVal (SVFactory::SymBookKeeper.allocate <SymBinary>(op, lhs, rhs));
525+ auto result =
526+ SymVal (SVFactory::SymBookKeeper.allocate <SymBinary>(op, lhs, rhs));
524527 BinaryOperationStore.insert ({key, result});
525528 return result;
526529}
@@ -594,8 +597,8 @@ inline SymVal make_unary(UnaryOperation op, const SymVal &value) {
594597 break ;
595598 }
596599 if (negated_op != inner_binary->op ) {
597- auto result =
598- SVFactory::make_binary (negated_op, inner_binary-> lhs , inner_binary->rhs );
600+ auto result = SVFactory::make_binary (negated_op, inner_binary-> lhs ,
601+ inner_binary->rhs );
599602 UnaryOperationStore.insert ({key, result});
600603 return result;
601604 }
@@ -609,7 +612,8 @@ inline SymVal make_unary(UnaryOperation op, const SymVal &value) {
609612
610613inline SymVal make_concat (const SymVal &lhs, const SymVal &rhs) {
611614 if (auto lhs_concrete = std::dynamic_pointer_cast<SymConcrete>(lhs.symptr )) {
612- if (auto rhs_concrete = std::dynamic_pointer_cast<SymConcrete>(rhs.symptr )) {
615+ if (auto rhs_concrete =
616+ std::dynamic_pointer_cast<SymConcrete>(rhs.symptr )) {
613617 if (lhs_concrete->kind == KindBV && rhs_concrete->kind == KindBV) {
614618 int new_width = lhs_concrete->width () + rhs_concrete->width ();
615619 int64_t new_value =
0 commit comments