-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramOptions.cpp
More file actions
175 lines (156 loc) · 4.46 KB
/
ProgramOptions.cpp
File metadata and controls
175 lines (156 loc) · 4.46 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
* @file ProgramOptions.cpp
* @brief Implementation of ProgramOptions functions.
* @author Ankit Srivastava <asrivast@gatech.edu>
*
* Copyright 2018 Georgia Institute of Technology
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ProgramOptions.hpp"
#include <iostream>
#include <numeric>
#include <boost/filesystem.hpp>
ProgramOptions::ProgramOptions(
) : m_options("Determines which of the given intervals were stabbed by the given points"),
m_deviceName(),
m_macrosDir(),
m_fsmName(),
m_intervalsFile(),
m_pointsFile(),
m_numBytes(),
m_randomSeed(),
m_numIntervals(),
m_numPoints(),
m_isReal(),
m_isSigned()
{
m_options.add_options()
("help,h", "Print this message.")
("device,d", po::value<std::string>(&m_deviceName), "Name of the AP device to be used for stabbing intervals.")
("macros,m", po::value<std::string>(&m_macrosDir)->default_value("./comparators"), "Directory which contains all the comparator macros.")
("fsm,f", po::value<std::string>(&m_fsmName), "Name of the FSM file to be written.")
("intervals,i", po::value<std::string>(&m_intervalsFile), "Name of the file from which intervals are to be read.")
("points,p", po::value<std::string>(&m_pointsFile), "Name of the file from which points are to be read.")
("bytes,b", po::value<size_t>(&m_numBytes)->default_value(4), "Number of bytes.")
("seed,s", po::value<size_t>(&m_randomSeed)->default_value(0), "Seed for random number generator.")
("random-intervals,I", po::value<size_t>(&m_numIntervals)->default_value(0), "Number of random intervals to be programmed.")
("random-points,P", po::value<size_t>(&m_numPoints)->default_value(0), "Number of random points to be used for stabbing.")
("chunks,c", po::value<size_t>(&m_maxChunkSize)->default_value(std::numeric_limits<size_t>::max()), "Maximum chunk size for flows to the AP.")
("real", po::bool_switch(&m_isReal)->default_value(false), "Use real numbers for labeling.")
("signed", po::bool_switch(&m_isSigned)->default_value(false), "Use signed numbers for labeling.")
;
}
void
ProgramOptions::parse(
int argc,
char** argv
)
{
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, m_options), vm);
po::notify(vm);
if ((argc == 1) || (vm.count("help") > 0)) {
std::stringstream ss;
ss << m_options;
throw po::error(ss.str());
}
if (!m_intervalsFile.empty() && !boost::filesystem::exists(boost::filesystem::path(m_intervalsFile))) {
throw po::error("Couldn't find the intervals file.");
}
if (!m_pointsFile.empty() && !boost::filesystem::exists(boost::filesystem::path(m_pointsFile))) {
throw po::error("Couldn't find the points file.");
}
if ((!m_intervalsFile.empty()) && (m_numIntervals > 0)) {
std::cerr << "WARNING: \"intervals\" and \"random-intervals\" argument provided together. \"random-intervals\" will be ignored." << std::endl;
}
if ((!m_pointsFile.empty()) && (m_numPoints > 0)) {
std::cerr << "WARNING: \"points\" and \"random-points\" argument provided together. \"random-points\" will be ignored." << std::endl;
}
}
std::string
ProgramOptions::deviceName(
) const
{
return m_deviceName;
}
std::string
ProgramOptions::macrosDir(
) const
{
return m_macrosDir;
}
std::string
ProgramOptions::fsmName(
) const
{
return m_fsmName;
}
std::string
ProgramOptions::intervalsFile(
) const
{
return m_intervalsFile;
}
std::string
ProgramOptions::pointsFile(
) const
{
return m_pointsFile;
}
size_t
ProgramOptions::numBytes(
) const
{
return m_numBytes;
}
size_t
ProgramOptions::randomSeed(
) const
{
return m_randomSeed;
}
size_t
ProgramOptions::numIntervals(
) const
{
return m_numIntervals;
}
size_t
ProgramOptions::numPoints(
) const
{
return m_numPoints;
}
size_t
ProgramOptions::maxChunkSize(
) const
{
return m_maxChunkSize;
}
bool
ProgramOptions::isReal(
) const
{
return m_isReal;
}
bool
ProgramOptions::isSigned(
) const
{
return m_isSigned;
}
ProgramOptions::~ProgramOptions(
)
{
}