P4C
The P4 Compiler
Loading...
Searching...
No Matches
parser_header_sequences.h
1
19#ifndef BF_P4C_PARDE_PARSER_HEADER_SEQUENCES_H_
20#define BF_P4C_PARDE_PARSER_HEADER_SEQUENCES_H_
21
22#include "bf-p4c/ir/control_flow_visitor.h"
23#include "bf-p4c/ir/gress.h"
24#include "bf-p4c/parde/parde_visitor.h"
25#include "bf-p4c/phv/phv_fields.h"
26#include "ir/ir.h"
27#include "ir/visitor.h"
28
29namespace {
30
31static constexpr unsigned int numHeaderIDs = 255;
32static constexpr unsigned int numHeadersPerSeq = 16;
33static constexpr unsigned int payloadHeaderID = 254;
34static cstring payloadHeaderStateName = "$final"_cs;
35static cstring payloadHeaderName = "payload"_cs;
36
37} // namespace
38
43 protected:
44 PhvInfo &phv;
45
49 void record_header(gress_t gress, cstring header, size_t size);
50
51 public:
53 std::map<gress_t, ordered_set<cstring>> headers;
54 std::map<std::pair<gress_t, cstring>, int> header_ids;
55
57 std::map<gress_t, std::vector<ordered_set<cstring>>> sequences;
58 // Name to size in bits of headers extracted in the ingress.
59 std::map<cstring, size_t> header_sizes;
60
61 explicit ParserHeaderSequences(PhvInfo &phv) : phv(phv) {}
62
63 Visitor::profile_t init_apply(const IR::Node *node) override;
64 bool preorder(const IR::BFN::Parser *) override;
65 bool preorder(const IR::BFN::Extract *) override;
66
67 void flow_merge(Visitor &) override;
68 void flow_copy(::ControlFlowVisitor &) override;
69
70 void end_apply() override;
71
72 ParserHeaderSequences *clone() const override { return new ParserHeaderSequences(*this); }
73};
74
75#endif /* BF_P4C_PARDE_PARSER_HEADER_SEQUENCES_H_ */
Definition visitor.h:463
Definition visitor.h:75
Definition cstring.h:85
Identify parsed header sequences.
Definition parser_header_sequences.h:42
void record_header(gress_t gress, cstring header, size_t size)
Record that header was parsed in gress.
Definition parser_header_sequences.cpp:62
void flow_merge(Visitor &) override
Definition parser_header_sequences.cpp:35
Visitor::profile_t init_apply(const IR::Node *node) override
Definition parser_header_sequences.cpp:21
std::map< gress_t, std::vector< ordered_set< cstring > > > sequences
Definition parser_header_sequences.h:57
bool preorder(const IR::BFN::Parser *) override
Create an empty set of sequences for each parser.
Definition parser_header_sequences.cpp:57
std::map< gress_t, ordered_set< cstring > > headers
Definition parser_header_sequences.h:53
Definition phv_fields.h:1095
Definition parde_visitor.h:27