P4C
The P4 Compiler
Loading...
Searching...
No Matches
ir_utils.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_COMMON_IR_UTILS_H_
20#define BACKENDS_TOFINO_BF_P4C_COMMON_IR_UTILS_H_
21
22#include "ir/ir.h"
23
24using namespace P4;
25
26IR::Member *gen_fieldref(const IR::HeaderOrMetadata *hdr, cstring field);
27
28const IR::HeaderOrMetadata *getMetadataType(const IR::BFN::Pipe *pipe, cstring typeName);
29
30bool isSigned(const IR::Type *);
31
32// probably belongs in ir/ir.h or ir/node.h...
33template <class T>
34inline T *clone_update(const T *&ptr) {
35 T *rv = ptr->clone();
36 ptr = rv;
37 return rv;
38}
39
40uint64_t bitMask(unsigned size);
41big_int bigBitMask(int size);
42
43// FIXME -- move to open source code (ir/pass_manager.h probably)
44template <class BT>
45class CatchBacktrack : public Backtrack {
46 std::function<void(BT *)> fn;
47 bool backtrack(trigger &trig) override {
48 if (auto t = dynamic_cast<BT *>(&trig)) {
49 fn(t);
50 return true;
51 } else {
52 return false;
53 }
54 }
55 // pass does nothing
56 const IR::Node *apply_visitor(const IR::Node *n, const char * = 0) override { return n; }
57
58 public:
59 explicit CatchBacktrack(std::function<void(BT *)> f) : fn(f) {}
60 explicit CatchBacktrack(std::function<void()> f) : fn([f](BT *) { f(); }) {}
61};
62
63#endif /* BACKENDS_TOFINO_BF_P4C_COMMON_IR_UTILS_H_ */
Definition ir_utils.h:45
Definition visitor.h:766
Definition node.h:94
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition visitor.h:768