P4C
The P4 Compiler
Loading...
Searching...
No Matches
dump.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
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
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed 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 and
14limitations under the License.
15*/
16
17#ifndef IR_DUMP_H_
18#define IR_DUMP_H_
19
20#include <cstdint>
21#include <iostream>
22#include <string>
23
24#include "ir/node.h"
25#include "ir/visitor.h"
26
27namespace P4 {
28
29/* overloads rather than optional arguments to make it easier to call from the debugger */
30void dump(std::ostream &out, const IR::Node *n);
31void dump(std::ostream &out, const IR::Node *n, unsigned maxdepth);
32void dump(const IR::Node *n);
33void dump(const IR::Node *n, unsigned maxdepth);
34void dump(const IR::INode *n);
35void dump(const IR::INode *n, unsigned maxdepth);
36void dump(uintptr_t p);
37void dump(uintptr_t p, unsigned maxdepth);
38void dump_notype(const IR::Node *n);
39void dump_notype(const IR::Node *n, unsigned maxdepth);
40void dump_notype(const IR::INode *n);
41void dump_notype(const IR::INode *n, unsigned maxdepth);
42void dump_notype(uintptr_t p);
43void dump_notype(uintptr_t p, unsigned maxdepth);
44void dump_src(const IR::Node *n);
45void dump_src(const IR::Node *n, unsigned maxdepth);
46void dump_src(const IR::INode *n);
47void dump_src(const IR::INode *n, unsigned maxdepth);
48void dump(std::ostream &, const Visitor::Context *);
49void dump(const Visitor::Context *);
50
51std::string dumpToString(const IR::Node *n);
52
53class Dump {
54 const IR::Node *n = nullptr;
55 const Visitor::Context *ctxt = nullptr;
56 unsigned maxdepth;
57 friend std::ostream &operator<<(std::ostream &, const Dump &);
58
59 public:
60 explicit Dump(const IR::Node *n, unsigned maxdepth = ~0U) : n(n), maxdepth(maxdepth) {}
61 explicit Dump(const Visitor::Context *ctxt) : ctxt(ctxt) {}
62};
63
64inline std::ostream &operator<<(std::ostream &out, const Dump &d) {
65 if (d.n)
66 dump(out, d.n, d.maxdepth);
67 else
68 dump(out, d.ctxt);
69 return out;
70}
71
72} // namespace P4
73
74#endif /* IR_DUMP_H_ */
Definition dump.h:53
Definition node.h:95
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition visitor.h:47