Skip to content

Commit

Permalink
Fix incorrect annotation parsing.
Browse files Browse the repository at this point in the history
Signed-off-by: fruffy <fruffy@nyu.edu>
  • Loading branch information
fruffy committed Dec 4, 2024
1 parent f8eaca2 commit d334655
Showing 1 changed file with 10 additions and 10 deletions.
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

0 comments on commit d334655

Please sign in to comment.