forked from vgvassilev/creduce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransformationManager.h
147 lines (96 loc) · 3.3 KB
/
TransformationManager.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//===----------------------------------------------------------------------===//
//
// Copyright (c) 2012, 2013 The University of Utah
// All rights reserved.
//
// This file is distributed under the University of Illinois Open Source
// License. See the file COPYING for details.
//
//===----------------------------------------------------------------------===//
#ifndef TRANSFORMATION_MANAGER_H
#define TRANSFORMATION_MANAGER_H
#include <string>
#include <map>
#include <cassert>
#include "llvm/Support/raw_ostream.h"
class Transformation;
namespace clang {
class CompilerInstance;
}
class TransformationManager {
public:
static TransformationManager *GetInstance();
static void Finalize();
static void registerTransformation(const char *TransName,
Transformation *TransImpl);
static bool isCXXLangOpt();
static bool isCLangOpt();
static int ErrorInvalidCounter;
bool doTransformation(std::string &ErrorMsg, int &ErrorCode);
bool verify(std::string &ErrorMsg, int &ErrorCode);
int setTransformation(const std::string &Trans) {
if (TransformationsMap.find(Trans.c_str()) == TransformationsMap.end())
return -1;
CurrentTransName = Trans;
CurrentTransformationImpl = TransformationsMap[Trans.c_str()];
return 0;
}
void setTransformationCounter(int Counter) {
assert((Counter > 0) && "Bad Counter value!");
TransformationCounter = Counter;
}
void setToCounter(int Counter) {
assert((Counter > 0) && "Bad to-counter value!");
ToCounter = Counter;
}
void setSrcFileName(const std::string &FileName) {
assert(SrcFileName.empty() && "Could only process one file each time");
SrcFileName = FileName;
}
void setOutputFileName(const std::string &FileName) {
OutputFileName = FileName;
}
void setQueryInstanceFlag(bool Flag) {
QueryInstanceOnly = Flag;
}
bool getQueryInstanceFlag() {
return QueryInstanceOnly;
}
bool initializeCompilerInstance(std::string &ErrorMsg);
void outputNumTransformationInstances();
void printTransformations();
void printTransformationNames();
private:
TransformationManager();
~TransformationManager();
llvm::raw_ostream *getOutStream();
void closeOutStream(llvm::raw_ostream *OutStream);
static TransformationManager *Instance;
static std::map<std::string, Transformation *> *TransformationsMapPtr;
std::map<std::string, Transformation *> TransformationsMap;
Transformation *CurrentTransformationImpl;
int TransformationCounter;
int ToCounter;
std::string SrcFileName;
std::string OutputFileName;
std::string CurrentTransName;
clang::CompilerInstance *ClangInstance;
bool QueryInstanceOnly;
// Unimplemented
TransformationManager(const TransformationManager &);
void operator=(const TransformationManager&);
};
template<typename TransformationClass>
class RegisterTransformation {
public:
RegisterTransformation(const char *TransName, const char *Desc) {
Transformation *TransImpl = new TransformationClass(TransName, Desc);
assert(TransImpl && "Fail to create TransformationClass");
TransformationManager::registerTransformation(TransName, TransImpl);
}
private:
// Unimplemented
RegisterTransformation(const RegisterTransformation &);
void operator=(const RegisterTransformation &);
};
#endif