17#ifndef BACKENDS_BMV2_COMMON_BACKEND_H_ 
   18#define BACKENDS_BMV2_COMMON_BACKEND_H_ 
   20#include "JsonObjects.h" 
   21#include "controlFlowGraph.h" 
   22#include "expression.h" 
   23#include "frontends/common/model.h" 
   24#include "frontends/p4/coreLibrary.h" 
   27#include "lib/cstring.h" 
   29#include "lib/exceptions.h" 
   33#include "lib/nullstream.h" 
   34#include "midend/actionSynthesis.h" 
   35#include "midend/convertEnums.h" 
   36#include "midend/removeComplexExpressions.h" 
   37#include "midend/removeLeftSlices.h" 
   39#include "sharedActionSelectorCheck.h" 
   43enum gress_t { INGRESS, EGRESS };
 
   56class ExpressionConverter;
 
   64    P4::ConvertEnums::EnumMapping *enumMap;
 
   67    const IR::ToplevelBlock *toplevel = 
nullptr;
 
   71            P4::ConvertEnums::EnumMapping *enumMap)
 
   76          corelib(P4::P4CoreLibrary::instance()),
 
   80    void serialize(std::ostream &out)
 const { json->toplevel->serialize(out); }
 
   81    virtual void convert(
const IR::ToplevelBlock *block) = 0;
 
 
   91    const std::set<cstring> *skip;
 
   94    explicit SkipControls(
const std::set<cstring> *skip) : skip(skip) { CHECK_NULL(skip); }
 
   96        if (skip->find(control->name) != skip->end()) 
return false;
 
 
 
  107    const std::set<cstring> *process;
 
  110    explicit ProcessControls(
const std::set<cstring> *process) : process(process) {
 
  113    bool convert(
const IR::P4Control *control)
 const {
 
  114        if (process->find(control->name) != process->end()) 
return true;
 
 
 
  125    const IR::Type_Struct *userMetaType;
 
  129    bool renamed = 
false;
 
  134        : refMap(refMap), userMetaType(userMetaType), namePrefix(namePrefix) {
 
  135        setName(
"RenameUserMetadata");
 
  137        visitDagOnce = 
false;
 
  140    const IR::Node *postorder(IR::Type_Struct *type)
 override {
 
  142        auto orig = getOriginal<IR::Type_Struct>();
 
  143        if (userMetaType->name != orig->name) 
return type;
 
  146        LOG2(
"Creating clone of " << orig);
 
  148        auto clone = type->clone();
 
  149        clone->name = namePrefix;
 
  150        vec->push_back(clone);
 
  154        for (
auto f : type->fields) {
 
  155            auto anno = f->getAnnotation(IR::Annotation::nameAnnotation);
 
  156            cstring suffix = cstring::empty;
 
  157            if (anno != 
nullptr) suffix = anno->getName();
 
  158            if (suffix.startsWith(
".")) {
 
  161                fields.push_back(f->clone());
 
  165            if (!suffix.isNullOrEmpty())
 
  166                suffix = 
"."_cs + suffix;
 
  168                suffix = 
"."_cs + f->name;
 
  169            cstring newName = namePrefix + suffix;
 
  170            auto stringLit = 
new IR::StringLiteral(newName);
 
  171            LOG2(
"Renaming " << f << 
" to " << newName);
 
  172            auto annos = f->annotations->addOrReplace(IR::Annotation::nameAnnotation, stringLit);
 
  173            auto field = 
new IR::StructField(f->srcInfo, f->name, annos, f->type);
 
  174            fields.push_back(field);
 
  178            new IR::Type_Struct(type->srcInfo, type->name, type->annotations, std::move(fields));
 
  179        vec->push_back(annotated);
 
  183    const IR::Node *preorder(IR::Type_Name *type)
 override {
 
  186        if (decl == userMetaType)
 
  187            type->path = 
new IR::Path(type->path->srcInfo, 
IR::ID(type->path->srcInfo, namePrefix));
 
  188        LOG2(
"Replacing reference with " << type);
 
  192    void end_apply(
const IR::Node *)
 override {
 
  193        BUG_CHECK(renamed, 
"Could not identify user metadata type declaration %1%", userMetaType);
 
 
Definition backends/bmv2/common/options.h:26
 
Backend is a the base class for SimpleSwitchBackend and PortableSwitchBackend.
Definition bmv2/common/backend.h:59
 
Definition JsonObjects.h:27
 
Definition bmv2/common/backend.h:106
 
bool convert(const IR::P4Control *control) const
Definition bmv2/common/backend.h:113
 
This class implements a policy suitable for the SynthesizeActions pass.
Definition bmv2/common/backend.h:89
 
bool convert(const Visitor::Context *, const IR::P4Control *control) override
Definition bmv2/common/backend.h:95
 
Definition actionSynthesis.h:30
 
Definition coreLibrary.h:98
 
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
 
const IR::IDeclaration * getDeclaration(const IR::Path *path, bool notNull=false) const override
Definition referenceMap.cpp:78
 
void setIsV1(bool isv1)
Set boolean indicating whether map is for a P4_14 program to isV1.
Definition referenceMap.h:105
 
Definition backends/common/removeComplexExpressions.h:28
 
bool isv1() const
True if we are compiling a P4 v1.0 or v1.1 program.
Definition parser_options.cpp:469
 
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition action.cpp:21