P4C
The P4 Compiler
Loading...
Searching...
No Matches
rewrite_flexible_header.h
1
24#ifndef BF_P4C_MIDEND_REWRITE_FLEXIBLE_HEADER_H_
25#define BF_P4C_MIDEND_REWRITE_FLEXIBLE_HEADER_H_
26
27#include "frontends/p4/typeMap.h"
28#include "ir/ir.h"
29
30namespace P4 {
31class TypeMap;
32class ReferenceMap;
33} // namespace P4
34
35namespace BFN {
36
40struct RewriteHeader : public Transform {
41 public:
42 RewriteHeader() {}
43 const IR::Node *postorder(IR::Type_Struct *st) override {
44 if (st->getAnnotation("flexible"_cs) == nullptr) return st;
45
47 for (auto f : st->fields) {
48 fields.push_back(new IR::StructField(
49 f->name, {new IR::Annotation(IR::ID("flexible"), {})}, f->type));
50 }
51
52 return new IR::Type_Struct(st->name, st->annotations, fields);
53 }
54};
55
62 public:
63 explicit RewriteFlexibleStruct(P4::ReferenceMap *refMap, P4::TypeMap *typeMap) {
64 addPasses({
65 new RewriteHeader(),
66 new P4::ClearTypeMap(typeMap),
67 new BFN::TypeChecking(refMap, typeMap, true),
68 });
69 }
70};
71
72} // namespace BFN
73
74#endif /* BF_P4C_MIDEND_REWRITE_FLEXIBLE_HEADER_H_ */
Definition typeChecker.h:32
Definition node.h:52
Definition node.h:94
Definition ir/pass_manager.h:40
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition visitor.h:424
Definition typeChecker.h:55
Definition typeMap.h:41
Top level PassManager that governs moving of flexible annotation from structure to its fields.
Definition rewrite_flexible_header.h:61
Definition rewrite_flexible_header.h:40
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24