19#ifndef BACKENDS_TOFINO_BF_P4C_COMMON_PRAGMA_PRAGMA_H_
20#define BACKENDS_TOFINO_BF_P4C_COMMON_PRAGMA_PRAGMA_H_
44 static void registerPragma(
const Pragma *p,
bool internal =
false) {
46 _supported_pragmas.insert(p);
48 _internal_pragmas.insert(p);
54 auto format = [](
const char *str,
size_t width ) {
55 std::string *res =
new std::string(
"");
57 std::string chunk = std::string(str).substr(0, width);
58 auto newline = chunk.find(
'\n');
59 if (newline != std::string::npos) {
60 *res += chunk.substr(0, newline + 1);
62 }
else if (strlen(str) < width) {
67 auto lastspace = chunk.rfind(
' ');
68 if (lastspace != std::string::npos) {
69 *res += chunk.substr(0, lastspace) +
"\n";
77 }
while (strlen(str) > 0);
81 auto formatPragma = [format](
const Pragma *p, std::ostream &o) {
82 o << std::endl << std::string(80,
'-') << std::endl;
83 auto d = format(p->_description, 80 - (strlen(p->_name) + 3));
84 auto h = format(p->_help, 80);
85 o << p->_name <<
": " << d->c_str() << std::endl
87 << h->c_str() << std::endl;
92 o <<
"Supported pragmas:" << std::endl;
93 for (
auto &p : _supported_pragmas) formatPragma(p, o);
96 << std::string(80,
'*') << std::endl
97 <<
"Barefoot internal pragmas" << std::endl;
98 for (
auto &p : _internal_pragmas) formatPragma(p, o);
105 const char *_description;
109 bool operator()(
const Pragma *a,
const Pragma *b)
const {
110 return std::string(a->_name) < std::string(b->_name);
115 static std::set<const Pragma *, PragmaCmp> _supported_pragmas;
117 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/pragma.h:52
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
Definition pretty_print.h:25