Skip to content

Commit

Permalink
implemented ParsePsaArchitecture pass to build a map from IR::Node* t…
Browse files Browse the repository at this point in the history
…o std::pair<gress_t, block_t> (#18)
  • Loading branch information
hanw authored May 5, 2018
1 parent 2ea05fc commit ab4fe72
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
33 changes: 27 additions & 6 deletions backends/bmv2/portableSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IR::ParserBlock>();
pipeline = block->getParameterValue("ig")->to<IR::ControlBlock>();
deparser = block->getParameterValue("id")->to<IR::ControlBlock>();
} else if (gress == EGRESS) {
parser = block->getParameterValue("ep")->to<IR::ParserBlock>();
pipeline = block->getParameterValue("eg")->to<IR::ControlBlock>();
deparser = block->getParameterValue("ed")->to<IR::ControlBlock>();
}

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<IR::Block>()) {
visit(t.second->getNode());
}
auto pkg = block->getParameterValue("ingress");
if (auto ingress = pkg->to<IR::PackageBlock>()) {
parse_pipeline(ingress, INGRESS);
}
pkg = block->getParameterValue("egress");
if (auto egress = pkg->to<IR::PackageBlock>()) {
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) {
Expand Down
15 changes: 15 additions & 0 deletions backends/bmv2/portableSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,6 +56,9 @@ class PsaProgramStructure {
unsigned error_width = 32;
unsigned bool_width = 1;

// architecture related information
ordered_map<IR::Node*, std::pair<gress_t, block_t>> block_type;

ordered_map<cstring, const IR::Type_Header*> header_types;
ordered_map<cstring, const IR::Type_Struct*> metadata_types;
ordered_map<cstring, const IR::Type_HeaderUnion*> header_union_types;
Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit ab4fe72

Please sign in to comment.