-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLengthInfo.cc
More file actions
89 lines (71 loc) · 2.12 KB
/
LengthInfo.cc
File metadata and controls
89 lines (71 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "LengthInfo.hh"
#include <cassert>
#include <llvm/IR/Argument.h>
#include <llvm/IR/InstrTypes.h>
#include <sstream>
using namespace std;
const LengthInfo LengthInfo::notFixedLength{NOT_FIXED_LENGTH};
const LengthInfo LengthInfo::inconsistent{INCONSISTENT};
const LengthInfo LengthInfo::sentinelTerminated{SENTINEL_TERMINATED, 0L};
LengthInfo LengthInfo::parameterLength(long slot) {
assert(slot >= 0);
return {PARAMETER_LENGTH, slot};
}
LengthInfo LengthInfo::parameterLength(const shared_ptr<const ValueSet> &symbolic) {
return {PARAMETER_LENGTH, symbolic};
}
LengthInfo LengthInfo::fixedLength(long length) {
assert(length >= 0);
if (length == 0) return notFixedLength;
return {FIXED_LENGTH, length};
}
string LengthInfo::getTypeString(const LengthType &type) {
switch (type) {
case NO_LENGTH_VALUE: return "None ";
case PARAMETER_LENGTH: return "Param";
case FIXED_LENGTH: return "Fixed";
case NOT_FIXED_LENGTH: return "Not Fixed";
case INCONSISTENT: return "Bad ";
case SENTINEL_TERMINATED: return "Sentinel";
}
return "Impossible";
}
int LengthInfo::getSymbolicLength() const {
if (length == -1) {
assert(symbolicLength);
if (symbolicLength->size() == 1) {
const llvm::Value *value = *symbolicLength->begin();
while (true) {
const llvm::CastInst *cast = llvm::dyn_cast<llvm::CastInst>(value);
if (cast == nullptr) break;
value = cast->getOperand(0);
}
const llvm::Argument *arg = llvm::dyn_cast<llvm::Argument>(value);
if (arg != nullptr) {
return arg->getArgNo();
}
}
return -1;
}
else {
return length;
}
}
string LengthInfo::toString() const {
stringstream stream;
switch(type) {
case NO_LENGTH_VALUE: return "No length value";
case PARAMETER_LENGTH:
stream << "Parameter length of " << (length == -1? getSymbolicLength() : length);
return stream.str();
case FIXED_LENGTH:
stream << "Fixed length of " << length;
return stream.str();
case NOT_FIXED_LENGTH: return "Not fixed length";
case INCONSISTENT: return "Inconsistent length";
case SENTINEL_TERMINATED:
stream << "Sentinel-terminated by " << length;
return stream.str();
}
return "Impossible";
}