Static Value-Flow Analysis
Loading...
Searching...
No Matches
ObjTypeInfo.h
Go to the documentation of this file.
1//===- ObjTypeInfo.h -- Object type information------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <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 * ObjTypeInfo.h
25 *
26 * Created on: Nov 11, 2013
27 * Author: Yulei Sui
28 */
29
30#ifndef INCLUDE_PAG_OBJTYPEINFO_H_
31#define INCLUDE_PAG_OBJTYPEINFO_H_
32
33#include "Util/GeneralType.h"
34
35namespace SVF
36{
37
38class SVFType;
39
44{
45 friend class SymbolTableBuilder;
46 friend class GraphDBClient;
47
48public:
49 typedef enum
50 {
51 FUNCTION_OBJ = 0x1, // object is a function
52 GLOBVAR_OBJ = 0x2, // object is a global variable
53 STATIC_OBJ = 0x4, // object is a static variable allocated before main
54 STACK_OBJ = 0x8, // object is a stack variable
55 HEAP_OBJ = 0x10, // object is a heap variable
56 VAR_STRUCT_OBJ = 0x20, // object contains struct
57 VAR_ARRAY_OBJ = 0x40, // object contains array
58 CONST_STRUCT_OBJ = 0x80, // constant struct
59 CONST_ARRAY_OBJ = 0x100, // constant array
60 CONST_GLOBAL_OBJ = 0x200, // global constant object
61 CONST_DATA = 0x400, // constant object str e.g. 5, 10, 1.0
62 } MEMTYPE;
63
64private:
66 const SVFType* type;
75
78
79 inline void resetTypeForHeapStaticObj(const SVFType* t)
80 {
81 assert((isStaticObj() || isHeap()) && "can only reset the inferred type for heap and static objects!");
82 type = t;
83 }
84public:
85
87 ObjTypeInfo(const SVFType* t, u32_t max)
88 : type(t), flags(0), maxOffsetLimit(max), elemNum(max), byteSize(0)
89 {
90 assert(t && "no type information for this object?");
91 }
92
94 virtual ~ObjTypeInfo()
95 {
96 }
97
99 inline const SVFType* getType() const
100 {
101 return type;
102 }
103
106 {
107 return maxOffsetLimit;
108 }
109
111 inline void setMaxFieldOffsetLimit(u32_t limit)
112 {
113 maxOffsetLimit = limit;
114 }
115
117 inline void setNumOfElements(u32_t num)
118 {
119 elemNum = num;
121 }
122
124 inline u32_t getNumOfElements() const
125 {
126 return elemNum;
127 }
128
130 inline u32_t getByteSizeOfObj() const
131 {
132 assert(isConstantByteSize() && "This Obj's byte size is not constant.");
133 return byteSize;
134 }
135
137 inline void setByteSizeOfObj(u32_t size)
138 {
139 byteSize = size;
140 }
141
143 inline bool isConstantByteSize() const
144 {
145 return byteSize != 0;
146 }
147
149
150 inline void setFlag(MEMTYPE mask)
151 {
152 flags |= mask;
153 }
154 inline u32_t getFlag() const
155 {
156 return flags;
157 }
158 inline bool hasFlag(MEMTYPE mask)
159 {
160 return (flags & mask) == mask;
161 }
162
163
165
166 inline bool isFunction()
167 {
168 return hasFlag(FUNCTION_OBJ);
169 }
170 inline bool isGlobalObj()
171 {
172 return hasFlag(GLOBVAR_OBJ);
173 }
174 inline bool isStaticObj()
175 {
176 return hasFlag(STATIC_OBJ);
177 }
178 inline bool isStack()
179 {
180 return hasFlag(STACK_OBJ);
181 }
182 inline bool isHeap()
183 {
184 return hasFlag(HEAP_OBJ);
185 }
186
187
190
191 inline bool isVarStruct()
192 {
193 return hasFlag(VAR_STRUCT_OBJ);
194 }
195 inline bool isConstantStruct()
196 {
198 }
199 inline bool isStruct()
200 {
202 }
203 inline bool isVarArray()
204 {
205 return hasFlag(VAR_ARRAY_OBJ);
206 }
207 inline bool isConstantArray()
208 {
209 return hasFlag(CONST_ARRAY_OBJ);
210 }
211 inline bool isArray()
212 {
214 }
216 {
218 }
220 {
221 return hasFlag(CONST_DATA);
222 }
223
224};
225
226
227} // End namespace SVF
228
229#endif /* INCLUDE_PAG_OBJTYPEINFO_H_ */
const SVFType * type
SVF type.
Definition ObjTypeInfo.h:66
bool isConstantStruct()
u32_t elemNum
Size of the object or number of elements.
Definition ObjTypeInfo.h:74
void resetTypeForHeapStaticObj(const SVFType *t)
Definition ObjTypeInfo.h:79
bool isConstDataOrAggData()
u32_t getMaxFieldOffsetLimit()
Get max field offset limit.
u32_t getFlag() const
bool hasFlag(MEMTYPE mask)
bool isConstDataOrConstGlobal()
u32_t getNumOfElements() const
Get the number of elements of this object.
const SVFType * getType() const
Get LLVM type.
Definition ObjTypeInfo.h:99
bool isConstantByteSize() const
Check if byte size is a const value.
friend class SymbolTableBuilder
Definition ObjTypeInfo.h:45
void setMaxFieldOffsetLimit(u32_t limit)
Get max field offset limit.
friend class GraphDBClient
Definition ObjTypeInfo.h:46
u32_t byteSize
Byte size of object.
Definition ObjTypeInfo.h:77
u32_t flags
Type flags.
Definition ObjTypeInfo.h:68
void setByteSizeOfObj(u32_t size)
Set the byte size of this object.
bool isFunction()
Object attributes.
ObjTypeInfo(const SVFType *t, u32_t max)
Constructors.
Definition ObjTypeInfo.h:87
virtual ~ObjTypeInfo()
Destructor.
Definition ObjTypeInfo.h:94
u32_t getByteSizeOfObj() const
Get the byte size of this object.
void setFlag(MEMTYPE mask)
Flag for this object type.
void setNumOfElements(u32_t num)
Set the number of elements of this object.
for isBitcode
Definition BasicTypes.h:70
unsigned u32_t
Definition GeneralType.h:67