49class ConvertToBackendIR :
public Inspector {
60 unsigned no_of_instances;
64 enum CounterType { PACKETS, BYTES, PACKETS_AND_BYTES };
65 const IR::ToplevelBlock *tlb;
66 IR::TCPipeline *tcPipeline;
70 unsigned int tableCount = 0;
71 unsigned int actionCount = 0;
72 unsigned int metadataCount = 0;
73 unsigned int labelCount = 0;
74 unsigned int externCount = 0;
76 cstring mainParserName =
nullptr;
89 : tlb(tlb), tcPipeline(pipe), refMap(refMap), typeMap(typeMap), options(options) {}
90 void setPipelineName();
91 cstring getPipelineName() {
return pipelineName; };
92 bool preorder(
const IR::P4Program *p)
override;
93 void postorder(
const IR::P4Action *a)
override;
94 void postorder(
const IR::P4Table *t)
override;
95 void postorder(
const IR::P4Program *p)
override;
96 void postorder(
const IR::Declaration_Instance *d)
override;
97 void postorder(
const IR::Type_Struct *ts)
override;
98 safe_vector<const IR::TCKey *> processExternConstructor(
const IR::Type_Extern *extn,
99 const IR::Declaration_Instance *decl,
100 struct ExternInstance *instance);
101 safe_vector<const IR::TCKey *> processExternControlPath(
const IR::Type_Extern *extn,
102 const IR::Declaration_Instance *decl,
104 cstring getControlPathKeyAnnotation(
const IR::StructField *field);
105 unsigned GetAccessNumericValue(std::string_view access);
106 bool isDuplicateAction(
const IR::P4Action *action);
107 bool isDuplicateOrNoAction(
const IR::P4Action *action);
108 void updateDefaultHitAction(
const IR::P4Table *t, IR::TCTable *tdef);
109 void updateDefaultMissAction(
const IR::P4Table *t, IR::TCTable *tdef);
110 void updateConstEntries(
const IR::P4Table *t, IR::TCTable *tdef);
111 void updateMatchType(
const IR::P4Table *t, IR::TCTable *tabledef);
112 void updateTimerProfiles(IR::TCTable *tabledef);
113 void updatePnaDirectCounter(
const IR::P4Table *t, IR::TCTable *tabledef,
unsigned tentries);
115 bool isPnaMainInputMeta(
const IR::Member *mem);
116 bool isPnaMainOutputMeta(
const IR::Member *mem);
117 unsigned int findMappedKernelMeta(
const IR::Member *mem);
118 const IR::Expression *ExtractExpFromCast(
const IR::Expression *exp);
119 unsigned getTcType(
const IR::StringLiteral *sl);
120 unsigned getTableId(cstring tableName)
const;
121 unsigned getActionId(cstring actionName)
const;
122 cstring getExternId(cstring externName)
const;
123 unsigned getExternInstanceId(cstring externName, cstring instanceName)
const;
124 cstring processExternPermission(
const IR::Type_Extern *ext);
125 unsigned getTableKeysize(
unsigned tableId)
const;
126 cstring externalName(
const IR::IDeclaration *declaration)
const;
127 cstring HandleTableAccessPermission(
const IR::P4Table *t);
128 std::pair<cstring, cstring> *GetAnnotatedAccessPath(
const IR::Annotation *anno);
129 void updateAddOnMissTable(
const IR::P4Table *t);
130 bool checkParameterDirection(
const IR::TCAction *tcAction);
131 bool hasExecuteMethod(
const IR::Type_Extern *extn);
132 safe_vector<const IR::TCKey *> HandleTypeNameStructField(
const IR::StructField *field,
133 const IR::Type_Extern *extn,
134 const IR::Declaration_Instance *decl,
135 int &kId, cstring annoName);
136 safe_vector<const IR::TCKey *> processCounterControlPathKeys(
137 const IR::Type_Struct *extern_control_path,
const IR::Type_Extern *extn,
138 const IR::Declaration_Instance *decl);
139 CounterType toCounterType(
const int type);
148class Backend :
public PassManager {
150 const IR::ToplevelBlock *toplevel;
154 IR::TCPipeline *pipeline =
new IR::TCPipeline();
158 const IR::ToplevelBlock *top =
nullptr;
164 explicit Backend(
const IR::ToplevelBlock *toplevel,
P4::ReferenceMap *refMap,
166 : toplevel(toplevel), refMap(refMap), typeMap(typeMap), options(options) {
171 void serialize()
const;
172 bool serializeIntrospectionJson(std::ostream &out)
const;