31 bool isDeclaration =
true;
41 VecPrint(
const char *sep,
const char *term) : separator(sep), terminator(term) {}
48 ListPrint(
const char *start,
const char *end) : start(start), end(end) {}
52 std::vector<VecPrint> vectorSeparator;
53 size_t vectorSeparator_init_apply_size = 0;
54 std::vector<ListPrint> listTerminators;
55 size_t listTerminators_init_apply_size = 0;
57 void setVecSep(
const char *sep,
const char *term =
nullptr) {
58 vectorSeparator.push_back(
VecPrint(sep, term));
61 BUG_CHECK(!vectorSeparator.empty(),
"Empty vectorSeparator");
62 vectorSeparator.pop_back();
65 BUG_CHECK(!vectorSeparator.empty(),
"Empty vectorSeparator");
66 return vectorSeparator.back();
70 BUG_CHECK(!listTerminators.empty(),
"Empty listTerminators");
71 listTerminators.pop_back();
74 std::optional<cstring>
ifSystemFile(
const IR::Node *node);
76 void dump(
unsigned depth,
const IR::Node *node =
nullptr,
unsigned adjDepth = 0);
77 unsigned curDepth()
const;
78 bool printAnnotations(
const IR::IAnnotated *ann);
82 Util::SourceCodeBuilder &builder;
87 std::ostream *outStream =
nullptr;
99 this->outStream = outStream;
102 ToP4(Util::SourceCodeBuilder &builder,
bool showIR, std::filesystem::path
mainFile)
106 ToP4(std::ostream *outStream,
bool showIR, std::filesystem::path
mainFile)
107 : ToP4(outStream,
showIR) {
111 ToP4() : ToP4(*new Util::SourceCodeBuilder(), false) {}
113 using Inspector::preorder;
115 void setnoIncludesArg(
bool condition) {
noIncludes = condition; }
117 void setListTerm(
const char *start,
const char *end) {
118 listTerminators.push_back(
ListPrint(start, end));
120 Visitor::profile_t init_apply(
const IR::Node *node)
override;
121 void end_apply(
const IR::Node *node)
override;
123 bool process(
const IR::Type_StructLike *t,
const char *name);
125 bool preorder(
const IR::Type_Boolean *t)
override;
126 bool preorder(
const IR::Type_Varbits *t)
override;
127 bool preorder(
const IR::Type_Bits *t)
override;
128 bool preorder(
const IR::Type_InfInt *t)
override;
129 bool preorder(
const IR::Type_String *t)
override;
130 bool preorder(
const IR::Type_Var *t)
override;
131 bool preorder(
const IR::Type_Dontcare *t)
override;
132 bool preorder(
const IR::Type_Void *t)
override;
133 bool preorder(
const IR::Type_Error *t)
override;
134 bool preorder(
const IR::Type_Struct *t)
override {
return process(t,
"struct"); }
135 bool preorder(
const IR::Type_Header *t)
override {
return process(t,
"header"); }
136 bool preorder(
const IR::Type_HeaderUnion *t)
override {
return process(t,
"header_union"); }
137 bool preorder(
const IR::Type_Package *t)
override;
138 bool preorder(
const IR::Type_Parser *t)
override;
139 bool preorder(
const IR::Type_Control *t)
override;
140 bool preorder(
const IR::Type_Name *t)
override;
141 bool preorder(
const IR::Type_Array *t)
override;
142 bool preorder(
const IR::Type_Specialized *t)
override;
143 bool preorder(
const IR::Type_Enum *t)
override;
144 bool preorder(
const IR::Type_SerEnum *t)
override;
145 bool preorder(
const IR::Type_Typedef *t)
override;
146 bool preorder(
const IR::Type_Newtype *t)
override;
147 bool preorder(
const IR::Type_Extern *t)
override;
148 bool preorder(
const IR::Type_Unknown *t)
override;
149 bool preorder(
const IR::Type_BaseList *t)
override;
150 bool preorder(
const IR::Type *t)
override {
151 builder.append(t->toString());
154 bool preorder(
const IR::Type_SpecializedCanonical *t)
override {
155 BUG(
"%1%: specialized canonical type in IR tree", t);
160 bool preorder(
const IR::Declaration_Constant *cst)
override;
161 bool preorder(
const IR::Declaration_Variable *v)
override;
162 bool preorder(
const IR::Declaration_Instance *t)
override;
163 bool preorder(
const IR::Declaration_MatchKind *d)
override;
166 bool preorder(
const IR::Dots *e)
override;
167 bool preorder(
const IR::NamedDots *e)
override;
168 bool preorder(
const IR::Constant *c)
override;
169 bool preorder(
const IR::AbstractSlice *slice)
override;
170 bool preorder(
const IR::BoolLiteral *b)
override;
171 bool preorder(
const IR::StringLiteral *s)
override;
172 bool preorder(
const IR::PathExpression *p)
override;
173 bool preorder(
const IR::Cast *c)
override;
174 bool preorder(
const IR::Operation_Binary *b)
override;
175 bool preorder(
const IR::Operation_Unary *u)
override;
176 bool preorder(
const IR::ArrayIndex *a)
override;
177 bool preorder(
const IR::TypeNameExpression *e)
override;
178 bool preorder(
const IR::Mux *a)
override;
179 bool preorder(
const IR::ConstructorCallExpression *e)
override;
180 bool preorder(
const IR::Member *e)
override;
181 bool preorder(
const IR::SelectCase *e)
override;
182 bool preorder(
const IR::SelectExpression *e)
override;
183 bool preorder(
const IR::ListExpression *e)
override;
184 bool preorder(
const IR::P4ListExpression *e)
override;
185 bool preorder(
const IR::StructExpression *e)
override;
186 bool preorder(
const IR::Invalid *e)
override;
187 bool preorder(
const IR::InvalidHeader *e)
override;
188 bool preorder(
const IR::InvalidHeaderUnion *e)
override;
189 bool preorder(
const IR::ArrayExpression *e)
override;
190 bool preorder(
const IR::MethodCallExpression *e)
override;
191 bool preorder(
const IR::DefaultExpression *e)
override;
192 bool preorder(
const IR::This *e)
override;
195 bool preorder(
const IR::Vector<IR::ActionListElement> *v)
override;
196 bool preorder(
const IR::Vector<IR::Annotation> *v)
override;
197 bool preorder(
const IR::Vector<IR::Entry> *v)
override;
198 bool preorder(
const IR::Vector<IR::Expression> *v)
override;
199 bool preorder(
const IR::Vector<IR::Argument> *v)
override;
200 bool preorder(
const IR::Vector<IR::KeyElement> *v)
override;
201 bool preorder(
const IR::Vector<IR::Method> *v)
override;
202 bool preorder(
const IR::Vector<IR::Node> *v)
override;
203 bool preorder(
const IR::Vector<IR::SelectCase> *v)
override;
204 bool preorder(
const IR::Vector<IR::SwitchCase> *v)
override;
205 bool preorder(
const IR::Vector<IR::Type> *v)
override;
206 bool preorder(
const IR::IndexedVector<IR::Declaration_ID> *v)
override;
207 bool preorder(
const IR::IndexedVector<IR::Declaration> *v)
override;
208 bool preorder(
const IR::IndexedVector<IR::Node> *v)
override;
209 bool preorder(
const IR::IndexedVector<IR::ParserState> *v)
override;
210 bool preorder(
const IR::IndexedVector<IR::StatOrDecl> *v)
override;
213 bool preorder(
const IR::AssignmentStatement *s)
override;
214 bool preorder(
const IR::OpAssignmentStatement *s)
override;
215 bool preorder(
const IR::BlockStatement *s)
override;
216 bool preorder(
const IR::MethodCallStatement *s)
override;
217 bool preorder(
const IR::EmptyStatement *s)
override;
218 bool preorder(
const IR::ReturnStatement *s)
override;
219 bool preorder(
const IR::BreakStatement *s)
override;
220 bool preorder(
const IR::ContinueStatement *s)
override;
221 bool preorder(
const IR::ExitStatement *s)
override;
222 bool preorder(
const IR::SwitchCase *s)
override;
223 bool preorder(
const IR::SwitchStatement *s)
override;
224 bool preorder(
const IR::IfStatement *s)
override;
225 bool preorder(
const IR::ForStatement *s)
override;
226 bool preorder(
const IR::ForInStatement *s)
override;
229 bool preorder(
const IR::NamedExpression *ne)
override;
230 bool preorder(
const IR::Argument *arg)
override;
231 bool preorder(
const IR::Path *p)
override;
232 bool preorder(
const IR::Parameter *p)
override;
233 bool preorder(
const IR::Annotation *a)
override;
234 bool preorder(
const IR::P4Program *program)
override;
235 bool preorder(
const IR::P4Control *c)
override;
236 bool preorder(
const IR::P4Action *c)
override;
237 bool preorder(
const IR::ParserState *s)
override;
238 bool preorder(
const IR::P4Parser *c)
override;
239 bool preorder(
const IR::TypeParameters *p)
override;
240 bool preorder(
const IR::ParameterList *p)
override;
241 bool preorder(
const IR::Method *p)
override;
242 bool preorder(
const IR::Function *function)
override;
244 bool preorder(
const IR::ExpressionValue *v)
override;
245 bool preorder(
const IR::ActionListElement *ale)
override;
246 bool preorder(
const IR::ActionList *v)
override;
247 bool preorder(
const IR::Key *v)
override;
248 bool preorder(
const IR::Property *p)
override;
249 bool preorder(
const IR::TableProperties *t)
override;
250 bool preorder(
const IR::EntriesList *l)
override;
251 bool preorder(
const IR::Entry *e)
override;
252 bool preorder(
const IR::P4Table *c)
override;
253 bool preorder(
const IR::P4ValueSet *c)
override;
256 bool preorder(
const IR::V1Program *)
override {
return false; }