PandA-2024.02
bit_lattice.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
41 #ifndef _BIT_LATTICE_HPP_
42 #define _BIT_LATTICE_HPP_
43 
45 #include <string>
46 
48 #include "custom_map.hpp"
49 #include "custom_set.hpp"
50 #include <deque>
51 
52 #include "panda_types.hpp"
53 #include "refcount.hpp"
54 
59 
60 enum class bit_lattice
61 {
62  U,
63  ZERO,
64  ONE,
65  X
66 };
67 
69 {
70  protected:
72 
79 
86 
91 
94  const int bl_debug_level;
95 
96  bool IsSignedIntegerType(const tree_nodeConstRef& tn) const;
97 
105  std::deque<bit_lattice> sup(const std::deque<bit_lattice>& a, const std::deque<bit_lattice>& b,
106  const unsigned int output_uid) const;
107 
108  std::deque<bit_lattice> sup(const std::deque<bit_lattice>& a, const std::deque<bit_lattice>& b,
109  const tree_nodeConstRef& out_node) const;
110 
118  std::deque<bit_lattice> inf(const std::deque<bit_lattice>& a, const std::deque<bit_lattice>& b,
119  const unsigned int output_uid) const;
120 
121  std::deque<bit_lattice> inf(const std::deque<bit_lattice>& a, const std::deque<bit_lattice>& b,
122  const tree_nodeConstRef& out_node) const;
123 
129  std::deque<bit_lattice> constructor_bitstring(const tree_nodeRef& ctor_tn, unsigned int ssa_node_id) const;
130 
136  std::deque<bit_lattice> string_cst_bitstring(const tree_nodeRef& strcst_tn, unsigned int ssa_node_id) const;
137 
142  bool IsHandledByBitvalue(const tree_nodeConstRef& tn) const;
143 
149  bool mix();
150 
156  bool update_current(std::deque<bit_lattice>& res, const tree_nodeConstRef& tn);
157 
161  void clear();
162 
163  public:
167  explicit BitLatticeManipulator(const tree_managerConstRef TM, const int debug_level);
168 
173 
181  static std::deque<bit_lattice> sign_extend_bitstring(const std::deque<bit_lattice>& bitstring,
182  bool bitstring_is_signed, size_t final_size);
183 
191  static void sign_reduce_bitstring(std::deque<bit_lattice>& bitstring, bool bitstring_is_signed);
192 
193  static bit_lattice bit_sup(const bit_lattice a, const bit_lattice b);
194 
195  static bit_lattice bit_inf(const bit_lattice a, const bit_lattice b);
196 
197  static std::deque<bit_lattice> sup(const std::deque<bit_lattice>& a, const std::deque<bit_lattice>& b,
198  const size_t out_type_size, const bool out_is_signed, const bool out_is_bool);
199 
200  static std::deque<bit_lattice> inf(const std::deque<bit_lattice>& a, const std::deque<bit_lattice>& b,
201  const size_t out_type_size, const bool out_is_signed, const bool out_is_bool);
202 
203  static unsigned long long Size(const tree_nodeConstRef& t);
204 
205  static unsigned long long size(const tree_managerConstRef tm, unsigned int index);
206 
207  static bool isBetter(const std::string& a_string, const std::string& b_string);
208 };
209 
215 std::deque<bit_lattice> create_u_bitstring(size_t lenght);
216 
222 std::deque<bit_lattice> create_x_bitstring(size_t lenght);
223 
231 std::deque<bit_lattice> create_bitstring_from_constant(integer_cst_t value_int, unsigned long long length,
232  bool signed_value);
233 
237 std::string bitstring_to_string(const std::deque<bit_lattice>& bitstring);
238 
242 std::deque<bit_lattice> string_to_bitstring(const std::string& s);
243 
249 bool bitstring_constant(const std::deque<bit_lattice>& a);
250 #endif
This class manages the tree structures extracted from the raw file.
std::string bitstring_to_string(const std::deque< bit_lattice > &bitstring)
Translates a bitstring ( expressed as an std::deque of bit_lattice ) into a string of characters...
CustomOrderedMap< T, U > CustomMap
Definition: custom_map.hpp:167
bool bitstring_constant(const std::deque< bit_lattice > &a)
Checks if a bitstring is constant.
redefinition of map to manage ordered/unordered structures
Abstract pure class for the tree structure.
Definition: tree_node.hpp:139
CustomSet< unsigned int > signed_var
Set storing the signed ssa.
Definition: bit_lattice.hpp:90
const int bl_debug_level
The debug level of methods of this class - it cannot be named debug_level because of ambiguity of Fro...
Definition: bit_lattice.hpp:94
static std::string sign_reduce_bitstring(std::string bitstring, bool bitstring_is_signed)
function slightly different than BitLatticeManipulator::sign_reduce_bitstring
CustomMap< unsigned int, std::deque< bit_lattice > > current
Map of the current bit-values of each variable.
Definition: bit_lattice.hpp:78
#define index(x, y)
Definition: Keccak.c:74
redefinition of set to manage ordered/unordered structures
CONSTREF_FORWARD_DECL(Parameter)
STD include.
bit_lattice
Definition: bit_lattice.hpp:60
std::deque< bit_lattice > create_x_bitstring(size_t lenght)
Create a bitstring containing bits initialized at <X>
const tree_managerConstRef TM
Definition: bit_lattice.hpp:71
Template definition of refcount.
Definition: APInt.hpp:53
REF_FORWARD_DECL(tree_node)
CustomMap< unsigned int, std::deque< bit_lattice > > best
Map of the best bit-values of each variable.
Definition: bit_lattice.hpp:85
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
std::deque< bit_lattice > create_bitstring_from_constant(integer_cst_t value_int, unsigned long long length, bool signed_value)
Creates a bitstring from a constant input.
std::deque< bit_lattice > create_u_bitstring(size_t lenght)
Creates a bitstring containing bits initialized at <U>
std::deque< bit_lattice > string_to_bitstring(const std::string &s)
inverse of bitstring_to_string

Generated on Mon Feb 12 2024 13:02:51 for PandA-2024.02 by doxygen 1.8.13