Skip to content

Commit

Permalink
Fixes from upstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Aug 15, 2024
1 parent 9ebe695 commit 1fa3ea5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
39 changes: 19 additions & 20 deletions dummy.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
#include <stdlib.h>
#include <iostream>

#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),
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions options.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "options.h"

namespace P4Dummy {
namespace P4::P4Dummy {

DummyOptions::DummyOptions() {
registerOption(
Expand All @@ -12,4 +12,4 @@ DummyOptions::DummyOptions() {
"Instead of parsing a real P4 program manipulate and parse a dummy program.");
}

} // namespace P4Dummy
} // namespace P4::P4Dummy
5 changes: 2 additions & 3 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -22,6 +21,6 @@ class DummyOptions : public CompilerOptions {

using P4DummyContext = P4CContextWithOptions<DummyOptions>;

} // namespace P4Dummy
} // namespace P4::P4Dummy

#endif /* _TOZ3_OPTIONS_H_ */

0 comments on commit 1fa3ea5

Please sign in to comment.