mirror of https://github.com/YosysHQ/yosys.git
log_help: Include source_location
Use `std::experimental::source_location` because clang support is `??` Add `ENABLE_SOURCE_LOCATION` make variable and corresponding `YOSYS_ENABLE_SOURCE_LOCATION` define. Dummy out the struct if disabled and check for null instead of using `#ifdef` blocks everywhere.
This commit is contained in:
parent
724d71e4a4
commit
36e5d4c3d5
3
Makefile
3
Makefile
|
@ -511,6 +511,9 @@ LIBS_VERIFIC += -Wl,--whole-archive $(patsubst %,$(VERIFIC_DIR)/%/*-linux.a,$(VE
|
|||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(ENABLE_SOURCE_LOCATION),1)
|
||||
CXXFLAGS += -DYOSYS_ENABLE_SOURCE_LOCATION
|
||||
endif
|
||||
|
||||
ifeq ($(ENABLE_COVER),1)
|
||||
CXXFLAGS += -DYOSYS_ENABLE_COVER
|
||||
|
|
|
@ -78,13 +78,15 @@ bool PrettyHelp::has_content()
|
|||
return false;
|
||||
}
|
||||
|
||||
void PrettyHelp::usage(const string &usage)
|
||||
void PrettyHelp::usage(const string &usage,
|
||||
const source_location location)
|
||||
{
|
||||
log_pass_str(usage, current_indent+1, true);
|
||||
log("\n");
|
||||
}
|
||||
|
||||
void PrettyHelp::option(const string &text, const string &description)
|
||||
void PrettyHelp::option(const string &text, const string &description,
|
||||
const source_location location)
|
||||
{
|
||||
open_option(text);
|
||||
if (description.length()) {
|
||||
|
@ -94,23 +96,27 @@ void PrettyHelp::option(const string &text, const string &description)
|
|||
close(1);
|
||||
}
|
||||
|
||||
void PrettyHelp::codeblock(const string &code, const string &)
|
||||
void PrettyHelp::codeblock(const string &code, const string &,
|
||||
const source_location location)
|
||||
{
|
||||
log("%s\n", code.c_str());
|
||||
}
|
||||
|
||||
void PrettyHelp::paragraph(const string &text)
|
||||
void PrettyHelp::paragraph(const string &text,
|
||||
const source_location location)
|
||||
{
|
||||
log_pass_str(text, current_indent);
|
||||
log("\n");
|
||||
}
|
||||
|
||||
void PrettyHelp::open_optiongroup(const string &)
|
||||
void PrettyHelp::open_optiongroup(const string &,
|
||||
const source_location location)
|
||||
{
|
||||
current_indent += 1;
|
||||
}
|
||||
|
||||
void PrettyHelp::open_option(const string &text)
|
||||
void PrettyHelp::open_option(const string &text,
|
||||
const source_location location)
|
||||
{
|
||||
log_pass_str(text, current_indent);
|
||||
current_indent += 1;
|
||||
|
|
|
@ -23,6 +23,19 @@
|
|||
#include "kernel/yosys_common.h"
|
||||
#include "kernel/json.h"
|
||||
|
||||
#ifdef YOSYS_ENABLE_SOURCE_LOCATION
|
||||
#include <experimental/source_location>
|
||||
using std::experimental::source_location;
|
||||
#else
|
||||
struct source_location { // dummy placeholder
|
||||
int line() const { return 0; }
|
||||
int column() const { return 0; }
|
||||
const char* file_name() const { return nullptr; }
|
||||
const char* function_name() const { return nullptr; }
|
||||
static const source_location current(...) { return source_location(); }
|
||||
};
|
||||
#endif
|
||||
|
||||
YOSYS_NAMESPACE_BEGIN
|
||||
|
||||
class PrettyHelp
|
||||
|
@ -37,13 +50,33 @@ public:
|
|||
|
||||
bool has_content();
|
||||
|
||||
void usage(const string &usage);
|
||||
void option(const string &text, const string &description = "");
|
||||
void codeblock(const string &code, const string &language = "none");
|
||||
void paragraph(const string &text);
|
||||
void usage(
|
||||
const string &usage,
|
||||
const source_location location = source_location::current()
|
||||
);
|
||||
void option(
|
||||
const string &text,
|
||||
const string &description = "",
|
||||
const source_location location = source_location::current()
|
||||
);
|
||||
void codeblock(
|
||||
const string &code,
|
||||
const string &language = "none",
|
||||
const source_location location = source_location::current()
|
||||
);
|
||||
void paragraph(
|
||||
const string &text,
|
||||
const source_location location = source_location::current()
|
||||
);
|
||||
|
||||
void open_optiongroup(const string &group = "");
|
||||
void open_option(const string &text);
|
||||
void open_optiongroup(
|
||||
const string &group = "",
|
||||
const source_location location = source_location::current()
|
||||
);
|
||||
void open_option(
|
||||
const string &text,
|
||||
const source_location location = source_location::current()
|
||||
);
|
||||
void close(int levels = 1);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue