19#ifndef BACKENDS_TOFINO_BF_P4C_COMMON_PRAGMA_H_
20#define BACKENDS_TOFINO_BF_P4C_COMMON_PRAGMA_H_
35 virtual const char *
name()
const {
return "undefined"; }
41 virtual const char *
help()
const = 0;
46 auto format = [](
const char *str,
size_t width,
size_t indent = 0) ->
const char * {
49 std::string chunk = std::string(str).substr(0, width);
50 auto newline = chunk.find(
'\n');
51 if (newline != std::string::npos) {
52 res += chunk.substr(0, newline + 1);
54 }
else if (strlen(str) < width) {
59 auto lastspace = chunk.rfind(
' ');
60 if (lastspace != std::string::npos) {
61 res += chunk.substr(0, lastspace) +
"\n";
69 }
while (strlen(str) > 0);
73 auto formatPragma = [format](
const Pragma *p, std::ostream &o) {
75 o << p->name() <<
": " << format(p->description(), 80 - (strlen(p->name()) + 3))
78 o << format(p->help(), 80) << std::endl;
81 o <<
"Supported pragmas:" << std::endl;
82 for (
auto &p : _supported_pragmas) formatPragma(p, o);
84 for (
auto &p : _internal_pragmas) formatPragma(p, o);
93 std::cerr <<
"registering " << p->name() << std::endl;
95 _supported_pragmas.insert(p);
97 _internal_pragmas.insert(p);
103 bool operator()(
const Pragma *a,
const Pragma *b)
const {
104 return std::string(a->name()) < std::string(b->name());
109 static std::set<const Pragma *, PragmaCmp> _supported_pragmas;
111 static std::set<const Pragma *, PragmaCmp> _internal_pragmas;
virtual const char * help() const =0
detailed description that will be printed as help
static bool registerPragma(const Pragma *p, bool internal=false)
Definition pragma.h:92
virtual const char * description() const =0
short description that will be printed as help
virtual const char * name() const
the pragma name – should be overriden
Definition pragma.h:35
static std::ostream & printHelp(std::ostream &o)
print the currently supported pragmas
Definition pragma.h:44
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
Definition pretty_print.h:25