Skip to content

Commit

Permalink
Further address duplicate system p4include issues
Browse files Browse the repository at this point in the history
Signed-off-by: Bili Dong <qobilidop@gmail.com>
  • Loading branch information
qobilidop committed Jun 30, 2024
1 parent 7345689 commit dab46f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion backends/tc/ebpfCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,10 @@ const PNAEbpfGenerator *ConvertToEbpfPNA::build(const IR::ToplevelBlock *tlb) {
!d->is<IR::Type_Error>()) {
if (d->srcInfo.isValid()) {
auto sourceFile = d->srcInfo.getSourceFile();
if (sourceFile.endsWith("/pna.p4")) {
// TODO: Similar logic exists in frontends/p4/toP4/toP4.cpp. Consider replacing
// the hard-coding here with a better long term solution.
if (sourceFile.endsWith("/pna.p4") ||
sourceFile.find("p4include/_internal") != nullptr) {
// do not generate standard PNA types
continue;
}
Expand Down
13 changes: 11 additions & 2 deletions frontends/p4/toP4/toP4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ bool ToP4::isSystemFile(cstring file) {
return false;
}

// Try to guess whether a file is a "system internal" file
bool ToP4::isSystemInternalFile(cstring file) {
if (noIncludes) return false;
if (file.startsWith(p4includeInternalPath) || file.find("p4include/_internal") != nullptr) {
return true;
}
return false;
}

cstring ToP4::ifSystemFile(const IR::Node *node) {
if (!node->srcInfo.isValid()) return nullptr;
auto sourceFile = node->srcInfo.getSourceFile();
Expand Down Expand Up @@ -165,10 +174,10 @@ bool ToP4::preorder(const IR::P4Program *program) {
* non-system header */

if (includesEmitted.find(sourceFile) == includesEmitted.end()) {
if (sourceFile.startsWith(p4includePath)) {
if (isSystemFile(sourceFile)) {
// Skip the include if it's an internal system header.
// TODO: This is a temporary hack. Need to figure out a better solution.
if (sourceFile.startsWith(p4includeInternalPath)) continue;
if (isSystemInternalFile(sourceFile)) continue;

const char *p = sourceFile.c_str() + strlen(p4includePath);
if (*p == '/') p++;
Expand Down
1 change: 1 addition & 0 deletions frontends/p4/toP4/toP4.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ToP4 : public Inspector {
listTerminators.pop_back();
}
bool isSystemFile(cstring file);
bool isSystemInternalFile(cstring file);
cstring ifSystemFile(const IR::Node *node); // return file containing node if system file
// dump node IR tree up to depth - in the form of a comment
void dump(unsigned depth, const IR::Node *node = nullptr, unsigned adjDepth = 0);
Expand Down

0 comments on commit dab46f6

Please sign in to comment.