From 916af69454a0bd212ce6b7d38c822c2f9f724207 Mon Sep 17 00:00:00 2001 From: Fabian Ruffy <5960321+fruffy@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:19:35 +0200 Subject: [PATCH] Fixes from upstream. (#4) --- dummy.cpp | 39 +++++++++++++++++++-------------------- options.cpp | 4 ++-- options.h | 5 ++--- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/dummy.cpp b/dummy.cpp index aea05e4be..855fa9282 100644 --- a/dummy.cpp +++ b/dummy.cpp @@ -1,32 +1,31 @@ -#include #include #include "frontends/common/constantFolding.h" -#include "frontends/common/parseInput.h" -#include "frontends/p4/frontend.h" -#include "frontends/p4/toP4/toP4.h" -#include "ir/ir.h" -#include "options.h" -#include "test/gtest/helpers.h" #include "frontends/common/options.h" +#include "frontends/common/parseInput.h" #include "frontends/common/parser_options.h" #include "frontends/common/resolveReferences/referenceMap.h" +#include "frontends/p4/frontend.h" +#include "frontends/p4/toP4/toP4.h" #include "frontends/p4/typeChecking/typeChecker.h" #include "frontends/p4/typeMap.h" +#include "ir/ir.h" #include "ir/pass_manager.h" #include "ir/visitor.h" #include "lib/compile_context.h" #include "lib/cstring.h" #include "lib/error.h" +#include "options.h" +#include "test/gtest/helpers.h" -namespace P4Dummy { +namespace P4::P4Dummy { class MidEnd : public PassManager { P4::ReferenceMap refMap; P4::TypeMap typeMap; public: - explicit MidEnd() { + MidEnd() { addPasses({ new P4::TypeChecking(&refMap, &typeMap, true), new P4::ConstantFolding(&refMap, &typeMap), @@ -127,29 +126,29 @@ V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main;)"; return P4::parseP4String(source, options.langVersion); } -} // namespace P4Dummy +} // namespace P4::P4Dummy int main(int argc, char *const argv[]) { - AutoCompileContext autoP4DummyContext(new P4Dummy::P4DummyContext); - auto &options = P4Dummy::P4DummyContext::get().options(); + P4::AutoCompileContext autoP4DummyContext(new P4::P4Dummy::P4DummyContext); + auto &options = P4::P4Dummy::P4DummyContext::get().options(); if (options.process(argc, argv) == nullptr) { return EXIT_FAILURE; } - if (::errorCount() > 0) { - return EXIT_FAILURE; + if (P4::errorCount() > 0) { + return EXIT_FAILURE; } - const IR::P4Program *program = nullptr; + const P4::IR::P4Program *program = nullptr; if (options.useFixed) { - program = P4Dummy::parseDummyP4(options); + program = P4::P4Dummy::parseDummyP4(options); } else { options.setInputFile(); program = P4::parseP4File(options); } - if (program == nullptr && ::errorCount() != 0) { + if (program == nullptr && P4::errorCount() != 0) { return EXIT_FAILURE; } @@ -171,14 +170,14 @@ int main(int argc, char *const argv[]) { std::cout << "\n############################## AFTER MID END ##############################\n"; // Apply the mid end passes. - program = program->apply(P4Dummy::MidEnd()); + program = program->apply(P4::P4Dummy::MidEnd()); // Print the program after running front end passes. program->apply(top4); std::cout << "\n############################## CUSTOM VISITOR ##############################\n"; // Apply a custom visitor that prints the parser states for the respective program. - program->apply(P4Dummy::ParserVisitor()); + program->apply(P4::P4Dummy::ParserVisitor()); - return ::errorCount() > 0 ? EXIT_FAILURE : EXIT_SUCCESS; + return P4::errorCount() > 0 ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/options.cpp b/options.cpp index 9dbf9d8ce..81d2466fc 100644 --- a/options.cpp +++ b/options.cpp @@ -1,6 +1,6 @@ #include "options.h" -namespace P4Dummy { +namespace P4::P4Dummy { DummyOptions::DummyOptions() { registerOption( @@ -12,4 +12,4 @@ DummyOptions::DummyOptions() { "Instead of parsing a real P4 program manipulate and parse a dummy program."); } -} // namespace P4Dummy +} // namespace P4::P4Dummy diff --git a/options.h b/options.h index f2f33a194..11e1a7315 100644 --- a/options.h +++ b/options.h @@ -2,10 +2,9 @@ #define _TOZ3_OPTIONS_H_ #include "frontends/common/options.h" - #include "frontends/common/parser_options.h" -namespace P4Dummy { +namespace P4::P4Dummy { class DummyOptions : public CompilerOptions { public: @@ -22,6 +21,6 @@ class DummyOptions : public CompilerOptions { using P4DummyContext = P4CContextWithOptions; -} // namespace P4Dummy +} // namespace P4::P4Dummy #endif /* _TOZ3_OPTIONS_H_ */