34 : parser_info(parser_info) {}
60 profile_t init_apply(
const IR::Node *root)
override {
61 parser_to_decl_names.clear();
62 parser_to_verifies.clear();
63 parser_to_residuals.clear();
64 parser_to_clots.clear();
65 decl_name_to_prims.clear();
66 decl_name_to_states.clear();
67 state_to_prims.clear();
68 prim_to_state.clear();
69 return Inspector::init_apply(root);
71 bool preorder(
const IR::BFN::Parser *parser)
override {
72 auto sorted_states = parser_info.graph(parser).topological_sort();
74 for (
auto state : sorted_states)
75 for (
auto stmt : state->statements)
76 if (
auto csum = stmt->to<IR::BFN::ParserChecksumPrimitive>())
77 visit(parser, state, csum);
82 void visit(
const IR::BFN::Parser *parser,
const IR::BFN::ParserState *state,
83 const IR::BFN::ParserChecksumPrimitive *csum) {
84 parser_to_decl_names[parser].insert(csum->declName);
85 prim_to_state[csum] = state;
86 state_to_prims[state].push_back(csum);
87 decl_name_to_states[parser][csum->declName].insert(state);
88 decl_name_to_prims[parser][csum->declName].push_back(csum);
91 bool is_verification(
const IR::BFN::Parser *parser,
cstring decl)
const {
92 for (
auto p : decl_name_to_prims.at(parser).at(decl)) {
93 if (!p->is<IR::BFN::ChecksumAdd>() && !p->is<IR::BFN::ChecksumVerify>())
return false;
98 bool is_residual(
const IR::BFN::Parser *parser,
cstring decl)
const {
99 for (
auto p : decl_name_to_prims.at(parser).at(decl)) {
100 if (!p->is<IR::BFN::ChecksumSubtract>() && !p->is<IR::BFN::ChecksumResidualDeposit>())
106 bool is_clot(
const IR::BFN::Parser *parser,
cstring decl)
const {
107 for (
auto p : decl_name_to_prims.at(parser).at(decl)) {
108 if (!p->is<IR::BFN::ChecksumAdd>() && !p->is<IR::BFN::ChecksumDepositToClot>())
114 IR::BFN::ChecksumMode get_type(
const IR::BFN::Parser *parser,
cstring name)
const {
115 if (is_verification(parser, name))
116 return IR::BFN::ChecksumMode::VERIFY;
117 else if (is_residual(parser, name))
118 return IR::BFN::ChecksumMode::RESIDUAL;
119 else if (is_clot(parser, name))
120 return IR::BFN::ChecksumMode::CLOT;
122 BUG(
"Unknown checksum type for %1%", name);
125 void end_apply()
override {
126 for (
auto &pd : parser_to_decl_names) {
127 for (
auto decl : pd.second) {
128 if (is_verification(pd.first, decl))
129 parser_to_verifies[pd.first].insert(decl);
130 else if (is_residual(pd.first, decl))
131 parser_to_residuals[pd.first].insert(decl);
132 else if (is_clot(pd.first, decl))
133 parser_to_clots[pd.first].insert(decl);
136 "Inconsistent use of checksum declaration %1% (it can be used either "
137 "to verify checksum or to calculate residual, but not for both)",
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:51