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

[P4fmt]: attaching comments to IR Nodes #4845

Merged
merged 15 commits into from
Oct 24, 2024
Prev Previous commit
Next Next commit
resolve: nits & suggestions
Signed-off-by: Nitish <snapdgnn@proton.me>
  • Loading branch information
snapdgn committed Oct 24, 2024
commit 741129ed7aaef4ee661fe79b9f04ddf30e6c6d72
4 changes: 1 addition & 3 deletions backends/p4fmt/attach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const IR::Node *Attach::attachCommentsToNode(IR::Node *node, TraversalType ttype
return node;
}

std::filesystem::path sourceFile(node->srcInfo.getSourceFile().string_view());
if (isSystemFile(sourceFile.string())) {
// Skip attachment for system files
if (isSystemFile(node->srcInfo.getSourceFile())) {
return node;
}

Expand Down
4 changes: 0 additions & 4 deletions backends/p4fmt/attach.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#ifndef BACKENDS_P4FMT_ATTACH_H_
#define BACKENDS_P4FMT_ATTACH_H_

#include <filesystem>
#include <unordered_map>
#include <vector>

#include "ir/visitor.h"
#include "lib/source_file.h"

Expand Down
9 changes: 3 additions & 6 deletions backends/p4fmt/p4fmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@ namespace P4::P4Fmt {

std::optional<std::pair<const IR::P4Program *, const Util::InputSources *>> parseProgram(
const ParserOptions &options) {
auto *file = fopen(options.file.c_str(), "r");
if (file == nullptr) {
::P4::error(ErrorType::ERR_NOT_FOUND, "%1%: No such file or directory.", options.file);
if (!std::filesystem::exists(options.file)) {
::P4::error(ErrorType::ERR_NOT_FOUND, "%1%: No such file found.", options.file);
return std::nullopt;
}
if (options.isv1()) {
::P4::error(ErrorType::ERR_UNKNOWN, "p4fmt cannot deal with p4-14 programs");
fclose(file);
::P4::error(ErrorType::ERR_UNKNOWN, "p4fmt cannot deal with p4-14 programs.");
return std::nullopt;
}
auto preprocessorResult = options.preprocess();
auto result =
P4ParserDriver::parseProgramSources(preprocessorResult.value().get(), options.file.c_str());
fclose(file);

if (::P4::errorCount() > 0) {
::P4::error(ErrorType::ERR_OVERLIMIT, "%1% errors encountered, aborting compilation",
Expand Down