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;
90 Util::SourceCodeBuilder &builder;
95 std::ostream *outStream =
nullptr;
102 visitDagOnce =
false;
107 this->outStream = outStream;
110 ToP4(Util::SourceCodeBuilder &builder,
bool showIR, std::filesystem::path
mainFile)
114 ToP4(std::ostream *outStream,
bool showIR, std::filesystem::path
mainFile)
115 : ToP4(outStream,
showIR) {
119 ToP4() : ToP4(*new Util::SourceCodeBuilder(), false) {}
121 using Inspector::preorder;
123 void setnoIncludesArg(
bool condition) {
noIncludes = condition; }
125 void setListTerm(
const char *start,
const char *end) {
126 listTerminators.push_back(ListPrint(start, end));
128 Visitor::profile_t init_apply(
const IR::Node *node)
override;
129 void end_apply(
const IR::Node *node)
override;
131 bool process(
const IR::Type_StructLike *t,
const char *name);
133 bool preorder(
const IR::Type_Boolean *t)
override;
134 bool preorder(
const IR::Type_Varbits *t)
override;
135 bool preorder(
const IR::Type_Bits *t)
override;
136 bool preorder(
const IR::Type_InfInt *t)
override;
137 bool preorder(
const IR::Type_String *t)
override;
138 bool preorder(
const IR::Type_Var *t)
override;
139 bool preorder(
const IR::Type_Dontcare *t)
override;
140 bool preorder(
const IR::Type_Void *t)
override;
141 bool preorder(
const IR::Type_Error *t)
override;
142 bool preorder(
const IR::Type_Struct *t)
override {
return process(t,
"struct"); }
143 bool preorder(
const IR::Type_Header *t)
override {
return process(t,
"header"); }
144 bool preorder(
const IR::Type_HeaderUnion *t)
override {
return process(t,
"header_union"); }
145 bool preorder(
const IR::Type_Package *t)
override;
146 bool preorder(
const IR::Type_Parser *t)
override;
147 bool preorder(
const IR::Type_Control *t)
override;
148 bool preorder(
const IR::Type_Name *t)
override;
149 bool preorder(
const IR::Type_Stack *t)
override;
150 bool preorder(
const IR::Type_Specialized *t)
override;
151 bool preorder(
const IR::Type_Enum *t)
override;
152 bool preorder(
const IR::Type_SerEnum *t)
override;
153 bool preorder(
const IR::Type_Typedef *t)
override;
154 bool preorder(
const IR::Type_Newtype *t)
override;
155 bool preorder(
const IR::Type_Extern *t)
override;
156 bool preorder(
const IR::Type_Unknown *t)
override;
157 bool preorder(
const IR::Type_BaseList *t)
override;
158 bool preorder(
const IR::Type *t)
override {
159 builder.append(t->toString());
162 bool preorder(
const IR::Type_SpecializedCanonical *t)
override {
163 BUG(
"%1%: specialized canonical type in IR tree", t);
168 bool preorder(
const IR::Declaration_Constant *cst)
override;
169 bool preorder(
const IR::Declaration_Variable *v)
override;
170 bool preorder(
const IR::Declaration_Instance *t)
override;
171 bool preorder(
const IR::Declaration_MatchKind *d)
override;
174 bool preorder(
const IR::Dots *e)
override;
175 bool preorder(
const IR::NamedDots *e)
override;
176 bool preorder(
const IR::Constant *c)
override;
177 bool preorder(
const IR::AbstractSlice *slice)
override;
178 bool preorder(
const IR::BoolLiteral *b)
override;
179 bool preorder(
const IR::StringLiteral *s)
override;
180 bool preorder(
const IR::PathExpression *p)
override;
181 bool preorder(
const IR::Cast *c)
override;
182 bool preorder(
const IR::Operation_Binary *b)
override;
183 bool preorder(
const IR::Operation_Unary *u)
override;
184 bool preorder(
const IR::ArrayIndex *a)
override;
185 bool preorder(
const IR::TypeNameExpression *e)
override;
186 bool preorder(
const IR::Mux *a)
override;
187 bool preorder(
const IR::ConstructorCallExpression *e)
override;
188 bool preorder(
const IR::Member *e)
override;
189 bool preorder(
const IR::SelectCase *e)
override;
190 bool preorder(
const IR::SelectExpression *e)
override;
191 bool preorder(
const IR::ListExpression *e)
override;
192 bool preorder(
const IR::P4ListExpression *e)
override;
193 bool preorder(
const IR::StructExpression *e)
override;
194 bool preorder(
const IR::Invalid *e)
override;
195 bool preorder(
const IR::InvalidHeader *e)
override;
196 bool preorder(
const IR::InvalidHeaderUnion *e)
override;
197 bool preorder(
const IR::HeaderStackExpression *e)
override;
198 bool preorder(
const IR::MethodCallExpression *e)
override;
199 bool preorder(
const IR::DefaultExpression *e)
override;
200 bool preorder(
const IR::This *e)
override;
203 bool preorder(
const IR::Vector<IR::ActionListElement> *v)
override;
204 bool preorder(
const IR::Vector<IR::Annotation> *v)
override;
205 bool preorder(
const IR::Vector<IR::Entry> *v)
override;
206 bool preorder(
const IR::Vector<IR::Expression> *v)
override;
207 bool preorder(
const IR::Vector<IR::Argument> *v)
override;
208 bool preorder(
const IR::Vector<IR::KeyElement> *v)
override;
209 bool preorder(
const IR::Vector<IR::Method> *v)
override;
210 bool preorder(
const IR::Vector<IR::Node> *v)
override;
211 bool preorder(
const IR::Vector<IR::SelectCase> *v)
override;
212 bool preorder(
const IR::Vector<IR::SwitchCase> *v)
override;
213 bool preorder(
const IR::Vector<IR::Type> *v)
override;
214 bool preorder(
const IR::IndexedVector<IR::Declaration_ID> *v)
override;
215 bool preorder(
const IR::IndexedVector<IR::Declaration> *v)
override;
216 bool preorder(
const IR::IndexedVector<IR::Node> *v)
override;
217 bool preorder(
const IR::IndexedVector<IR::ParserState> *v)
override;
218 bool preorder(
const IR::IndexedVector<IR::StatOrDecl> *v)
override;
221 bool preorder(
const IR::AssignmentStatement *s)
override;
222 bool preorder(
const IR::BlockStatement *s)
override;
223 bool preorder(
const IR::MethodCallStatement *s)
override;
224 bool preorder(
const IR::EmptyStatement *s)
override;
225 bool preorder(
const IR::ReturnStatement *s)
override;
226 bool preorder(
const IR::BreakStatement *s)
override;
227 bool preorder(
const IR::ContinueStatement *s)
override;
228 bool preorder(
const IR::ExitStatement *s)
override;
229 bool preorder(
const IR::SwitchCase *s)
override;
230 bool preorder(
const IR::SwitchStatement *s)
override;
231 bool preorder(
const IR::IfStatement *s)
override;
232 bool preorder(
const IR::ForStatement *s)
override;
233 bool preorder(
const IR::ForInStatement *s)
override;
236 bool preorder(
const IR::NamedExpression *ne)
override;
237 bool preorder(
const IR::Argument *arg)
override;
238 bool preorder(
const IR::Path *p)
override;
239 bool preorder(
const IR::Parameter *p)
override;
240 bool preorder(
const IR::Annotations *a)
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