P4C
The P4 Compiler
Loading...
Searching...
No Matches
check_duplicate.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_MAU_CHECK_DUPLICATE_H_
20#define BACKENDS_TOFINO_BF_P4C_MAU_CHECK_DUPLICATE_H_
21
22#include "ir/dump.h"
23
24using namespace P4;
25
27 std::set<cstring> names;
28 profile_t init_apply(const IR::Node *root) override {
29 names.clear();
30 return MauInspector::init_apply(root);
31 }
32 bool preorder(const IR::MAU::Table *t) override {
33 auto name = t->name;
34 if (t->is_placed()) name = t->unique_id().build_name();
35 if (names.count(name)) BUG("Multiple tables named '%s'", name);
36 names.insert(name);
37 return true;
38 }
39};
40
42 std::map<cstring, const IR::MAU::AttachedMemory *> attached;
43
44 public:
45 const char *pass = "";
46 bool ok = true;
47 profile_t init_apply(const IR::Node *root) {
48 attached.clear();
49 return Inspector::init_apply(root);
50 }
51 bool preorder(const IR::MAU::AttachedMemory *at) {
52 if (attached.count(at->name)) {
53 LOG1("Duplicated attached table " << at->name << " after " << pass);
54 ok = false;
55 }
56 attached[at->name] = at;
57 return true;
58 }
59 void end_apply(const IR::Node *root) {
60 if (!ok && LOGGING(3)) {
61 std::cout << "---------- After " << pass << " ----------" << std::endl;
62 dump(root);
63 }
64 BUG_CHECK(ok, "abort after %s", pass);
65 }
66};
67
68#endif /* BACKENDS_TOFINO_BF_P4C_MAU_CHECK_DUPLICATE_H_ */
Definition check_duplicate.h:41
Definition check_duplicate.h:26
Definition mau_visitor.h:29
Definition node.h:95
Definition visitor.h:400
Definition visitor.h:78
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24