retdec
used_types_visitor.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_ANALYSIS_USED_TYPES_VISITOR_H
8 #define RETDEC_LLVMIR2HLL_ANALYSIS_USED_TYPES_VISITOR_H
9 
10 #include <cstddef>
11 
16 
17 namespace retdec {
18 namespace llvmir2hll {
19 
20 class Value;
21 class Type;
22 
30 class UsedTypes {
31  friend class UsedTypesVisitor;
32 
33 public:
35  using type_iterator = TypeSet::const_iterator;
36 
38  using struct_type_iterator = StructTypeSet::const_iterator;
39 
40 public:
41  UsedTypes(const UsedTypes &other);
42 
43  UsedTypes &operator=(const UsedTypes &other);
44  bool operator==(const UsedTypes &other) const;
45  bool operator!=(const UsedTypes &other) const;
46 
47  TypeSet getIntTypes() const;
48  TypeSet getSignedIntTypes() const;
50  TypeSet getFloatTypes() const;
52  TypeSet getOtherTypes() const;
53  TypeSet getAllTypes() const;
54  std::size_t getCount(bool intTy = true, bool floatTy = true,
55  bool structTy = true, bool otherTy = true) const;
56  bool isUsedBool() const;
57 
60  type_iterator int_begin() const;
61  type_iterator int_end() const;
62 
65 
68 
69  type_iterator float_begin() const;
70  type_iterator float_end() const;
71 
74 
75  type_iterator other_begin() const;
76  type_iterator other_end() const;
77 
78  type_iterator all_begin() const;
79  type_iterator all_end() const;
81 
82 private:
83  UsedTypes();
84 
85 private:
88 
91 
94 
97 
100 
103 
106 
108  bool usedBool;
109 };
110 
119 public:
121 
122 private:
123  explicit UsedTypesVisitor();
124 
128  virtual void visit(ShPtr<Function> func) override;
129  virtual void visit(ShPtr<Variable> var) override;
130  virtual void visit(ShPtr<ConstBool> constant) override;
131  // Casts
132  virtual void visit(ShPtr<BitCastExpr> expr) override;
133  virtual void visit(ShPtr<ExtCastExpr> expr) override;
134  virtual void visit(ShPtr<FPToIntCastExpr> expr) override;
135  virtual void visit(ShPtr<IntToFPCastExpr> expr) override;
136  virtual void visit(ShPtr<IntToPtrCastExpr> expr) override;
137  virtual void visit(ShPtr<PtrToIntCastExpr> expr) override;
138  virtual void visit(ShPtr<TruncCastExpr> expr) override;
139  // Types
140  virtual void visit(ShPtr<FloatType> type) override;
141  virtual void visit(ShPtr<IntType> type) override;
142  virtual void visit(ShPtr<PointerType> type) override;
143  virtual void visit(ShPtr<StringType> type) override;
144  virtual void visit(ShPtr<ArrayType> type) override;
145  virtual void visit(ShPtr<StructType> type) override;
146  virtual void visit(ShPtr<FunctionType> type) override;
147  virtual void visit(ShPtr<VoidType> type) override;
148  virtual void visit(ShPtr<UnknownType> type) override;
150 
151 private:
154 };
155 
156 } // namespace llvmir2hll
157 } // namespace retdec
158 
159 #endif
A visitor that visits everything in an ordered way.
Definition: ordered_all_visitor.h:44
virtual void visit(ShPtr< GlobalVarDef > varDef) override
Definition: ordered_all_visitor.cpp:95
A visitor for obtaining the used types in the IR.
Definition: used_types_visitor.h:118
virtual void visit(ShPtr< GlobalVarDef > varDef) override
Definition: ordered_all_visitor.cpp:95
ShPtr< UsedTypes > usedTypes
Set of used types.
Definition: used_types_visitor.h:153
static ShPtr< UsedTypes > getUsedTypes(ShPtr< Module > module)
Returns the set of used types in the given module.
Definition: used_types_visitor.cpp:268
UsedTypesVisitor()
Constructs a new visitor.
Definition: used_types_visitor.cpp:260
Used types in a module.
Definition: used_types_visitor.h:30
type_iterator int_end() const
Returns an iterator past the last int type.
Definition: used_types_visitor.cpp:197
TypeSet unsignedIntTypes
Set of unsigned integer types.
Definition: used_types_visitor.h:93
type_iterator other_begin() const
Returns an iterator to the first other type.
Definition: used_types_visitor.cpp:232
TypeSet getOtherTypes() const
Returns the other types (int, float, struct not included).
Definition: used_types_visitor.cpp:111
type_iterator signed_int_end() const
Returns an iterator past the last signed int type.
Definition: used_types_visitor.cpp:169
type_iterator unsigned_int_begin() const
Returns an iterator to the first unsigned int type.
Definition: used_types_visitor.cpp:176
UsedTypes & operator=(const UsedTypes &other)
Assigns other to the current object.
TypeSet getUnsignedIntTypes() const
Returns the unsigned integer types.
Definition: used_types_visitor.cpp:90
std::size_t getCount(bool intTy=true, bool floatTy=true, bool structTy=true, bool otherTy=true) const
Returns the number of used types.
Definition: used_types_visitor.cpp:133
struct_type_iterator struct_begin() const
Returns an iterator to the first struct type.
Definition: used_types_visitor.cpp:218
type_iterator float_end() const
Returns an iterator past the last float type.
Definition: used_types_visitor.cpp:211
TypeSet getIntTypes() const
Returns the integer types.
Definition: used_types_visitor.cpp:76
type_iterator all_begin() const
Returns an iterator to the first type.
Definition: used_types_visitor.cpp:246
bool isUsedBool() const
Returns true if the bool type was detected, false otherwise.
Definition: used_types_visitor.cpp:155
TypeSet getFloatTypes() const
Returns the float types.
Definition: used_types_visitor.cpp:97
type_iterator all_end() const
Returns an iterator past the last type.
Definition: used_types_visitor.cpp:253
type_iterator signed_int_begin() const
Returns an iterator to the first signed int type.
Definition: used_types_visitor.cpp:162
UsedTypes(const UsedTypes &other)
Constructs a new UsedTypes object from other.
TypeSet getAllTypes() const
Returns the all types (int, float, struct included).
Definition: used_types_visitor.cpp:118
StructTypeSet structTypes
Set of structure types.
Definition: used_types_visitor.h:99
TypeSet signedIntTypes
Set of signed integer types.
Definition: used_types_visitor.h:90
bool operator!=(const UsedTypes &other) const
Returns true if the current object is not equal to other, false otherwise.
Definition: used_types_visitor.cpp:69
TypeSet intTypes
Set of all integer types.
Definition: used_types_visitor.h:87
bool usedBool
Is bool type used?
Definition: used_types_visitor.h:108
TypeSet allTypes
Set of all types (integer, float, structs and other).
Definition: used_types_visitor.h:105
StructTypeSet::const_iterator struct_type_iterator
Struct types iterator.
Definition: used_types_visitor.h:38
TypeSet::const_iterator type_iterator
Types iterator.
Definition: used_types_visitor.h:35
StructTypeSet getStructTypes() const
Returns the structure types.
Definition: used_types_visitor.cpp:104
bool operator==(const UsedTypes &other) const
Returns true if the current object is equal to other, false otherwise.
Definition: used_types_visitor.cpp:56
UsedTypes()
Constructs a new UsedTypes object.
Definition: used_types_visitor.cpp:39
TypeSet floatTypes
Set of float types.
Definition: used_types_visitor.h:96
TypeSet getSignedIntTypes() const
Returns the signed integer types.
Definition: used_types_visitor.cpp:83
type_iterator float_begin() const
Returns an iterator to the first float type.
Definition: used_types_visitor.cpp:204
struct_type_iterator struct_end() const
Returns an iterator past the last struct type.
Definition: used_types_visitor.cpp:225
TypeSet otherTypes
Set of other types (integer, float, structs are not included).
Definition: used_types_visitor.h:102
type_iterator int_begin() const
Returns an iterator to the first int type.
Definition: used_types_visitor.cpp:190
type_iterator other_end() const
Returns an iterator past the last other type.
Definition: used_types_visitor.cpp:239
type_iterator unsigned_int_end() const
Returns an iterator past the last unsigned int type.
Definition: used_types_visitor.cpp:183
A mixin to make classes non-copyable.
Definition: non_copyable.h:27
ShPtr< Module > module
The current module.
Definition: hll_writer.cpp:100
A library providing API for working with back-end IR.
std::shared_ptr< T > ShPtr
An alias for a shared pointer.
Definition: smart_ptr.h:18
std::set< ShPtr< Type > > TypeSet
Set of types.
Definition: types.h:63
std::set< ShPtr< StructType > > StructTypeSet
Set of structured types.
Definition: types.h:66
Definition: archive_wrapper.h:19
A mixin to make classes non-copyable.
A visitor that visits everything in an ordered way.
Declarations, aliases, macros, etc. for the use of smart pointers.
Aliases for several useful types.