Skip to content

Commit b58ffb4

Browse files
committed
Merge branch 'optional-warning-file' into master+wip
2 parents 681a2b0 + ea325b8 commit b58ffb4

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

libs/libvtrutil/src/vtr_log.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ void add_warnings_to_suppress(std::string function_name) {
2323
warnings_to_suppress.insert(function_name);
2424
}
2525

26-
void set_noisy_warn_log_file(const char* log_file_name) {
26+
void set_noisy_warn_log_file(std::string log_file_name) {
2727
std::ofstream log;
2828
log.open(log_file_name, std::ifstream::out | std::ifstream::trunc);
2929
log.close();
30-
noisy_warn_log_file = std::string(log_file_name);
30+
noisy_warn_log_file = log_file_name;
3131
}
3232

3333
void print_or_suppress_warning(const char* pszFileName, unsigned int lineNum, const char* pszFuncName, const char* pszMessage, ...) {
@@ -41,7 +41,7 @@ void print_or_suppress_warning(const char* pszFileName, unsigned int lineNum, co
4141
auto result = warnings_to_suppress.find(function_name);
4242
if (result == warnings_to_suppress.end()) {
4343
vtr::printf_warning(pszFileName, lineNum, msg.data());
44-
} else {
44+
} else if (!noisy_warn_log_file.empty()) {
4545
std::ofstream log;
4646
log.open(noisy_warn_log_file.data(), std::ios_base::app);
4747
log << "Warning:\n\tfile: " << pszFileName << "\n\tline: " << lineNum << "\n\tmessage: " << msg << std::endl;

libs/libvtrutil/src/vtr_log.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ void set_log_file(const char* filename);
141141
} // namespace vtr
142142

143143
// The following data structure and functions allow to suppress noisy warnings
144-
// and direct them into an external file.
144+
// and direct them into an external file, if specified.
145145
static std::unordered_set<std::string> warnings_to_suppress;
146146
static std::string noisy_warn_log_file;
147147

148148
void add_warnings_to_suppress(std::string function_name);
149149

150150
// This function creates a new log file to hold the suppressed warnings.
151151
// If the file already exists, it is cleared out first.
152-
void set_noisy_warn_log_file(const char* log_file_name);
152+
void set_noisy_warn_log_file(std::string log_file_name);
153153

154154
// This function checks whether the function from which the warning has been called
155155
// is in the set of warnings_to_suppress. If so, the warning is printed on the

vpr/src/base/read_options.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,9 @@ static argparse::ArgumentParser create_arg_parser(std::string prog_name, t_optio
949949
.help(
950950
"Parses a list of functions for which the warnings will be suppressed on stdout.\n"
951951
"The first element of the list is the name of the output log file with the suppressed warnings.\n"
952-
"The file name and the list of functions is separated by `,`\n"
952+
"The output log file can be omitted to completely suppress warnings.\n"
953+
"The file name and the list of functions is separated by `,`. If no output log file is specified,\n"
954+
"the comma is not needed.\n"
953955
"Each function in the list is delimited by `:`\n"
954956
"This option should be only used for development purposes.")
955957
.default_value("");

vpr/src/base/vpr_api.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,20 @@ void vpr_init(const int argc, const char** argv, t_options* options, t_vpr_setup
227227
* warnings are being suppressed
228228
*/
229229
std::vector<std::string> split_warning_option = vtr::split(options->suppress_warnings, std::string(","));
230+
std::string warn_log_file;
231+
std::string warn_functions;
232+
// If no log file name is provided, the specified warning
233+
// to suppress are not output anywhere.
234+
if (split_warning_option.size() == 1) {
235+
warn_functions = split_warning_option[0];
236+
} else if (split_warning_option.size() == 2) {
237+
warn_log_file = split_warning_option[0];
238+
warn_functions = split_warning_option[1];
239+
}
230240

231-
// If the file or the list of functions is not provided
232-
// no warning is suppressed
233-
if (split_warning_option.size() == 2) {
234-
set_noisy_warn_log_file(split_warning_option[0].data());
235-
for (std::string func_name : vtr::split(split_warning_option[1], std::string(":"))) {
236-
add_warnings_to_suppress(func_name);
237-
}
241+
set_noisy_warn_log_file(warn_log_file);
242+
for (std::string func_name : vtr::split(warn_functions, std::string(":"))) {
243+
add_warnings_to_suppress(func_name);
238244
}
239245

240246
/* Read in arch and circuit */

0 commit comments

Comments
 (0)