Skip to content

Commit

Permalink
Check to ensure PassManagers are called properly with apply.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Dodd committed Jan 26, 2017
1 parent 323643a commit 8b27ae3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frontends/common/parseInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const IR::P4Program* parseP4File(CompilerOptions& options) {
return nullptr;
if (Log::verbose())
std::cerr << "Converting to P4-16" << std::endl;
converter.visit(v1);
v1 = v1->apply(converter);
if (v1 != nullptr) {
result = v1->to<IR::P4Program>();
if (result == nullptr) {
Expand Down
4 changes: 4 additions & 0 deletions ir/pass_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const IR::Node *PassManager::apply_visitor(const IR::Node *program, const char *
vector<std::pair<vector<Visitor *>::iterator, const IR::Node *>> backup;

early_exit_flag = false;
BUG_CHECK(running, "not calling apply properly");
for (auto it = passes.begin(); it != passes.end();) {
Visitor* v = *it;
if (auto b = dynamic_cast<Backtrack *>(v)) {
Expand Down Expand Up @@ -62,6 +63,7 @@ const IR::Node *PassManager::apply_visitor(const IR::Node *program, const char *
break;
seqNo++;
it++; }
running = false;
return program;
}

Expand Down Expand Up @@ -93,6 +95,7 @@ const IR::Node *PassRepeated::apply_visitor(const IR::Node *program, const char
unsigned iterations = 0;
while (!done) {
LOG5("PassRepeated state is:\n" << dumpToString(program));
running = true;
auto newprogram = PassManager::apply_visitor(program, name);
if (program == newprogram || newprogram == nullptr)
done = true;
Expand All @@ -109,6 +112,7 @@ const IR::Node *PassRepeated::apply_visitor(const IR::Node *program, const char

const IR::Node *PassRepeatUntil::apply_visitor(const IR::Node *program, const char *name) {
do {
running = true;
program = PassManager::apply_visitor(program, name);
} while (!done());
return program;
Expand Down
4 changes: 4 additions & 0 deletions ir/pass_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ class PassManager : virtual public Visitor, virtual public Backtrack {
vector<Visitor *> passes;
// if true stops compilation after first pass that signals an error
bool stop_on_error = true;
bool running = false;
unsigned seqNo = 0;
void addPasses(const std::initializer_list<Visitor *> &init) {
never_backtracks_cache = -1;
for (auto p : init) if (p) passes.emplace_back(p); }
void runDebugHooks(const char* visitorName, const IR::Node* node);
profile_t init_apply(const IR::Node *root) override {
running = true;
return Visitor::init_apply(root); }

public:
PassManager() = default;
Expand Down

0 comments on commit 8b27ae3

Please sign in to comment.