P4C
The P4 Compiler
Loading...
Searching...
No Matches
dump.h
1/*
2 * SPDX-FileCopyrightText: 2013 Barefoot Networks, Inc.
3 * Copyright 2013-present Barefoot Networks, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef IR_DUMP_H_
9#define IR_DUMP_H_
10
11#include <cstdint>
12#include <iostream>
13#include <string>
14
15#include "ir/node.h"
16#include "ir/visitor.h"
17
18namespace P4 {
19
20/* overloads rather than optional arguments to make it easier to call from the debugger */
21void dump(std::ostream &out, const IR::Node *n);
22void dump(std::ostream &out, const IR::Node *n, unsigned maxdepth);
23void dump(const IR::Node *n);
24void dump(const IR::Node *n, unsigned maxdepth);
25void dump(const IR::INode *n);
26void dump(const IR::INode *n, unsigned maxdepth);
27void dump(uintptr_t p);
28void dump(uintptr_t p, unsigned maxdepth);
29void dump_notype(const IR::Node *n);
30void dump_notype(const IR::Node *n, unsigned maxdepth);
31void dump_notype(const IR::INode *n);
32void dump_notype(const IR::INode *n, unsigned maxdepth);
33void dump_notype(uintptr_t p);
34void dump_notype(uintptr_t p, unsigned maxdepth);
35void dump_src(const IR::Node *n);
36void dump_src(const IR::Node *n, unsigned maxdepth);
37void dump_src(const IR::INode *n);
38void dump_src(const IR::INode *n, unsigned maxdepth);
39void dump(std::ostream &, const Visitor::Context *);
40void dump(const Visitor::Context *);
41
42std::string dumpToString(const IR::Node *n);
43
44class Dump {
45 const IR::Node *n = nullptr;
46 const Visitor::Context *ctxt = nullptr;
47 unsigned maxdepth;
48 friend std::ostream &operator<<(std::ostream &, const Dump &);
49
50 public:
51 explicit Dump(const IR::Node *n, unsigned maxdepth = ~0U) : n(n), maxdepth(maxdepth) {}
52 explicit Dump(const Visitor::Context *ctxt) : ctxt(ctxt) {}
53};
54
55inline std::ostream &operator<<(std::ostream &out, const Dump &d) {
56 if (d.n)
57 dump(out, d.n, d.maxdepth);
58 else
59 dump(out, d.ctxt);
60 return out;
61}
62
63struct DumpPipe : public Inspector {
64 const char *heading;
65 DumpPipe() : heading(nullptr) {}
66 explicit DumpPipe(const char *h) : heading(h) {}
67 bool preorder(const IR::Node *pipe) override;
68};
69
70} // namespace P4
71
72#endif /* IR_DUMP_H_ */
Definition dump.h:44
Definition inode.h:42
Definition node.h:44
Definition visitor.h:409
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13