retdec
const_float.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_IR_CONST_FLOAT_H
8 #define RETDEC_LLVMIR2HLL_IR_CONST_FLOAT_H
9 
10 #include <string>
11 #include <utility>
12 
13 #include <llvm/ADT/APFloat.h>
14 
17 
18 namespace retdec {
19 namespace llvmir2hll {
20 
21 class Expression;
22 class FloatType;
23 class Visitor;
24 
31 class ConstFloat final: public Constant {
32 public:
34  // We use the arbitrary precision floats from LLVM to store constant
35  // floats. This way, we don't have to use another 3rd party library or
36  // craft some custom code.
37  using Type = llvm::APFloat;
38 
39 public:
41 
42  virtual ShPtr<Value> clone() override;
43 
44  virtual bool isEqualTo(ShPtr<Value> otherValue) const override;
45  virtual ShPtr<retdec::llvmir2hll::Type> getType() const override;
46  virtual void replace(ShPtr<Expression> oldExpr,
47  ShPtr<Expression> newExpr) override;
48 
49  Type getValue() const;
50  unsigned getSize() const;
51  std::string toString(unsigned precision = 0, unsigned maxPadding = 0) const;
52  std::string toMostReadableString() const;
53 
54  void flipSign();
55 
56  bool isNegative() const;
57  bool isNegativeOne() const;
58  bool isPositive() const;
59  bool isZero() const;
60 
63  virtual void accept(Visitor *v) override;
65 
66 private:
68  using ToStringArgs = std::pair<unsigned, unsigned>;
69 
70 private:
73 
76 
77 private:
78  // Since instances are created by calling the static function create(), the
79  // constructor can be private.
80  explicit ConstFloat(Type value);
81 
83 };
84 
85 } // namespace llvmir2hll
86 } // namespace retdec
87 
88 #endif
A float constant.
Definition: const_float.h:31
bool isNegativeOne() const
Determines whether the float constant is negative one.
Definition: const_float.cpp:225
void flipSign()
Flip the sign of value.
Definition: const_float.cpp:208
virtual bool isEqualTo(ShPtr< Value > otherValue) const override
Returns true if this value is equal to otherValue, false otherwise.
Definition: const_float.cpp:69
ToStringArgs getToStringArgsForMostReadableString() const
Returns the arguments for which toString() returns the most readable string.
Definition: const_float.cpp:176
virtual void replace(ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr) override
Replaces all occurrences of oldExpr with newExpr in the current expression.
Definition: const_float.cpp:84
ConstFloat(Type value)
Constructs a float constant initialized to the given value.
Definition: const_float.cpp:60
bool isPositive() const
Determines whether the float constant is positive (> 0).
Definition: const_float.cpp:233
virtual ShPtr< retdec::llvmir2hll::Type > getType() const override
Returns the type of the expression.
Definition: const_float.cpp:80
Type getValue() const
Returns the constant's value.
Definition: const_float.cpp:93
bool isNegative() const
Determines whether the float constant is negative (< 0).
Definition: const_float.cpp:217
std::string toString(unsigned precision=0, unsigned maxPadding=0) const
Converts the constant into a decimal string.
Definition: const_float.cpp:132
std::string toMostReadableString() const
Converts the constant into the most readable decimal representation.
Definition: const_float.cpp:155
virtual void accept(Visitor *v) override
Visitor pattern implementation.
Definition: const_float.cpp:253
static ShPtr< ConstFloat > create(Type value)
Constructs a float constant initialized to the given value.
Definition: const_float.cpp:249
llvm::APFloat Type
Underlying floating-point type.
Definition: const_float.h:37
ShPtr< FloatType > type
Type of the constant.
Definition: const_float.h:75
bool isZero() const
Determines whether the float constant is zero.
Definition: const_float.cpp:240
std::pair< unsigned, unsigned > ToStringArgs
Arguments of toString().
Definition: const_float.h:68
unsigned getSize() const
Returns the number of bits of the constant's type.
Definition: const_float.cpp:100
Type value
Value of the constant.
Definition: const_float.h:72
virtual ShPtr< Value > clone() override
Returns a clone of the value.
Definition: const_float.cpp:63
A base class for all constants.
Definition: constant.h:20
A base class of all visitors.
Definition: visitor.h:95
A base class for all constants.
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
Definition: archive_wrapper.h:19
Declarations, aliases, macros, etc. for the use of smart pointers.