From ab4fe7251bc7ad5f689ed576ebc028f4b7b74697 Mon Sep 17 00:00:00 2001 From: Han Wang Date: Sat, 5 May 2018 09:11:37 -0700 Subject: [PATCH] implemented ParsePsaArchitecture pass to build a map from IR::Node* to std::pair (#18) --- backends/bmv2/portableSwitch.cpp | 33 ++++++++++++++++++++++++++------ backends/bmv2/portableSwitch.h | 15 +++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/backends/bmv2/portableSwitch.cpp b/backends/bmv2/portableSwitch.cpp index 59af549a4f..4133537771 100644 --- a/backends/bmv2/portableSwitch.cpp +++ b/backends/bmv2/portableSwitch.cpp @@ -177,19 +177,40 @@ bool ParsePsaArchitecture::preorder(const IR::ToplevelBlock* block) { return false; } +void ParsePsaArchitecture::parse_pipeline(const IR::PackageBlock* block, gress_t gress) { + const IR::ParserBlock* parser; + const IR::ControlBlock* pipeline; + const IR::ControlBlock* deparser; + if (gress == INGRESS) { + parser = block->getParameterValue("ip")->to(); + pipeline = block->getParameterValue("ig")->to(); + deparser = block->getParameterValue("id")->to(); + } else if (gress == EGRESS) { + parser = block->getParameterValue("ep")->to(); + pipeline = block->getParameterValue("eg")->to(); + deparser = block->getParameterValue("ed")->to(); + } + + structure->block_type.emplace(parser->container, std::make_pair(gress, PARSER)); + structure->block_type.emplace(pipeline->container, std::make_pair(gress, PIPELINE)); + structure->block_type.emplace(deparser->container, std::make_pair(gress, DEPARSER)); +} + bool ParsePsaArchitecture::preorder(const IR::PackageBlock* block) { - for (auto t : block->constantValue) { - LOG1("first " << t.first << " second " << t.second); - if (t.second->is()) { - visit(t.second->getNode()); - } + auto pkg = block->getParameterValue("ingress"); + if (auto ingress = pkg->to()) { + parse_pipeline(ingress, INGRESS); + } + pkg = block->getParameterValue("egress"); + if (auto egress = pkg->to()) { + parse_pipeline(egress, EGRESS); } return false; } void InspectPsaProgram::postorder(const IR::P4Parser* p) { - // inspect IR::P4Parser // populate structure->parsers + } void InspectPsaProgram::postorder(const IR::P4Control* c) { diff --git a/backends/bmv2/portableSwitch.h b/backends/bmv2/portableSwitch.h index 2e4845261b..75c04acbd6 100644 --- a/backends/bmv2/portableSwitch.h +++ b/backends/bmv2/portableSwitch.h @@ -30,6 +30,17 @@ limitations under the License. namespace P4 { +enum gress_t { + INGRESS, + EGRESS +}; + +enum block_t { + PARSER, + PIPELINE, + DEPARSER +}; + class PsaProgramStructure { BMV2::JsonObjects* json; // output json data structure ReferenceMap* refMap; @@ -45,6 +56,9 @@ class PsaProgramStructure { unsigned error_width = 32; unsigned bool_width = 1; + // architecture related information + ordered_map> block_type; + ordered_map header_types; ordered_map metadata_types; ordered_map header_union_types; @@ -103,6 +117,7 @@ class ParsePsaArchitecture : public Inspector { public: explicit ParsePsaArchitecture(PsaProgramStructure* structure) : structure(structure) { } + void parse_pipeline(const IR::PackageBlock* block, gress_t gress); bool preorder(const IR::ToplevelBlock* block) override; bool preorder(const IR::PackageBlock* block) override; };