P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
introspection.h
1/*
2Copyright (C) 2023 Intel Corporation
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing,
11software distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions
14and limitations under the License.
15*/
16
17#ifndef BACKENDS_TC_INTROSPECTION_H_
18#define BACKENDS_TC_INTROSPECTION_H_
19
20#include "frontends/p4/parseAnnotations.h"
21#include "frontends/p4/parserCallGraph.h"
22#include "ir/ir.h"
23#include "lib/json.h"
24#include "lib/nullstream.h"
25#include "options.h"
26#include "tcAnnotations.h"
27
31namespace TC {
32
34 cstring schemaVersion;
35 cstring pipelineName;
37 schemaVersion = nullptr;
38 pipelineName = nullptr;
39 }
40 void initIntrospectionInfo(IR::TCPipeline *tcPipeline) {
41 schemaVersion = "1.0.0";
42 pipelineName = tcPipeline->pipelineName;
43 }
44};
45
47 unsigned int id;
48 cstring name;
49 cstring type;
50 cstring matchType;
51 unsigned int bitwidth;
53 id = 0;
54 name = nullptr;
55 type = nullptr;
56 matchType = nullptr;
57 bitwidth = 0;
58 }
59};
60
61struct Annotation {
62 cstring name;
63 Annotation() { name = nullptr; }
64 explicit Annotation(cstring n) { name = n; }
65};
66
68 unsigned int id;
69 cstring name;
70 unsigned int dataType;
71 unsigned int bitwidth;
72 ActionParam() {
73 id = 0;
74 name = nullptr;
75 bitwidth = 0;
76 }
77};
78
79enum ActionScope { TableOnly, DefaultOnly, TableAndDefault };
80
82 unsigned int id;
83 cstring name;
84 ActionScope scope;
85 bool defaultHit;
86 bool defaultMiss;
90 id = 0;
91 name = nullptr;
92 scope = TableAndDefault;
93 defaultHit = false;
94 defaultMiss = false;
95 }
96};
97
99 cstring name;
100 unsigned int id;
101 unsigned int tentries;
102 unsigned int numMask;
103 unsigned int keysize;
104 unsigned int keyid;
108 name = nullptr;
109 id = 0;
110 tentries = 0;
111 numMask = 0;
112 keysize = 0;
113 keyid = 0;
114 }
115};
116
118class IntrospectionGenerator : public Inspector {
119 IR::TCPipeline *tcPipeline;
120 P4::ReferenceMap *refMap;
121 P4::TypeMap *typeMap;
124
125 public:
126 IntrospectionGenerator(IR::TCPipeline *tcPipeline, P4::ReferenceMap *refMap,
127 P4::TypeMap *typeMap)
128 : tcPipeline(tcPipeline), refMap(refMap), typeMap(typeMap) {}
129 void postorder(const IR::P4Table *t);
130 const Util::JsonObject *genIntrospectionJson();
131 void genTableJson(Util::JsonArray *tablesJson);
132 Util::JsonObject *genTableInfo(struct TableAttributes *tbl);
133 void collectTableInfo();
134 void collectKeyInfo(const IR::Key *k, struct TableAttributes *tableinfo);
135 void collectActionInfo(const IR::ActionList *actionlist, struct TableAttributes *tableinfo,
136 const IR::P4Table *p4table, const IR::TCTable *table);
137 Util::JsonObject *genActionInfo(struct ActionAttributes *action);
138 Util::JsonObject *genKeyInfo(struct KeyFieldAttributes *keyField);
139 bool serializeIntrospectionJson(std::ostream &destination);
140 std::optional<cstring> checkValidTcType(const IR::StringLiteral *sl);
141 cstring externalName(const IR::IDeclaration *declaration);
142};
143
144} // namespace TC
145
146#endif /* BACKENDS_TC_INTROSPECTION_H_ */
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition typeMap.h:42
This pass generates introspection JSON into user specified file.
Definition introspection.h:118
Definition json.h:111
Definition json.h:158
Definition cstring.h:72
Definition ordered_map.h:30
Definition safe_vector.h:25
This file defines functions for the pass to generate the introspection file.
Definition backend.cpp:24
Definition introspection.h:81
Definition introspection.h:67
Definition introspection.h:61
Definition introspection.h:33
Definition introspection.h:46
Definition introspection.h:98