retdec
storage.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_COMMON_STORAGE_H
8 #define RETDEC_COMMON_STORAGE_H
9 
10 #include <string>
11 #include <optional>
12 
13 #include "retdec/common/address.h"
14 
15 namespace retdec {
16 namespace common {
17 
21 class Storage
22 {
23  public:
24  enum class eType
25  {
26  UNDEFINED = 0,
27  GLOBAL,
28  REGISTER,
29  STACK
30  };
31 
32  public:
33  Storage();
34 
37  static Storage undefined();
38  static Storage onStack(int offset);
39  static Storage onStack(int offset, unsigned registerNumber);
40  static Storage inMemory(const retdec::common::Address& address);
41  static Storage inRegister(const std::string& registerName);
42  static Storage inRegister(unsigned registerNumber);
43  static Storage inRegister(
44  const std::string& registerName,
45  unsigned registerNumber);
47 
50  bool isDefined() const;
51  bool isUndefined() const;
52  bool isMemory() const;
53  bool isMemory(retdec::common::Address& globalAddress) const;
54  bool isRegister() const;
55  bool isRegister(std::string& registerName) const;
56  bool isRegister(int& registerNumber) const;
57  bool isStack() const;
58  bool isStack(int& stackOffset) const;
60 
64  std::string getRegisterName() const;
65  int getStackOffset() const;
66  std::optional<unsigned> getRegisterNumber() const;
68 
71  void setRegisterNumber(unsigned registerNumber);
73 
74  protected:
75  const static int UNDEF_REG_NUM = -1;
76 
77  protected:
79 
80  int _stackOffset = 0;
81  std::string _registerName;
83 
84  std::optional<unsigned> _registerNumber;
85 };
86 
87 } // namespace common
88 } // namespace retdec
89 
90 #endif
Definition: address.h:21
Definition: storage.h:22
static Storage inMemory(const retdec::common::Address &address)
Definition: storage.cpp:48
retdec::common::Address getAddress() const
Definition: storage.cpp:177
Storage()
Definition: storage.cpp:17
eType type
Definition: storage.h:78
int _stackOffset
Definition: storage.h:80
bool isUndefined() const
Definition: storage.cpp:102
std::optional< unsigned > getRegisterNumber() const
Definition: storage.cpp:206
std::optional< unsigned > _registerNumber
Definition: storage.h:84
std::string getRegisterName() const
Definition: storage.cpp:186
bool isDefined() const
Definition: storage.cpp:97
static Storage inRegister(const std::string &registerName)
Definition: storage.cpp:61
static Storage onStack(int offset)
Definition: storage.cpp:28
static Storage undefined()
Definition: storage.cpp:23
int getStackOffset() const
Definition: storage.cpp:195
static const int UNDEF_REG_NUM
Definition: storage.h:75
std::string _registerName
Definition: storage.h:81
retdec::common::Address _globalAddress
Definition: storage.h:82
bool isRegister() const
Definition: storage.cpp:112
void setRegisterNumber(unsigned registerNumber)
Definition: storage.cpp:211
bool isMemory() const
Definition: storage.cpp:107
bool isStack() const
Definition: storage.cpp:117
eType
Definition: storage.h:25
Address, address pair and other derived class representation.
Definition: archive_wrapper.h:19