-
Notifications
You must be signed in to change notification settings - Fork 14
/
utils.h
126 lines (97 loc) · 3.07 KB
/
utils.h
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* Nadav Rotem - C-to-Verilog.com */
#ifndef LLVM_SCHED_UTILS_H
#define LLVM_SCHED_UTILS_H
#include "llvm/Support/Mangler.h"
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <set>
using namespace llvm;
using std::set;
using std::vector;
using std::pair;
using std::string;
using std::stringstream;
namespace {
/*
* Set the terminal to color mode. Each line from this point will
* be printed in color (white over blue).
*/
std::string xBlue() {
return "\033[44;37;5m";
}
/*
* Set the terminal to color mode. Each line from this point will
* be printed in color (white over blue).
*/
std::string xRed() {
return "\033[22;31;5m";
}
/*
* Reset the terminal to it's regular color mode
*/
std::string xReset() {
return "\033[0m";
}
void logPassMessage(std::string passName,int line ,std::string message, bool good=true) {
if (good) {
cerr<<xBlue();
} else {
cerr<<xRed();
}
cerr<<"OPT:"<<passName<<","<<line<<":"<<xReset()<<message<<std::endl;
}
string toPrintable(const string& in ){
string VarName;
VarName.reserve(in.capacity());
for (std::string::const_iterator I = in.begin(), E = in.end();
I != E; ++I) {
char ch = *I;
if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9') || ch == '_'))
VarName += '_';
else
VarName += ch;
}
return VarName;
}
string valueToString(Mangler* mang ,const Value *Operand) {
std::string Name;
const ConstantInt* CI = dyn_cast<ConstantInt>(Operand);
if (CI && !isa<GlobalValue>(CI)) {
stringstream ss;
const Type* Ty = CI->getType();
if (Ty == Type::Int1Ty)
ss<<((CI->getZExtValue() ? "1" : "0"));
else {
ss << "(";
if (CI->isMinValue(true)) ss <<"-"<< CI->getZExtValue() <<"";
else ss << CI->getSExtValue();
ss << ")";
}
return ss.str();
}
if (!isa<GlobalValue>(Operand) && Operand->getName() != "") {
std::string VarName;
Name = Operand->getName();
VarName = toPrintable(Name);
const Type* tp = Operand->getType();
if (tp->isInteger()) {
Name = "i_" + VarName;
} else if(tp->isSized()) {
Name = "p_" + VarName;
} else {
Name = "o_" + VarName;
}
return Name;//JAWAD
}
if(isa<ConstantPointerNull> (Operand)){ //JAWAD
return "(0) /* NULL */";
}
//TODO: pass mang to this method ...
Name = mang->getValueName(Operand);
return Name;
}
} //end of namespace
#endif // h guard