-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpz_option.h
148 lines (130 loc) · 2.83 KB
/
pz_option.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
148
/*
* Plasma runtime options
* vim: ts=4 sw=4 et
*
* Copyright (C) Plasma Team
* Distributed under the terms of the MIT license, see ../LICENSE.code
*/
#ifndef PZ_OPTIONS_H
#define PZ_OPTIONS_H
#include <string>
#include <vector>
namespace pz {
/*
* Runtime options
*
* Options are specified by environment variable, see README.md in this
* directory for the list of configurable options.
*
* Not all options may be specified, some are compiled in as can be seen in
* their accessor functions below.
*
* TODO: probably integrate options that can change at runtime with this
* class, such as the GC size.
*/
class Options
{
public:
enum Mode {
NORMAL,
HELP,
VERSION,
ERROR,
};
private:
std::string m_pzfile;
std::vector<std::string> m_pzlibs;
bool m_verbose;
bool m_fast_exit;
#ifdef PZ_DEV
bool m_interp_trace;
bool m_gc_zealous;
bool m_gc_usage_stats;
bool m_gc_trace;
#endif
// Non-null if parse returns Mode::ERROR
const char * m_error_message;
Mode parseCommandLine(int artc, char * const argv[]);
void parseEnvironment();
public:
Options()
: m_verbose(false)
#ifndef PZ_DEV
, m_fast_exit(true)
#else
, m_fast_exit(false)
, m_interp_trace(false)
, m_gc_zealous(false)
, m_gc_usage_stats(false)
, m_gc_trace(false)
#endif
{}
Mode parse(int artc, char * const argv[]);
/*
* Non-null if parse made an error message available. Even if an error
* occurs, sometimes getopt will print the error message and this will
* be null.
*/
const char * error_message() const
{
return m_error_message;
}
bool verbose() const
{
return m_verbose;
}
std::string pzfile() const
{
return m_pzfile;
}
const std::vector<std::string> & pzlibs() const
{
return m_pzlibs;
}
bool fast_exit() const
{
return m_fast_exit;
}
#ifdef PZ_DEV
bool interp_trace() const
{
return m_interp_trace;
}
bool gc_zealous() const
{
return m_gc_zealous;
}
bool gc_usage_stats() const
{
return m_gc_usage_stats;
}
// In the future make these false by default and allow them to be
// changed at runtime.
bool gc_slow_asserts() const
{
return true;
}
bool gc_poison() const
{
return true;
}
// Change temporarily to enable tracing.
bool gc_trace() const
{
return m_gc_trace;
}
bool gc_trace2() const
{
return false;
}
#else
bool interp_trace() const
{
return false;
}
#endif
Options(const Options &) = delete;
void operator=(const Options &) = delete;
};
} // namespace pz
#endif