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