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

[P4Testgen] Add the Tofino testgen target. #5038

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Next Next commit
Fix incorrect annotation parsing in Tofino.
Signed-off-by: fruffy <fruffy@nyu.edu>
  • Loading branch information
fruffy committed Dec 4, 2024
commit dbc99ec35243aa001b07c68f0aae9800b92a3fdc
20 changes: 10 additions & 10 deletions backends/tofino/bf-p4c/bf-p4c-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,24 +905,24 @@ BFNOptionPragmaParser::parseCompilerOption(const IR::Annotation *annotation) {
// Parsing of option pragmas is done early in the compiler, before P4₁₆
// annotations are parsed, so we are responsible for doing our own parsing
// here.
auto args = &annotation->getExpr();
if (args->empty()) {
auto parseResult =
const IR::Vector<IR::Expression> *args = nullptr;
if (annotation->needsParsing()) {
args =
P4::P4ParserDriver::parseExpressionList(annotation->srcInfo, annotation->getUnparsed());
if (parseResult != nullptr) {
args = parseResult;
}
} else {
args = &annotation->getExpr();
}
CHECK_NULL(args);

bool first = true;
for (auto *arg : *args) {
for (const P4::IR::Expression *arg : *args) {
// Try to convert the parsed expression to a valid option string
cstring optionString = ""_cs;
if (auto *argString = arg->to<IR::StringLiteral>()) {
if (const auto *argString = arg->to<IR::StringLiteral>()) {
optionString = argString->value;
} else {
// The expression is not a IR::StringLiteral, but it can still be a valid integer
if (auto *argConstant = arg->to<IR::Constant>()) {
if (const auto *argConstant = arg->to<IR::Constant>()) {
optionString = std::to_string(argConstant->asInt());
} else {
// The expression is neither a IR::StringLiteral or IR::Constant and so is invalid
Expand All @@ -932,7 +932,7 @@ BFNOptionPragmaParser::parseCompilerOption(const IR::Annotation *annotation) {
}
}

if (first && !cmdLinePragmas.count(optionString)) {
if (first && (cmdLinePragmas.count(optionString) == 0U)) {
::warning("Unknown @pragma command_line %1%", annotation);
return std::nullopt;
}
Expand Down
Loading