diff --git a/backends/bmv2/common/addMissingIds.cpp b/backends/bmv2/common/addMissingIds.cpp deleted file mode 100644 index aec1fed58fa..00000000000 --- a/backends/bmv2/common/addMissingIds.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "addMissingIds.h" - -namespace BMV2 {} // namespace BMV2 diff --git a/backends/bmv2/common/addMissingIds.h b/backends/bmv2/common/addMissingIds.h deleted file mode 100644 index 0839ec2136a..00000000000 --- a/backends/bmv2/common/addMissingIds.h +++ /dev/null @@ -1,201 +0,0 @@ - -#ifndef BACKENDS_BMV2_COMMON_ADDMISSINGIDS_H_ -#define BACKENDS_BMV2_COMMON_ADDMISSINGIDS_H_ - -#include "common/resolveReferences/referenceMap.h" -#include "control-plane/p4RuntimeAnnotations.h" -#include "control-plane/p4RuntimeArchStandard.h" -#include "control-plane/p4RuntimeSerializer.h" -#include "control-plane/p4RuntimeSymbolTable.h" -#include "ir/ir.h" -#include "p4/evaluator/evaluator.h" -#include "p4/typeMap.h" - -namespace P4 { - -namespace BMV2 { - -class MissingIdAssigner : public Transform { - ReferenceMap* refMap; - - TypeMap* typeMap; - - ControlPlaneAPI::P4RuntimeSymbolTable symbols; - - const IR::P4Table* preorder(IR::P4Table* table) override { - if (ControlPlaneAPI::isHidden(table)) { - return table; - } - auto anno = ControlPlaneAPI::getIdAnnotation(table); - if (!anno) { - const auto* annos = table->getAnnotations(); - auto* newAnnos = annos->clone(); - IR::Vector annoExprs; - auto symbolId = symbols.getId( - ControlPlaneAPI::P4RuntimeSymbolType::TABLE(), table); - const auto* idConst = - new IR::Constant(new IR::Type_Bits(32, false), symbolId); - annoExprs.push_back(idConst); - newAnnos->add(new IR::Annotation("id", annoExprs)); - table->annotations = newAnnos; - } - int propertyIdx = 0; - - const IR::Key* key = nullptr; - for (propertyIdx = 0; - propertyIdx < - static_cast(table->properties->properties.size()); - ++propertyIdx) { - const auto* property = - table->properties->properties.at(propertyIdx); - if (property->name == "key") { - key = property->value->checkedTo(); - break; - } - } - if (key == nullptr) { - return table; - } - auto* newKey = key->clone(); - IR::Vector newKeys; - for (int symbolId = 0; symbolId < key->keyElements.size(); ++symbolId) { - auto* keyElement = key->keyElements.at(symbolId)->clone(); - auto anno = ControlPlaneAPI::getIdAnnotation(keyElement); - if (!anno) { - const auto* annos = keyElement->getAnnotations(); - auto* newAnnos = annos->clone(); - IR::Vector annoExprs; - const auto* idConst = new IR::Constant( - new IR::Type_Bits(32, false), symbolId + 1); - annoExprs.push_back(idConst); - newAnnos->add(new IR::Annotation("id", annoExprs)); - keyElement->annotations = newAnnos; - } - newKeys.push_back(keyElement); - } - newKey->keyElements = newKeys; - auto* clonedTableProperties = table->properties->clone(); - auto* properties = &clonedTableProperties->properties; - auto* propertyValue = properties->at(propertyIdx)->clone(); - propertyValue->value = newKey; - (*properties)[propertyIdx] = propertyValue; - table->properties = clonedTableProperties; - - return table; - } - - const IR::Type_Header* preorder(IR::Type_Header* hdr) override { - if (!ControlPlaneAPI::isControllerHeader(hdr) || - ControlPlaneAPI::isHidden(hdr)) { - return hdr; - } - auto anno = ControlPlaneAPI::getIdAnnotation(hdr); - if (!anno) { - const auto* annos = hdr->getAnnotations(); - auto* newAnnos = annos->clone(); - IR::Vector annoExprs; - auto symbolId = symbols.getId( - ControlPlaneAPI::P4RuntimeSymbolType::CONTROLLER_HEADER(), hdr); - const auto* idConst = - new IR::Constant(new IR::Type_Bits(32, false), symbolId); - annoExprs.push_back(idConst); - newAnnos->add(new IR::Annotation("id", annoExprs)); - hdr->annotations = newAnnos; - } - - return hdr; - } - - const IR::P4ValueSet* preorder(IR::P4ValueSet* valueSet) override { - if (ControlPlaneAPI::isHidden(valueSet)) { - return valueSet; - } - auto anno = ControlPlaneAPI::getIdAnnotation(valueSet); - if (!anno) { - const auto* annos = valueSet->getAnnotations(); - auto* newAnnos = annos->clone(); - IR::Vector annoExprs; - auto symbolId = symbols.getId( - ControlPlaneAPI::P4RuntimeSymbolType::VALUE_SET(), valueSet); - const auto* idConst = - new IR::Constant(new IR::Type_Bits(32, false), symbolId); - annoExprs.push_back(idConst); - newAnnos->add(new IR::Annotation("id", annoExprs)); - valueSet->annotations = newAnnos; - } - return valueSet; - } - - const IR::P4Action* preorder(IR::P4Action* action) override { - if (ControlPlaneAPI::isHidden(action)) { - return action; - } - auto anno = ControlPlaneAPI::getIdAnnotation(action); - if (!anno) { - const auto* annos = action->getAnnotations(); - auto* newAnnos = annos->clone(); - IR::Vector annoExprs; - auto symbolId = symbols.getId( - ControlPlaneAPI::P4RuntimeSymbolType::ACTION(), action); - const auto* idConst = - new IR::Constant(new IR::Type_Bits(32, false), symbolId); - annoExprs.push_back(idConst); - newAnnos->add(new IR::Annotation("id", annoExprs)); - action->annotations = newAnnos; - } - - auto* paramList = new IR::ParameterList(); - for (int symbolId = 0; symbolId < action->parameters->size(); - ++symbolId) { - auto* param = action->parameters->getParameter(symbolId)->clone(); - auto anno = ControlPlaneAPI::getIdAnnotation(param); - if (!anno) { - const auto* annos = param->getAnnotations(); - auto* newAnnos = annos->clone(); - IR::Vector annoExprs; - const auto* idConst = new IR::Constant( - new IR::Type_Bits(32, false), symbolId + 1); - annoExprs.push_back(idConst); - newAnnos->add(new IR::Annotation("id", annoExprs)); - param->annotations = newAnnos; - } - paramList->parameters.push_back(param); - } - action->parameters = paramList; - return action; - } - - public: - explicit MissingIdAssigner(ReferenceMap* refMap, TypeMap* typeMap, - const IR::ToplevelBlock* evaluatedProgram) - : refMap(refMap), typeMap(typeMap), - symbols(ControlPlaneAPI::P4RuntimeSymbolTable::generateSymbols( - evaluatedProgram->getProgram(), evaluatedProgram, refMap, typeMap, - ControlPlaneAPI::Standard::V1ModelArchHandlerBuilder()( - refMap, typeMap, evaluatedProgram))) { - CHECK_NULL(typeMap); - CHECK_NULL(refMap); - setName("MissingIdAssigner"); - } -}; - -class AddMissingIdAnnotations final : public PassManager { - public: - AddMissingIdAnnotations(ReferenceMap* refMap, TypeMap* typeMap, - const IR::ToplevelBlock* toplevelBlock) { - CHECK_NULL(refMap); - CHECK_NULL(typeMap); - passes.push_back(new ControlPlaneAPI::ParseP4RuntimeAnnotations()); - passes.push_back(new MissingIdAssigner(refMap, typeMap, toplevelBlock)); - // Need to refresh types after we have updated some expressions with - // IDs. - passes.push_back(new TypeChecking(refMap, typeMap, true)); - setName("AddMissingIdAnnotations"); - } -}; - -} // namespace BMV2 - -} // namespace P4 - -#endif /* BACKENDS_BMV2_COMMON_ADDMISSINGIDS_H_ */ diff --git a/backends/bmv2/simple_switch/midend.cpp b/backends/bmv2/simple_switch/midend.cpp index 4012d6af12b..72931074c9d 100644 --- a/backends/bmv2/simple_switch/midend.cpp +++ b/backends/bmv2/simple_switch/midend.cpp @@ -60,6 +60,7 @@ limitations under the License. #include "midend/midEndLast.h" #include "midend/fillEnumMap.h" #include "midend/removeAssertAssume.h" +#include "control-plane/addMissingIds.h" #include "backends/bmv2/simple_switch/options.h" @@ -71,6 +72,7 @@ SimpleSwitchMidEnd::SimpleSwitchMidEnd(CompilerOptions& options, std::ostream* o if (BMV2::SimpleSwitchContext::get().options().loadIRFromJson == false) { auto convertEnums = new P4::ConvertEnums(&refMap, &typeMap, new EnumOn32Bits("v1model.p4")); addPasses({ + new P4::AddMissingIdAnnotations(&refMap, &typeMap), options.ndebug ? new P4::RemoveAssertAssume(&refMap, &typeMap) : nullptr, new P4::CheckTableSize(), new P4::RemoveMiss(&refMap, &typeMap), diff --git a/backends/bmv2/simple_switch/simpleSwitch.cpp b/backends/bmv2/simple_switch/simpleSwitch.cpp index 6969ebfab9b..f82892b0e59 100644 --- a/backends/bmv2/simple_switch/simpleSwitch.cpp +++ b/backends/bmv2/simple_switch/simpleSwitch.cpp @@ -21,12 +21,10 @@ limitations under the License. #include #include #include -#include "backends/bmv2/common/addMissingIds.h" #include "backends/bmv2/common/annotations.h" #include "frontends/p4/fromv1.0/v1model.h" #include "frontends/p4/cloner.h" #include "midend/flattenLogMsg.h" -#include "p4/toP4/toP4.h" #include "simpleSwitch.h" #include "backends/bmv2/simple_switch/options.h" @@ -1224,11 +1222,6 @@ SimpleSwitchBackend::convert(const IR::ToplevelBlock* tlb) { main->apply(*parseV1Arch); program = toplevel->getProgram(); - program = program->apply( - P4::BMV2::AddMissingIdAnnotations(refMap, typeMap, toplevel)); - P4::ToP4 newEmitter; - program->apply(newEmitter); - program->apply(DiscoverStructure(structure)); /// generate error types diff --git a/control-plane/CMakeLists.txt b/control-plane/CMakeLists.txt index 930dd2be991..baf8962c421 100644 --- a/control-plane/CMakeLists.txt +++ b/control-plane/CMakeLists.txt @@ -71,6 +71,7 @@ add_custom_command(OUTPUT ${P4RUNTIME_GEN_SRCS} ${P4RUNTIME_GEN_HDRS} #PROTOBUF_GENERATE_PYTHON (P4RUNTIME_GEN_PYTHON P4RUNTIME_INFO_GEN_HDRS ${P4RUNTIME_INFO_PROTO}) set (CONTROLPLANE_SRCS + addMissingIds.cpp bytestrings.cpp flattenHeader.cpp p4RuntimeArchHandler.cpp @@ -86,6 +87,7 @@ set (CONTROLPLANE_SOURCES ) set (CONTROLPLANE_HDRS + addMissingIds.h bytestrings.h flattenHeader.h p4RuntimeArchHandler.h diff --git a/control-plane/addMissingIds.cpp b/control-plane/addMissingIds.cpp new file mode 100644 index 00000000000..a10f891a412 --- /dev/null +++ b/control-plane/addMissingIds.cpp @@ -0,0 +1,206 @@ +#include "addMissingIds.h" + +#include "p4RuntimeAnnotations.h" +#include "p4RuntimeArchStandard.h" + +#include "p4/evaluator/evaluator.h" + +namespace P4 { + + +const IR::P4Program* MissingIdAssigner::preorder(IR::P4Program* program) { + auto evaluator = EvaluatorPass(refMap, typeMap); + program->apply(evaluator); + auto* toplevel = evaluator.getToplevelBlock(); + CHECK_NULL(toplevel); + symbols = ControlPlaneAPI::P4RuntimeSymbolTable::generateSymbols( + toplevel->getProgram(), toplevel, refMap, typeMap, + ControlPlaneAPI::Standard::V1ModelArchHandlerBuilder()(refMap, typeMap, + toplevel)); + auto objectVector = IR::Vector(); + for (const auto* obj : program->objects) { + objectVector.push_back( + obj->apply(MissingIdAssigner(refMap, typeMap, symbols))); + } + program->objects = objectVector; + return program; +} + +const IR::P4Table* MissingIdAssigner::preorder(IR::P4Table* table) { + if (ControlPlaneAPI::isHidden(table)) { + return table; + } + auto anno = ControlPlaneAPI::getIdAnnotation(table); + if (!anno) { + const auto* annos = table->getAnnotations(); + auto* newAnnos = annos->clone(); + IR::Vector annoExprs; + auto symbolId = symbols->getId( + ControlPlaneAPI::P4RuntimeSymbolType::TABLE(), table); + const auto* idConst = + new IR::Constant(new IR::Type_Bits(ID_BIT_WIDTH, false), symbolId); + annoExprs.push_back(idConst); + newAnnos->add(new IR::Annotation("id", annoExprs)); + table->annotations = newAnnos; + } + size_t propertyIdx = 0; + + const IR::Key* key = nullptr; + auto propertyVector = table->properties->properties; + for (propertyIdx = 0; propertyIdx < propertyVector.size(); ++propertyIdx) { + const auto* property = propertyVector.at(propertyIdx); + if (property->name == "key") { + key = property->value->checkedTo(); + break; + } + } + if (key == nullptr) { + return table; + } + auto* newKey = key->clone(); + IR::Vector newKeys; + for (size_t symbolId = 0; symbolId < key->keyElements.size(); ++symbolId) { + auto* keyElement = key->keyElements.at(symbolId)->clone(); + auto anno = ControlPlaneAPI::getIdAnnotation(keyElement); + if (!anno) { + const auto* annos = keyElement->getAnnotations(); + auto* newAnnos = annos->clone(); + IR::Vector annoExprs; + const auto* idConst = new IR::Constant( + new IR::Type_Bits(ID_BIT_WIDTH, false), symbolId + 1); + annoExprs.push_back(idConst); + newAnnos->add(new IR::Annotation("id", annoExprs)); + keyElement->annotations = newAnnos; + } + newKeys.push_back(keyElement); + } + newKey->keyElements = newKeys; + auto* clonedTableProperties = table->properties->clone(); + IR::IndexedVector newProperties; + for (size_t idx = 0; idx < propertyVector.size(); ++idx) { + const auto* property = propertyVector.at(idx); + if (idx == propertyIdx) { + auto* propertyValue = property->clone(); + propertyValue->value = newKey; + newProperties.push_back(propertyValue); + } else { + newProperties.push_back(property); + } + } + clonedTableProperties->properties = newProperties; + table->properties = clonedTableProperties; + + return table; +} + +const IR::Type_Header* MissingIdAssigner::preorder(IR::Type_Header* hdr) { + if (!ControlPlaneAPI::isControllerHeader(hdr) || + ControlPlaneAPI::isHidden(hdr)) { + return hdr; + } + auto anno = ControlPlaneAPI::getIdAnnotation(hdr); + if (!anno) { + const auto* annos = hdr->getAnnotations(); + auto* newAnnos = annos->clone(); + IR::Vector annoExprs; + auto symbolId = symbols->getId( + ControlPlaneAPI::P4RuntimeSymbolType::CONTROLLER_HEADER(), hdr); + const auto* idConst = + new IR::Constant(new IR::Type_Bits(ID_BIT_WIDTH, false), symbolId); + annoExprs.push_back(idConst); + newAnnos->add(new IR::Annotation("id", annoExprs)); + hdr->annotations = newAnnos; + } + + return hdr; +} + +const IR::P4ValueSet* MissingIdAssigner::preorder(IR::P4ValueSet* valueSet) { + if (ControlPlaneAPI::isHidden(valueSet)) { + return valueSet; + } + auto anno = ControlPlaneAPI::getIdAnnotation(valueSet); + if (!anno) { + const auto* annos = valueSet->getAnnotations(); + auto* newAnnos = annos->clone(); + IR::Vector annoExprs; + auto symbolId = symbols->getId( + ControlPlaneAPI::P4RuntimeSymbolType::VALUE_SET(), valueSet); + const auto* idConst = + new IR::Constant(new IR::Type_Bits(ID_BIT_WIDTH, false), symbolId); + annoExprs.push_back(idConst); + newAnnos->add(new IR::Annotation("id", annoExprs)); + valueSet->annotations = newAnnos; + } + return valueSet; +} + +const IR::P4Action* MissingIdAssigner::preorder(IR::P4Action* action) { + if (ControlPlaneAPI::isHidden(action)) { + return action; + } + auto anno = ControlPlaneAPI::getIdAnnotation(action); + if (!anno) { + const auto* annos = action->getAnnotations(); + auto* newAnnos = annos->clone(); + IR::Vector annoExprs; + auto symbolId = symbols->getId( + ControlPlaneAPI::P4RuntimeSymbolType::ACTION(), action); + const auto* idConst = + new IR::Constant(new IR::Type_Bits(ID_BIT_WIDTH, false), symbolId); + annoExprs.push_back(idConst); + newAnnos->add(new IR::Annotation("id", annoExprs)); + action->annotations = newAnnos; + } + + auto* paramList = new IR::ParameterList(); + for (size_t symbolId = 0; symbolId < action->parameters->size(); + ++symbolId) { + auto* param = action->parameters->getParameter(symbolId)->clone(); + auto anno = ControlPlaneAPI::getIdAnnotation(param); + if (!anno) { + const auto* annos = param->getAnnotations(); + auto* newAnnos = annos->clone(); + IR::Vector annoExprs; + const auto* idConst = new IR::Constant( + new IR::Type_Bits(ID_BIT_WIDTH, false), symbolId + 1); + annoExprs.push_back(idConst); + newAnnos->add(new IR::Annotation("id", annoExprs)); + param->annotations = newAnnos; + } + paramList->parameters.push_back(param); + } + action->parameters = paramList; + return action; +} +MissingIdAssigner::MissingIdAssigner(ReferenceMap* refMap, TypeMap* typeMap) + : refMap(refMap), typeMap(typeMap) { + CHECK_NULL(typeMap); + CHECK_NULL(refMap); + setName("MissingIdAssigner"); +} + +MissingIdAssigner::MissingIdAssigner( + ReferenceMap* refMap, TypeMap* typeMap, + const ControlPlaneAPI::P4RuntimeSymbolTable* symbols) + : refMap(refMap), typeMap(typeMap), symbols(symbols) { + CHECK_NULL(typeMap); + CHECK_NULL(refMap); + CHECK_NULL(symbols); + setName("MissingIdAssigner"); +} + +AddMissingIdAnnotations::AddMissingIdAnnotations(ReferenceMap* refMap, + TypeMap* typeMap) { + CHECK_NULL(refMap); + CHECK_NULL(typeMap); + + passes.push_back(new ControlPlaneAPI::ParseP4RuntimeAnnotations()); + passes.push_back(new MissingIdAssigner(refMap, typeMap)); + // Need to refresh types after we have updated some expressions with + // IDs. + passes.push_back(new TypeChecking(refMap, typeMap, true)); + setName("AddMissingIdAnnotations"); +} + +} // namespace P4 diff --git a/control-plane/addMissingIds.h b/control-plane/addMissingIds.h new file mode 100644 index 00000000000..55487041c39 --- /dev/null +++ b/control-plane/addMissingIds.h @@ -0,0 +1,51 @@ + +#ifndef CONTROL_PLANE_ADDMISSINGIDS_H_ +#define CONTROL_PLANE_ADDMISSINGIDS_H_ + +#include "common/resolveReferences/referenceMap.h" +#include "ir/ir.h" +#include "p4RuntimeSymbolTable.h" +#include "p4/typeMap.h" + +namespace P4 { + +class MissingIdAssigner : public Transform { + /// The reference map. This is needed to identify the correct references for + /// some extern constructs. + ReferenceMap* refMap; + + /// The type map. This is needed to identify the correct types for some + /// extern constructs. + TypeMap* typeMap; + + /// Specifies the width of the IDs. + static constexpr int ID_BIT_WIDTH = 32; + + const ControlPlaneAPI::P4RuntimeSymbolTable* symbols = nullptr; + + const IR::P4Program* preorder(IR::P4Program* program) override; + + const IR::P4Table* preorder(IR::P4Table* table) override; + + const IR::Type_Header* preorder(IR::Type_Header* hdr) override; + + const IR::P4ValueSet* preorder(IR::P4ValueSet* valueSet) override; + + const IR::P4Action* preorder(IR::P4Action* action) override; + + public: + explicit MissingIdAssigner(ReferenceMap* refMap, TypeMap* typeMap); + + explicit MissingIdAssigner( + ReferenceMap* refMap, TypeMap* typeMap, + const ControlPlaneAPI::P4RuntimeSymbolTable* symbols); +}; + +class AddMissingIdAnnotations final : public PassManager { + public: + AddMissingIdAnnotations(ReferenceMap* refMap, TypeMap* typeMap); +}; + +} // namespace P4 + +#endif /* CONTROL_PLANE_ADDMISSINGIDS_H_ */ diff --git a/control-plane/p4RuntimeSerializer.cpp b/control-plane/p4RuntimeSerializer.cpp index 5dcca27e7aa..fd13df22f8d 100644 --- a/control-plane/p4RuntimeSerializer.cpp +++ b/control-plane/p4RuntimeSerializer.cpp @@ -1356,13 +1356,13 @@ P4RuntimeAnalyzer::analyze(const IR::P4Program* program, // Perform a first pass to collect all of the control plane visible symbols in // the program. - auto symbols = P4RuntimeSymbolTable::generateSymbols( + const auto *symbols = P4RuntimeSymbolTable::generateSymbols( program, evaluatedProgram, refMap, typeMap, archHandler); - archHandler->postCollect(symbols); + archHandler->postCollect(*symbols); // Construct a P4Runtime control plane API from the program. - P4RuntimeAnalyzer analyzer(symbols, typeMap, refMap, archHandler); + P4RuntimeAnalyzer analyzer(*symbols, typeMap, refMap, archHandler); Helpers::forAllEvaluatedBlocks(evaluatedProgram, [&](const IR::Block* block) { if (block->is()) { analyzer.analyzeControl(block->to()); @@ -1394,7 +1394,7 @@ P4RuntimeAnalyzer::analyze(const IR::P4Program* program, analyzer.addPkgInfo(evaluatedProgram, arch); - P4RuntimeEntriesConverter entriesConverter(symbols); + P4RuntimeEntriesConverter entriesConverter(*symbols); Helpers::forAllEvaluatedBlocks(evaluatedProgram, [&](const IR::Block* block) { if (block->is()) entriesConverter.addTableEntries(block->to(), refMap, diff --git a/control-plane/p4RuntimeSymbolTable.cpp b/control-plane/p4RuntimeSymbolTable.cpp index 903f91547dd..651275ed687 100644 --- a/control-plane/p4RuntimeSymbolTable.cpp +++ b/control-plane/p4RuntimeSymbolTable.cpp @@ -151,7 +151,7 @@ void collectParserSymbols(P4RuntimeSymbolTable& symbols, } } -P4::ControlPlaneAPI::P4RuntimeSymbolTable +P4::ControlPlaneAPI::P4RuntimeSymbolTable* P4::ControlPlaneAPI::P4RuntimeSymbolTable::generateSymbols( const IR::P4Program* program, const IR::ToplevelBlock* evaluatedProgram, ReferenceMap* refMap, TypeMap* typeMap, diff --git a/control-plane/p4RuntimeSymbolTable.h b/control-plane/p4RuntimeSymbolTable.h index af0e13f7a91..ac6536f8de9 100644 --- a/control-plane/p4RuntimeSymbolTable.h +++ b/control-plane/p4RuntimeSymbolTable.h @@ -111,22 +111,23 @@ class P4RuntimeSymbolTable : public P4RuntimeSymbolTableIface { * are assigned, create() enforces that only code that runs before id * assignment has access to a non-const reference to the symbol table. */ - template static P4RuntimeSymbolTable create(Func function) { + template + static P4RuntimeSymbolTable* create(Func function) { // Create and initialize the symbol table. At this stage, ids aren't // available, because computing ids requires global knowledge of all the // P4Runtime symbols in the program. - P4RuntimeSymbolTable symbols; - function(symbols); + auto* symbols = new P4RuntimeSymbolTable(); + function(*symbols); // Now that the symbol table is initialized, we can compute ids. - for (auto& table : symbols.symbolTables) { - symbols.computeIdsForSymbols(table.first); + for (auto& table : symbols->symbolTables) { + symbols->computeIdsForSymbols(table.first); } return symbols; } - static P4RuntimeSymbolTable + static P4RuntimeSymbolTable* generateSymbols(const IR::P4Program* program, const IR::ToplevelBlock* evaluatedProgram, ReferenceMap* refMap, TypeMap* typeMap, diff --git a/frontends/p4/evaluator/evaluator.h b/frontends/p4/evaluator/evaluator.h index 14fd1b6b085..eb8964b0298 100644 --- a/frontends/p4/evaluator/evaluator.h +++ b/frontends/p4/evaluator/evaluator.h @@ -25,7 +25,7 @@ namespace P4 { class IHasBlock { public: - virtual IR::ToplevelBlock* getToplevelBlock() = 0; + virtual IR::ToplevelBlock* getToplevelBlock() const = 0; }; class Evaluator final : public Inspector, public IHasBlock { @@ -42,7 +42,7 @@ class Evaluator final : public Inspector, public IHasBlock { Evaluator(const ReferenceMap* refMap, const TypeMap* typeMap) : refMap(refMap), typeMap(typeMap), toplevelBlock(nullptr) { CHECK_NULL(refMap); CHECK_NULL(typeMap); setName("Evaluator"); visitDagOnce = false; } - IR::ToplevelBlock* getToplevelBlock() override { return toplevelBlock; } + IR::ToplevelBlock* getToplevelBlock() const override { return toplevelBlock; } IR::Block* currentBlock() const; /// Map a node to value. The value can be nullptr, e.g., for an @@ -97,7 +97,7 @@ class Evaluator final : public Inspector, public IHasBlock { class EvaluatorPass final : public PassManager, public IHasBlock { P4::Evaluator* evaluator; public: - IR::ToplevelBlock* getToplevelBlock() override { return evaluator->getToplevelBlock(); } + IR::ToplevelBlock* getToplevelBlock() const override { return evaluator->getToplevelBlock(); } EvaluatorPass(ReferenceMap* refMap, TypeMap* typeMap); };