40 bool isDeclaration =
true;
50 VecPrint(
const char *sep,
const char *term) : separator(sep), terminator(term) {}
57 ListPrint(
const char *start,
const char *end) : start(start), end(end) {}
61 std::vector<VecPrint> vectorSeparator;
62 size_t vectorSeparator_init_apply_size = 0;
63 std::vector<ListPrint> listTerminators;
64 size_t listTerminators_init_apply_size = 0;
66 void setVecSep(
const char *sep,
const char *term =
nullptr) {
67 vectorSeparator.push_back(
VecPrint(sep, term));
70 BUG_CHECK(!vectorSeparator.empty(),
"Empty vectorSeparator");
71 vectorSeparator.pop_back();
74 BUG_CHECK(!vectorSeparator.empty(),
"Empty vectorSeparator");
75 return vectorSeparator.back();
79 BUG_CHECK(!listTerminators.empty(),
"Empty listTerminators");
80 listTerminators.pop_back();
83 std::optional<cstring>
ifSystemFile(
const IR::Node *node);
85 void dump(
unsigned depth,
const IR::Node *node =
nullptr,
unsigned adjDepth = 0);
86 unsigned curDepth()
const;
87 bool printAnnotations(
const IR::IAnnotated *ann);
91 Util::SourceCodeBuilder &builder;
96 std::ostream *outStream =
nullptr;
103 visitDagOnce =
false;
108 this->outStream = outStream;
111 ToP4(Util::SourceCodeBuilder &builder,
bool showIR, std::filesystem::path
mainFile)
115 ToP4(std::ostream *outStream,
bool showIR, std::filesystem::path
mainFile)
116 : ToP4(outStream,
showIR) {
120 ToP4() : ToP4(*new Util::SourceCodeBuilder(), false) {}
122 using Inspector::preorder;
124 void setnoIncludesArg(
bool condition) {
noIncludes = condition; }
126 void setListTerm(
const char *start,
const char *end) {
127 listTerminators.push_back(ListPrint(start, end));
129 Visitor::profile_t init_apply(
const IR::Node *node)
override;
130 void end_apply(
const IR::Node *node)
override;
132 bool process(
const IR::Type_StructLike *t,
const char *name);
134 bool preorder(
const IR::Type_Boolean *t)
override;
135 bool preorder(
const IR::Type_Varbits *t)
override;
136 bool preorder(
const IR::Type_Bits *t)
override;
137 bool preorder(
const IR::Type_InfInt *t)
override;
138 bool preorder(
const IR::Type_String *t)
override;
139 bool preorder(
const IR::Type_Var *t)
override;
140 bool preorder(
const IR::Type_Dontcare *t)
override;
141 bool preorder(
const IR::Type_Void *t)
override;
142 bool preorder(
const IR::Type_Error *t)
override;
143 bool preorder(
const IR::Type_Struct *t)
override {
return process(t,
"struct"); }
144 bool preorder(
const IR::Type_Header *t)
override {
return process(t,
"header"); }
145 bool preorder(
const IR::Type_HeaderUnion *t)
override {
return process(t,
"header_union"); }
146 bool preorder(
const IR::Type_Package *t)
override;
147 bool preorder(
const IR::Type_Parser *t)
override;
148 bool preorder(
const IR::Type_Control *t)
override;
149 bool preorder(
const IR::Type_Name *t)
override;
150 bool preorder(
const IR::Type_Stack *t)
override;
151 bool preorder(
const IR::Type_Specialized *t)
override;
152 bool preorder(
const IR::Type_Enum *t)
override;
153 bool preorder(
const IR::Type_SerEnum *t)
override;
154 bool preorder(
const IR::Type_Typedef *t)
override;
155 bool preorder(
const IR::Type_Newtype *t)
override;
156 bool preorder(
const IR::Type_Extern *t)
override;
157 bool preorder(
const IR::Type_Unknown *t)
override;
158 bool preorder(
const IR::Type_BaseList *t)
override;
159 bool preorder(
const IR::Type *t)
override {
160 builder.append(t->toString());
163 bool preorder(
const IR::Type_SpecializedCanonical *t)
override {
164 BUG(
"%1%: specialized canonical type in IR tree", t);
169 bool preorder(
const IR::Declaration_Constant *cst)
override;
170 bool preorder(
const IR::Declaration_Variable *v)
override;
171 bool preorder(
const IR::Declaration_Instance *t)
override;
172 bool preorder(
const IR::Declaration_MatchKind *d)
override;
175 bool preorder(
const IR::Dots *e)
override;
176 bool preorder(
const IR::NamedDots *e)
override;
177 bool preorder(
const IR::Constant *c)
override;
178 bool preorder(
const IR::AbstractSlice *slice)
override;
179 bool preorder(
const IR::BoolLiteral *b)
override;
180 bool preorder(
const IR::StringLiteral *s)
override;
181 bool preorder(
const IR::PathExpression *p)
override;
182 bool preorder(
const IR::Cast *c)
override;
183 bool preorder(
const IR::Operation_Binary *b)
override;
184 bool preorder(
const IR::Operation_Unary *u)
override;
185 bool preorder(
const IR::ArrayIndex *a)
override;
186 bool preorder(
const IR::TypeNameExpression *e)
override;
187 bool preorder(
const IR::Mux *a)
override;
188 bool preorder(
const IR::ConstructorCallExpression *e)
override;
189 bool preorder(
const IR::Member *e)
override;
190 bool preorder(
const IR::SelectCase *e)
override;
191 bool preorder(
const IR::SelectExpression *e)
override;
192 bool preorder(
const IR::ListExpression *e)
override;
193 bool preorder(
const IR::P4ListExpression *e)
override;
194 bool preorder(
const IR::StructExpression *e)
override;
195 bool preorder(
const IR::Invalid *e)
override;
196 bool preorder(
const IR::InvalidHeader *e)
override;
197 bool preorder(
const IR::InvalidHeaderUnion *e)
override;
198 bool preorder(
const IR::HeaderStackExpression *e)
override;
199 bool preorder(
const IR::MethodCallExpression *e)
override;
200 bool preorder(
const IR::DefaultExpression *e)
override;
201 bool preorder(
const IR::This *e)
override;
204 bool preorder(
const IR::Vector<IR::ActionListElement> *v)
override;
205 bool preorder(
const IR::Vector<IR::Annotation> *v)
override;
206 bool preorder(
const IR::Vector<IR::Entry> *v)
override;
207 bool preorder(
const IR::Vector<IR::Expression> *v)
override;
208 bool preorder(
const IR::Vector<IR::Argument> *v)
override;
209 bool preorder(
const IR::Vector<IR::KeyElement> *v)
override;
210 bool preorder(
const IR::Vector<IR::Method> *v)
override;
211 bool preorder(
const IR::Vector<IR::Node> *v)
override;
212 bool preorder(
const IR::Vector<IR::SelectCase> *v)
override;
213 bool preorder(
const IR::Vector<IR::SwitchCase> *v)
override;
214 bool preorder(
const IR::Vector<IR::Type> *v)
override;
215 bool preorder(
const IR::IndexedVector<IR::Declaration_ID> *v)
override;
216 bool preorder(
const IR::IndexedVector<IR::Declaration> *v)
override;
217 bool preorder(
const IR::IndexedVector<IR::Node> *v)
override;
218 bool preorder(
const IR::IndexedVector<IR::ParserState> *v)
override;
219 bool preorder(
const IR::IndexedVector<IR::StatOrDecl> *v)
override;
222 bool preorder(
const IR::AssignmentStatement *s)
override;
223 bool preorder(
const IR::BlockStatement *s)
override;
224 bool preorder(
const IR::MethodCallStatement *s)
override;
225 bool preorder(
const IR::EmptyStatement *s)
override;
226 bool preorder(
const IR::ReturnStatement *s)
override;
227 bool preorder(
const IR::BreakStatement *s)
override;
228 bool preorder(
const IR::ContinueStatement *s)
override;
229 bool preorder(
const IR::ExitStatement *s)
override;
230 bool preorder(
const IR::SwitchCase *s)
override;
231 bool preorder(
const IR::SwitchStatement *s)
override;
232 bool preorder(
const IR::IfStatement *s)
override;
233 bool preorder(
const IR::ForStatement *s)
override;
234 bool preorder(
const IR::ForInStatement *s)
override;
237 bool preorder(
const IR::NamedExpression *ne)
override;
238 bool preorder(
const IR::Argument *arg)
override;
239 bool preorder(
const IR::Path *p)
override;
240 bool preorder(
const IR::Parameter *p)
override;
241 bool preorder(
const IR::Annotation *a)
override;
242 bool preorder(
const IR::P4Program *program)
override;
243 bool preorder(
const IR::P4Control *c)
override;
244 bool preorder(
const IR::P4Action *c)
override;
245 bool preorder(
const IR::ParserState *s)
override;
246 bool preorder(
const IR::P4Parser *c)
override;
247 bool preorder(
const IR::TypeParameters *p)
override;
248 bool preorder(
const IR::ParameterList *p)
override;
249 bool preorder(
const IR::Method *p)
override;
250 bool preorder(
const IR::Function *function)
override;
252 bool preorder(
const IR::ExpressionValue *v)
override;
253 bool preorder(
const IR::ActionListElement *ale)
override;
254 bool preorder(
const IR::ActionList *v)
override;
255 bool preorder(
const IR::Key *v)
override;
256 bool preorder(
const IR::Property *p)
override;
257 bool preorder(
const IR::TableProperties *t)
override;
258 bool preorder(
const IR::EntriesList *l)
override;
259 bool preorder(
const IR::Entry *e)
override;
260 bool preorder(
const IR::P4Table *c)
override;
261 bool preorder(
const IR::P4ValueSet *c)
override;
264 bool preorder(
const IR::V1Program *)
override {
return false; }
Visitor mixin for looking up names in enclosing scopes from the Visitor::Context.
Definition resolveReferences.h:35