17#ifndef BACKENDS_TC_INTROSPECTION_H_
18#define BACKENDS_TC_INTROSPECTION_H_
20#include "frontends/p4/parseAnnotations.h"
21#include "frontends/p4/parserCallGraph.h"
24#include "lib/nullstream.h"
26#include "tcAnnotations.h"
33using namespace P4::literals;
35struct IntrospectionInfo {
39 schemaVersion =
nullptr;
40 pipelineName =
nullptr;
42 void initIntrospectionInfo(IR::TCPipeline *tcPipeline) {
43 schemaVersion =
"1.0.0"_cs;
44 pipelineName = tcPipeline->pipelineName;
48struct KeyFieldAttributes {
54 unsigned int bitwidth;
55 KeyFieldAttributes() {
67 Annotation() { name =
nullptr; }
68 explicit Annotation(
cstring n) { name = n; }
74 unsigned int dataType;
75 unsigned int bitwidth;
83enum ActionScope { TableOnly, DefaultOnly, TableAndDefault };
85struct ActionAttributes {
96 scope = TableAndDefault;
102struct TableAttributes {
106 unsigned int tentries;
107 unsigned int numMask;
108 unsigned int keysize;
114 permissions =
nullptr;
123struct ExternInstancesAttributes {
128 ExternInstancesAttributes() {
135struct ExternAttributes {
142 permissions =
nullptr;
148class IntrospectionGenerator :
public Inspector {
149 IR::TCPipeline *tcPipeline;
157 IntrospectionGenerator(IR::TCPipeline *tcPipeline,
P4::ReferenceMap *refMap,
159 : tcPipeline(tcPipeline), refMap(refMap), typeMap(typeMap) {}
160 void postorder(
const IR::P4Table *t);
166 void collectTableInfo();
167 void collectExternInfo();
168 void collectKeyInfo(
const IR::Key *k,
struct TableAttributes *tableinfo);
169 void collectActionInfo(
const IR::ActionList *actionlist,
struct TableAttributes *tableinfo,
170 const IR::P4Table *p4table,
const IR::TCTable *table);
173 bool serializeIntrospectionJson(std::ostream &destination);
174 std::optional<cstring> checkValidTcType(
const IR::StringLiteral *sl);
The Declaration interface, representing objects with names.
Definition declaration.h:26
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition ordered_map.h:32
Definition safe_vector.h:27
This file defines functions for the pass to generate the introspection file.
Definition tc/backend.cpp:24
Definition introspection.h:85
Definition introspection.h:135
Definition introspection.h:48
Definition introspection.h:102