Skip to content

Commit

Permalink
Polish front end last pass. (p4lang#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnfoster authored and sethfowler committed May 8, 2017
1 parent 8f355cd commit d576fda
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions frontends/common/constantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ const IR::Node* DoConstantFolding::postorder(IR::PathExpression* e) {
auto decl = refMap->getDeclaration(e->path);
if (decl == nullptr)
return e;
auto v = get(constants, decl->getNode());
if (v == nullptr)
return e;
setConstant(e, v);
if (v->is<IR::ListExpression>())
return e;
return v;
if (decl->is<IR::Declaration_Constant>()) {
auto c = decl->to<IR::Declaration_Constant>();
auto v = getConstant(c->initializer);
if (v == nullptr)
return e;
if (v->is<IR::ListExpression>())
return e;
LOG2("Folded " << e << " to " << v);
return v;
}
LOG2("Skipping " << e);
return e;
}

const IR::Node* DoConstantFolding::postorder(IR::Declaration_Constant* d) {
Expand Down Expand Up @@ -457,6 +462,7 @@ const IR::Node* DoConstantFolding::postorder(IR::Slice* e) {
}

const IR::Node* DoConstantFolding::postorder(IR::Member* e) {
LOG2("e->type " << e->type);
if (!typesKnown)
return e;
auto orig = getOriginal<IR::Member>();
Expand Down
2 changes: 1 addition & 1 deletion frontends/p4/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class PrettyPrint : public Inspector {

/**
* This pass is a no-op whose purpose is to mark the end of the
* front-end, used for testing. It is implemented as an
* front-end, which is useful for debugging. It is implemented as an
* empty @ref PassManager (instead of a @ref Visitor) for efficiency.
*/
class FrontEndLast : public PassManager {
Expand Down

0 comments on commit d576fda

Please sign in to comment.