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 P4::TC {
32
33using namespace P4::literals;
34
36 cstring schemaVersion;
37 cstring pipelineName;
39 schemaVersion = nullptr;
40 pipelineName = nullptr;
41 }
42 void initIntrospectionInfo(IR::TCPipeline *tcPipeline) {
43 schemaVersion = "1.0.0"_cs;
44 pipelineName = tcPipeline->pipelineName;
45 }
46};
47
49 unsigned int id;
50 cstring name;
51 cstring type;
52 cstring matchType;
53 cstring attribute;
54 unsigned int bitwidth;
56 id = 0;
57 name = nullptr;
58 type = nullptr;
59 matchType = nullptr;
60 attribute = nullptr;
61 bitwidth = 0;
62 }
63};
64
65struct Annotation {
66 cstring name;
67 Annotation() { name = nullptr; }
68 explicit Annotation(cstring n) { name = n; }
69};
70
72 unsigned int id;
73 cstring name;
74 unsigned int dataType;
75 unsigned int bitwidth;
76 ActionParam() {
77 id = 0;
78 name = nullptr;
79 bitwidth = 0;
80 }
81};
82
83enum ActionScope { TableOnly, DefaultOnly, TableAndDefault };
84
86 unsigned int id;
87 cstring name;
88 ActionScope scope;
89 bool defaultHit;
90 bool defaultMiss;
94 id = 0;
95 name = nullptr;
96 scope = TableAndDefault;
97 defaultHit = false;
98 defaultMiss = false;
99 }
100};
101
103 cstring name;
104 cstring permissions;
105 unsigned int id;
106 unsigned int tentries;
107 unsigned int numMask;
108 unsigned int keysize;
109 unsigned int keyid;
113 name = nullptr;
114 permissions = nullptr;
115 id = 0;
116 tentries = 0;
117 numMask = 0;
118 keysize = 0;
119 keyid = 0;
120 }
121};
122
124 unsigned int id;
125 cstring name;
126 cstring type;
129 id = 0;
130 name = nullptr;
131 type = nullptr;
132 }
133};
134
136 cstring name;
137 cstring permissions;
138 cstring id;
141 name = nullptr;
142 permissions = nullptr;
143 id = 0;
144 }
145};
146
149 IR::TCPipeline *tcPipeline;
150 P4::ReferenceMap *refMap;
151 P4::TypeMap *typeMap;
155
156 public:
157 IntrospectionGenerator(IR::TCPipeline *tcPipeline, P4::ReferenceMap *refMap,
158 P4::TypeMap *typeMap)
159 : tcPipeline(tcPipeline), refMap(refMap), typeMap(typeMap) {}
160 void postorder(const IR::P4Table *t);
161 const Util::JsonObject *genIntrospectionJson();
162 void genExternJson(Util::JsonArray *externJson);
163 Util::JsonObject *genExternInfo(struct ExternAttributes *extn);
164 void genTableJson(Util::JsonArray *tablesJson);
165 Util::JsonObject *genTableInfo(struct TableAttributes *tbl);
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);
171 Util::JsonObject *genActionInfo(struct ActionAttributes *action);
172 Util::JsonObject *genKeyInfo(struct KeyFieldAttributes *keyField);
173 bool serializeIntrospectionJson(std::ostream &destination);
174 std::optional<cstring> checkValidTcType(const IR::StringLiteral *sl);
175 cstring externalName(const IR::IDeclaration *declaration);
176};
177
178} // namespace P4::TC
179
180#endif /* BACKENDS_TC_INTROSPECTION_H_ */
The Declaration interface, representing objects with names.
Definition declaration.h:26
Definition visitor.h:400
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
This pass generates introspection JSON into user specified file.
Definition introspection.h:148
Definition typeMap.h:41
Definition json.h:115
Definition json.h:164
Definition cstring.h:85
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 cstring.h:80
Definition introspection.h:85
Definition introspection.h:71
Definition introspection.h:65
Definition introspection.h:135
Definition introspection.h:123
Definition introspection.h:35
Definition introspection.h:48
Definition introspection.h:102