Skip to content

Commit 86d1c51

Browse files
committed
refactored some defines and remove some *_ONCE() to support multiple passes linked into a single .so
1 parent 697396a commit 86d1c51

File tree

5 files changed

+34
-54
lines changed

5 files changed

+34
-54
lines changed

cli.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ inline int OptParamParser::check(vector<OptParam> &list, string &err)
382382
return 0;
383383
}
384384

385-
int OptParamParser::registerParam(OptParam &src, OptParam **trg, bool isPass)
385+
inline int OptParamParser::registerParam(OptParam &src, OptParam **trg, bool isPass)
386386
{
387387
if (trg)
388388
*trg = NULL;
@@ -416,8 +416,5 @@ int OptParamParser::registerParam(OptParam &src, OptParam **trg, bool isPass)
416416
return 0;
417417
}
418418

419-
#define OPT_CLI_ONCE() \
420-
OptParamParser* OptParamParser::__OptParamParser = NULL; \
421-
std::vector<const PassTimer*> PassTimer::expiredTimers;
422419

423420
#endif

di-opt.cpp

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,22 @@
1010

1111
#include <sys/time.h>
1212

13-
OPT_CLI_ONCE();
14-
PASSICLI_ONCE();
13+
OptParamParser* OptParamParser::__OptParamParser = NULL;
14+
std::vector<const PassTimer*> PassTimer::expiredTimers;
15+
16+
TEMPLATE_INSTANTIATION(class cl::basic_parser<bool>);
17+
TEMPLATE_INSTANTIATION(class cl::basic_parser<int>);
18+
TEMPLATE_INSTANTIATION(class cl::basic_parser<unsigned>);
19+
TEMPLATE_INSTANTIATION(class cl::basic_parser<unsigned long long>);
20+
TEMPLATE_INSTANTIATION(class cl::basic_parser<double>);
21+
TEMPLATE_INSTANTIATION(class cl::basic_parser<float>);
22+
TEMPLATE_INSTANTIATION(class cl::basic_parser<std::string>);
23+
TEMPLATE_INSTANTIATION(class cl::basic_parser<char>);
24+
25+
bool di_debug;
26+
std::string di_debug_pass;
27+
28+
BPatch bpatch;
1529

1630
void EXIT(int status)
1731
{
@@ -25,21 +39,6 @@ void exit_usage(string err, OptParamParser *parser)
2539
EXIT(1);
2640
}
2741

28-
/* Standard command-line options. */
29-
#define STD_CL_OPTS() \
30-
STD_GEN_CL_OPTS(); \
31-
cl::opt<bool> \
32-
detach("detach", \
33-
cl::desc("Detach immediately."), \
34-
cl::init(true)); \
35-
cl::opt<bool> \
36-
quit("quit", \
37-
cl::desc("Quit immediately."), \
38-
cl::init(false)); \
39-
cl::opt<bool> \
40-
forceRewriting("force-rewriting", \
41-
cl::desc("Force rewriting even when not necessary."), \
42-
cl::init(false))
4342

4443
int main(int argc, char **argv)
4544
{
@@ -55,7 +54,13 @@ int main(int argc, char **argv)
5554
ret = parser->parse(err);
5655
if (ret < 0)
5756
exit_usage(err, parser);
58-
STD_CL_OPTS();
57+
58+
cl::opt<bool> __PASS_DEBUG("debug", cl::desc("Enables debugging for all the passes."), cl::init(false));
59+
cl::opt<std::string> __PASS_DEBUG_PASS("debug-pass", cl::desc("Enables debugging for a specific pass."), cl::init(""));
60+
cl::opt<bool> __CL_TIME_PASSES("time-passes", cl::desc("Time each pass and print elapsed time."), cl::init(false));
61+
cl::opt<bool> detach("detach", cl::desc("Detach immediately."), cl::init(true));
62+
cl::opt<bool> quit("quit", cl::desc("Quit immediately."), cl::init(false));
63+
cl::opt<bool> forceRewriting("force-rewriting", cl::desc("Force rewriting even when not necessary."), cl::init(false));
5964

6065
TimeRegion *dyninstMainTR = new TimeRegion(PassTimer::getPassTimer("di-opt.main", __CL_TIME_PASSES));
6166
TimeRegion *untilDetachTR = new TimeRegion(PassTimer::getPassTimer("di-opt.detached", __CL_TIME_PASSES));
@@ -69,6 +74,9 @@ int main(int argc, char **argv)
6974
if (ret < 0)
7075
exit_usage(err, parser);
7176

77+
di_debug = __PASS_DEBUG.getValue();
78+
di_debug_pass = __PASS_DEBUG_PASS.getValue();
79+
7280
vector<OptParam> passes = parser->getPasses();
7381
for (unsigned i=0;i<passes.size();i++) {
7482
ModulePass *pass = dynamic_cast<ModulePass*>(passes[i].owner);

pass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
using namespace Dyninst;
1515

16-
BPatch bpatch;
16+
extern BPatch bpatch;
1717

1818
#endif /* _DI_PASS_H */
1919

passcli.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ initializer<Ty> init(const Ty &Val) {
243243
return initializer<Ty>(Val);
244244
}
245245

246-
initializer<string> init(const char *cptr) {
246+
inline initializer<string> init(const char *cptr) {
247247
std::stringstream ss;
248248
ss << cptr;
249249
return initializer<string>(ss.str());
@@ -295,15 +295,6 @@ struct opt : public Option {
295295

296296
}
297297

298-
#define PASSICLI_ONCE() \
299-
TEMPLATE_INSTANTIATION(class cl::basic_parser<bool>); \
300-
TEMPLATE_INSTANTIATION(class cl::basic_parser<int>); \
301-
TEMPLATE_INSTANTIATION(class cl::basic_parser<unsigned>); \
302-
TEMPLATE_INSTANTIATION(class cl::basic_parser<unsigned long long>); \
303-
TEMPLATE_INSTANTIATION(class cl::basic_parser<double>); \
304-
TEMPLATE_INSTANTIATION(class cl::basic_parser<float>); \
305-
TEMPLATE_INSTANTIATION(class cl::basic_parser<std::string>); \
306-
TEMPLATE_INSTANTIATION(class cl::basic_parser<char>);
307298

308299
#endif
309300

passi.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -174,27 +174,11 @@ class TimeRegion {
174174
}
175175
};
176176

177-
extern cl::opt<bool> __PASS_DEBUG;
178-
extern cl::opt<std::string> __PASS_DEBUG_PASS;
179-
180-
#define DEBUG(X) if (__PASS_DEBUG || !__PASS_DEBUG_PASS.getValue().compare(this->name)) { X; }
181-
182-
#define PASS_ONCE() \
183-
PASSICLI_ONCE(); \
184-
cl::opt<bool> \
185-
__PASS_DEBUG("debug", \
186-
cl::desc("Enables debugging for all the passes."), \
187-
cl::init(false)); \
188-
cl::opt<std::string> \
189-
__PASS_DEBUG_PASS("debug-pass", \
190-
cl::desc("Enables debugging for a specific pass."), \
191-
cl::init(""))
192-
193-
#define STD_GEN_CL_OPTS() \
194-
cl::opt<bool> \
195-
__CL_TIME_PASSES("time-passes", \
196-
cl::desc("Time each pass and print elapsed time."), \
197-
cl::init(false)); \
177+
extern bool di_debug;
178+
extern std::string di_debug_pass;
179+
180+
#define DEBUG(X) if (di_debug || di_debug_pass == this->name) { X; }
181+
198182

199183
#endif
200184

0 commit comments

Comments
 (0)