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 auto *fieldAnnotations = new IR::Annotations();
49 fieldAnnotations->annotations.push_back(new IR::Annotation(IR::ID("flexible"), {}));
50 fields.push_back(new IR::StructField(f->name, fieldAnnotations, f->type));
51 }
52
53 return new IR::Type_Struct(st->name, st->annotations, fields);
54 }
55};
56
63 public:
64 explicit RewriteFlexibleStruct(P4::ReferenceMap *refMap, P4::TypeMap *typeMap) {
65 addPasses({
66 new RewriteHeader(),
67 new P4::ClearTypeMap(typeMap),
68 new BFN::TypeChecking(refMap, typeMap, true),
69 });
70 }
71};
72
73} // namespace BFN
74
75#endif /* BF_P4C_MIDEND_REWRITE_FLEXIBLE_HEADER_H_ */
Definition typeChecker.h:32
Definition node.h:52
Definition node.h:95
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:62
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
Definition id.h:28