Static Value-Flow Analysis
SVFModule.h
Go to the documentation of this file.
1 //===- SVFModule.h -- SVFModule* class----------------------------------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-2017> <Yulei Sui>
6 //
7 
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
17 
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 /*
24  * SVFModule.h
25  *
26  * Created on: Aug 4, 2017
27  * Author: Xiaokang Fan
28  */
29 
30 #ifndef INCLUDE_SVFMODULE_H_
31 #define INCLUDE_SVFMODULE_H_
32 
33 #include "SVFIR/SVFValue.h"
34 #include "Util/NodeIDAllocator.h"
35 #include "Util/ThreadAPI.h"
36 
37 namespace SVF
38 {
39 
40 class SVFModule
41 {
42  friend class SVFIRWriter;
43  friend class SVFIRReader;
44 
45 public:
46  typedef std::vector<const SVFFunction*> FunctionSetType;
47  typedef std::vector<SVFGlobalValue*> GlobalSetType;
48  typedef std::vector<SVFGlobalValue*> AliasSetType;
49  typedef std::vector<SVFConstant*> ConstantType;
50  typedef std::vector<SVFOtherValue*> OtherValueType;
51 
53  typedef FunctionSetType::iterator iterator;
54  typedef FunctionSetType::const_iterator const_iterator;
55  typedef GlobalSetType::iterator global_iterator;
56  typedef GlobalSetType::const_iterator const_global_iterator;
57  typedef AliasSetType::iterator alias_iterator;
58  typedef AliasSetType::const_iterator const_alias_iterator;
59  typedef ConstantType::iterator cdata_iterator;
60  typedef ConstantType::const_iterator const_cdata_iterator;
61  typedef OtherValueType::iterator ovalue_iterator;
62  typedef OtherValueType::const_iterator const_ovalue_iterator;
63 
64 private:
73 
75  SVFModule() = default;
76 
77 public:
78  static SVFModule* getSVFModule();
79  static void releaseSVFModule();
80 
81  ~SVFModule();
82 
83  static inline void setPagFromTXT(const std::string& txt)
84  {
85  pagReadFromTxt = txt;
86  }
87 
89  {
90  this->moduleIdentifier = moduleIdentifier;
91  }
92 
93  static inline std::string pagFileName()
94  {
95  return pagReadFromTxt;
96  }
97 
98  static inline bool pagReadFromTXT()
99  {
100  return !pagReadFromTxt.empty();
101  }
102 
104 
106  inline void addFunctionSet(SVFFunction* svfFunc)
107  {
108  FunctionSet.push_back(svfFunc);
109  }
110  inline void addGlobalSet(SVFGlobalValue* glob)
111  {
112  GlobalSet.push_back(glob);
113  addConstant(glob);
114  }
115  inline void addAliasSet(SVFGlobalValue* alias)
116  {
117  AliasSet.push_back(alias);
118  addConstant(alias);
119  }
120  inline void addConstant(SVFConstant* cd)
121  {
122  ConstantSet.push_back(cd);
123  }
124  inline void addOtherValue(SVFOtherValue* ov)
125  {
126  OtherValueSet.push_back(ov);
127  }
128 
130 
134  {
135  return GlobalSet.begin();
136  }
138  {
139  return GlobalSet.begin();
140  }
142  {
143  return GlobalSet.end();
144  }
146  {
147  return GlobalSet.end();
148  }
149 
151  {
152  return AliasSet.begin();
153  }
155  {
156  return AliasSet.begin();
157  }
159  {
160  return AliasSet.end();
161  }
163  {
164  return AliasSet.end();
165  }
166 
168  {
169  return ConstantSet.begin();
170  }
172  {
173  return ConstantSet.begin();
174  }
176  {
177  return ConstantSet.end();
178  }
180  {
181  return ConstantSet.end();
182  }
184 
186  {
187  if (pagReadFromTxt.empty())
188  {
189  assert(!moduleIdentifier.empty() &&
190  "No module found! Reading from a file other than LLVM-IR?");
191  return moduleIdentifier;
192  }
193  else
194  {
195  return pagReadFromTxt;
196  }
197  }
198 
199  inline const FunctionSetType& getFunctionSet() const
200  {
201  return FunctionSet;
202  }
203  inline const ConstantType& getConstantSet() const
204  {
205  return ConstantSet;
206  }
207  inline const GlobalSetType& getGlobalSet() const
208  {
209  return GlobalSet;
210  }
211  inline const AliasSetType& getAliasSet() const
212  {
213  return AliasSet;
214  }
215  inline const OtherValueType& getOtherValueSet() const
216  {
217  return OtherValueSet;
218  }
219 };
220 
221 } // End namespace SVF
222 
223 #endif /* INCLUDE_SVFMODULE_H_ */
const char *const name
Definition: cJSON.h:264
const char *const string
Definition: cJSON.h:172
SVFModule()=default
Constructors.
void addGlobalSet(SVFGlobalValue *glob)
Definition: SVFModule.h:110
const_alias_iterator alias_begin() const
Definition: SVFModule.h:154
static bool pagReadFromTXT()
Definition: SVFModule.h:98
const_alias_iterator alias_end() const
Definition: SVFModule.h:162
const_cdata_iterator constant_begin() const
Definition: SVFModule.h:171
static std::string pagReadFromTxt
Definition: SVFModule.h:66
std::vector< SVFOtherValue * > OtherValueType
Definition: SVFModule.h:50
OtherValueType::const_iterator const_ovalue_iterator
Definition: SVFModule.h:62
alias_iterator alias_end()
Definition: SVFModule.h:158
void addOtherValue(SVFOtherValue *ov)
Definition: SVFModule.h:124
GlobalSetType::iterator global_iterator
Definition: SVFModule.h:55
global_iterator global_begin()
Definition: SVFModule.h:133
GlobalSetType GlobalSet
The Global Variables in the module.
Definition: SVFModule.h:69
static void releaseSVFModule()
Definition: SVFModule.cpp:69
static std::string pagFileName()
Definition: SVFModule.h:93
GlobalSetType::const_iterator const_global_iterator
Definition: SVFModule.h:56
AliasSetType::const_iterator const_alias_iterator
Definition: SVFModule.h:58
AliasSetType AliasSet
The Aliases in the module.
Definition: SVFModule.h:70
ConstantType ConstantSet
The ConstantData in the module.
Definition: SVFModule.h:71
FunctionSetType::iterator iterator
Iterators type def.
Definition: SVFModule.h:53
static void setPagFromTXT(const std::string &txt)
Definition: SVFModule.h:83
OtherValueType::iterator ovalue_iterator
Definition: SVFModule.h:61
const GlobalSetType & getGlobalSet() const
Definition: SVFModule.h:207
alias_iterator alias_begin()
Definition: SVFModule.h:150
void addFunctionSet(SVFFunction *svfFunc)
Definition: SVFModule.h:106
global_iterator global_end()
Definition: SVFModule.h:141
std::vector< SVFConstant * > ConstantType
Definition: SVFModule.h:49
OtherValueType OtherValueSet
All other values in the module.
Definition: SVFModule.h:72
std::vector< SVFGlobalValue * > AliasSetType
Definition: SVFModule.h:48
const ConstantType & getConstantSet() const
Definition: SVFModule.h:203
void addAliasSet(SVFGlobalValue *alias)
Definition: SVFModule.h:115
const std::string & getModuleIdentifier() const
Definition: SVFModule.h:185
std::vector< SVFGlobalValue * > GlobalSetType
Definition: SVFModule.h:47
ConstantType::const_iterator const_cdata_iterator
Definition: SVFModule.h:60
static SVFModule * getSVFModule()
Definition: SVFModule.cpp:60
const FunctionSetType & getFunctionSet() const
Definition: SVFModule.h:199
const_cdata_iterator constant_end() const
Definition: SVFModule.h:179
AliasSetType::iterator alias_iterator
Definition: SVFModule.h:57
cdata_iterator constant_begin()
Definition: SVFModule.h:167
std::string moduleIdentifier
Definition: SVFModule.h:67
void setModuleIdentifier(const std::string &moduleIdentifier)
Definition: SVFModule.h:88
const AliasSetType & getAliasSet() const
Definition: SVFModule.h:211
ConstantType::iterator cdata_iterator
Definition: SVFModule.h:59
std::vector< const SVFFunction * > FunctionSetType
Definition: SVFModule.h:46
cdata_iterator constant_end()
Definition: SVFModule.h:175
static SVFModule * svfModule
Definition: SVFModule.h:65
void addConstant(SVFConstant *cd)
Definition: SVFModule.h:120
const OtherValueType & getOtherValueSet() const
Definition: SVFModule.h:215
FunctionSetType FunctionSet
The Functions in the module.
Definition: SVFModule.h:68
const_global_iterator global_begin() const
Definition: SVFModule.h:137
const_global_iterator global_end() const
Definition: SVFModule.h:145
FunctionSetType::const_iterator const_iterator
Definition: SVFModule.h:54
const SVFFunction * getSVFFunction(const std::string &name)
Definition: SVFModule.cpp:48
for isBitcode
Definition: BasicTypes.h:68