P4C
The P4 Compiler
Loading...
Searching...
No Matches
dbprint.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_DBPRINT_H_
18#define IR_DBPRINT_H_
19
20#include <cassert>
21#include <iosfwd>
22
23#include "lib/log.h"
24
25namespace P4::DBPrint {
26
27// Support for debug print, needed by the LOG* macros.
28// TODO: These should be part of a def file
29enum dbprint_flags {
30 Precedence = 0xf,
31 Prec_Postfix = 15,
32 Prec_Prefix = 14,
33 Prec_Mul = 13,
34 Prec_Div = 13,
35 Prec_Mod = 13,
36 Prec_Add = 12,
37 Prec_Sub = 12,
38 Prec_AddSat = 12,
39 Prec_SubSat = 12,
40 Prec_Shl = 11,
41 Prec_Shr = 11,
42 Prec_BAnd = 10,
43 Prec_BXor = 9,
44 Prec_BOr = 8,
45 Prec_Lss = 7,
46 Prec_Leq = 7,
47 Prec_Grt = 7,
48 Prec_Geq = 7,
49 Prec_Equ = 6,
50 Prec_Neq = 6,
51 Prec_LAnd = 5,
52 Prec_LOr = 4,
53 Prec_Cond = 3,
54 Prec_Low = 1,
55
56 Reset = 0,
57 TableNoActions = 0x10,
58 Brief = 0x20,
59};
60
61int dbgetflags(std::ostream &out);
62int dbsetflags(std::ostream &out, int val, int mask = ~0U);
63
64inline int getprec(std::ostream &out) { return dbgetflags(out) & DBPrint::Precedence; }
66 int val, mask;
67
68 protected:
69 setflags_helper(int v, int m) : val(v), mask(m) { assert((val & ~mask) == 0); }
70
71 public:
72 setflags_helper() = delete;
73
74 void set(std::ostream &out) const { dbsetflags(out, val, mask); }
75};
76struct setprec : public setflags_helper {
77 explicit setprec(int prec) : setflags_helper(prec, DBPrint::Precedence) {}
78};
79struct setflag : public setflags_helper {
80 explicit setflag(int fl) : setflags_helper(fl, fl) {}
81};
82struct clrflag : public setflags_helper {
83 explicit clrflag(int fl) : setflags_helper(0, fl) {}
84};
85
86inline std::ostream &operator<<(std::ostream &out, const DBPrint::setflags_helper &p) {
87 p.set(out);
88 return out;
89}
90
91inline std::ostream &operator<<(std::ostream &out, const DBPrint::dbprint_flags fl) {
92 DBPrint::dbsetflags(out, fl, fl ? fl : ~0);
93 return out;
94}
95
96} // end namespace P4::DBPrint
97
98#endif /* IR_DBPRINT_H_ */
Definition dbprint.h:65
Definition dbprint.h:82
Definition dbprint.h:79
Definition dbprint.h:76