Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new P4C option #3425

Merged
merged 2 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions frontends/common/parser_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ ParserOptions::ParserOptions() : Util::Options(defaultMessage) {
"When the optimization is enabled, compiler tries to identify the cases,\n"
"when it can inline the subparser's states only once for multiple\n"
"invocations of the same subparser instance.");
registerOption(
"--doNotEmitIncludes", "condition",
[this](const char* arg) {
noIncludes = arg;
return true;
},
"[Compiler debugging] If true do not generate #include statements\n");
registerUsage(
"loglevel format is: \"sourceFile:level,...,sourceFile:level\"\n"
"where 'sourceFile' is a compiler source file and "
Expand Down Expand Up @@ -439,6 +446,9 @@ void ParserOptions::dumpPass(const char* manager, unsigned seq,
if (Log::verbose())
std::cerr << "Writing program to " << fileName << std::endl;
P4::ToP4 toP4(stream, Log::verbose(), file);
if (noIncludes) {
toP4.setnoIncludesArg(true);
}
node->apply(toP4);
delete stream; // close the file
}
Expand Down
3 changes: 3 additions & 0 deletions frontends/common/parser_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class ParserOptions : public Util::Options {
// list of possible relative paths.
bool searchForIncludePath(const char*& includePathOut,
std::vector<cstring> relativePaths, const char*);
/// If true do not generate #include statements.
/// Used for debugging.
bool noIncludes = false;
};

/// A compilation context which exposes compiler options and a compiler
Expand Down
4 changes: 4 additions & 0 deletions frontends/p4/toP4/toP4.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class ToP4 : public Inspector {

using Inspector::preorder;

void setnoIncludesArg(bool condition) {
noIncludes = condition;
}

void setListTerm(const char* start, const char* end) {
listTerminators.push_back(ListPrint(start, end));
}
Expand Down