P4C
The P4 Compiler
Loading...
Searching...
No Matches
parse_annotations.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_COMMON_PARSE_ANNOTATIONS_H_
20#define BACKENDS_TOFINO_BF_P4C_COMMON_PARSE_ANNOTATIONS_H_
21
22#include "backends/tofino/bf-p4c/common/pragma/all_pragmas.h"
23#include "frontends/p4/parseAnnotations.h"
24#include "ir/ir.h"
25
26namespace BFN {
27
28// wrapper for PARSE, PARSE_PAIR, and PARSE_TRIPLE
29#define BFN_PARSE(pragmaClass, parse, tname, internal) \
30 { \
31 auto p = new Pragma(pragmaClass::name, pragmaClass::description, pragmaClass::help); \
32 std::pair<std::string, P4::ParseAnnotations::Handler> h = parse(pragmaClass::name, tname); \
33 addHandler(h.first, h.second); \
34 Pragma::registerPragma(p, internal); \
35 }
36
37// wrapper for PARSE_EMPTY, PARSE_CONSTANT_OR_STRING_LITERAL, PARSE_EXPRESSION_LIST,
38// PARSE_CONSTANT_LIST, PARSE_CONSTANT_OR_STRING_LITERAL_LIST, PARSE_STRING_LITERAL_LIST and
39// PARSE_SKIP
40#define BFN_PARSE_EMPTY(pragmaClass, parse, internal) \
41 { \
42 auto p = new Pragma(pragmaClass::name, pragmaClass::description, pragmaClass::help); \
43 std::pair<std::string, P4::ParseAnnotations::Handler> h = parse(pragmaClass::name); \
44 addHandler(h.first, h.second); \
45 Pragma::registerPragma(p, internal); \
46 }
47
50 public:
52 : P4::ParseAnnotations("BFN", true,
53 {
54 // Ignore p4v annotations.
55 PARSE_SKIP("assert"_cs),
56 PARSE_SKIP("assume"_cs),
57
58 // Ignore p4runtime annotations
59 PARSE_SKIP("brief"_cs),
60 PARSE_SKIP("description"_cs),
61
62 // Ignore unused annotations appearing in headers for v1model.
63 PARSE_SKIP("metadata"_cs),
64 PARSE_SKIP("alias"_cs),
65 PARSE_SKIP("pipeline"_cs),
66 PARSE_SKIP("deparser"_cs),
67 },
68 true) {
69 constexpr bool extPragma = false; // externally supported
70 constexpr bool intPragma = true; // Barefoot internal
71 BFN_PARSE(PragmaAdjustByteCount, PARSE, Expression, intPragma);
72 BFN_PARSE(PragmaAlpm, PARSE, Expression, extPragma);
73 BFN_PARSE(PragmaAlpmPartitions, PARSE, Expression, extPragma);
74 BFN_PARSE(PragmaAlpmSubtreePartitions, PARSE, Expression, extPragma);
75 BFN_PARSE(PragmaAtcamPartitions, PARSE, Expression, extPragma);
76 BFN_PARSE(PragmaAtcamPartitionIndex, PARSE, StringLiteral, extPragma);
77 BFN_PARSE_EMPTY(PragmaAlpmAtcamExcludeFieldMsbs, PARSE_EXPRESSION_LIST, extPragma);
78 BFN_PARSE(PragmaCalculatedFieldUpdateLocation, PARSE, StringLiteral, extPragma);
79 BFN_PARSE_EMPTY(PragmaBackwardCompatible, PARSE_EMPTY, extPragma);
80 BFN_PARSE_EMPTY(PragmaChainAddress, PARSE_EMPTY, intPragma);
81 BFN_PARSE(PragmaChainTotalSize, PARSE, Expression, intPragma);
82 BFN_PARSE_EMPTY(PragmaCommandLine, PARSE_CONSTANT_OR_STRING_LITERAL_LIST, extPragma);
83 BFN_PARSE_EMPTY(PragmaCritical, PARSE_EMPTY, extPragma);
84 BFN_PARSE_EMPTY(PragmaDefaultPortmap, PARSE_EXPRESSION_LIST, intPragma);
85 BFN_PARSE(PragmaDisableAtomicModify, PARSE, Expression, extPragma);
86 BFN_PARSE_EMPTY(PragmaDisableI2EReservedDropImplementation, PARSE_EMPTY, extPragma);
87 BFN_PARSE_EMPTY(PragmaDisableEgressMirrorIOSelectInitialization, PARSE_EMPTY, extPragma);
88 BFN_PARSE(PragmaDoNotBridge, PARSE_PAIR, StringLiteral, extPragma);
89 BFN_PARSE_EMPTY(PragmaDoNotUseClot, PARSE_STRING_LITERAL_LIST, extPragma);
90 BFN_PARSE(PragmaDontTranslateExternMethod, PARSE, StringLiteral, intPragma);
91 BFN_PARSE(PragmaDontMerge, PARSE, Expression, extPragma);
92 BFN_PARSE_EMPTY(PragmaDontUnroll, PARSE_EMPTY, extPragma);
93 BFN_PARSE(PragmaDynamicTableKeyMasks, PARSE, Expression, extPragma);
94 BFN_PARSE_EMPTY(PragmaEgressIntrinsicMetadataOpt, PARSE_EMPTY, extPragma);
95 BFN_PARSE(PragmaEntriesWithRanges, PARSE, Expression, extPragma);
96 BFN_PARSE(PragmaFieldListFieldSlice, PARSE_TRIPLE, Expression, extPragma);
97 BFN_PARSE_EMPTY(PragmaFlexible, PARSE_EMPTY, extPragma);
98 BFN_PARSE(PragmaForceImmediate, PARSE, Expression, extPragma);
99 BFN_PARSE(PragmaForceShift, PARSE_PAIR, Expression, extPragma);
100 BFN_PARSE_EMPTY(PragmaGFMParityEnable, PARSE_EMPTY, extPragma);
101 BFN_PARSE_EMPTY(PragmaGhostMetadata, PARSE_EMPTY, intPragma);
102 BFN_PARSE(PragmaIdletimeInterval, PARSE, Expression, extPragma);
103 BFN_PARSE(PragmaIdletimePerFlow, PARSE, Expression, extPragma);
104 BFN_PARSE(PragmaIdletimePrecision, PARSE, Expression, extPragma);
105 BFN_PARSE(PragmaIdletimeTwoWayNotification, PARSE, Expression, extPragma);
106 BFN_PARSE(PragmaIgnoreTableDependency, PARSE, StringLiteral, extPragma);
107 BFN_PARSE(PragmaImmediate, PARSE, Expression, extPragma);
108 BFN_PARSE(PragmaIxbarGroupNum, PARSE, Expression, extPragma);
109 BFN_PARSE_EMPTY(PragmaIRContextBasedDebugLogging, PARSE_EMPTY, intPragma);
110 BFN_PARSE_EMPTY(PragmaInHash, PARSE_EMPTY, intPragma);
111 BFN_PARSE_EMPTY(PragmaIntrinsicMetadata, PARSE_EMPTY, intPragma);
112 BFN_PARSE(PragmaLrtEnable, PARSE, Expression, extPragma);
113 BFN_PARSE(PragmaLrtScale, PARSE, Expression, intPragma);
114 BFN_PARSE(PragmaMaxActions, PARSE, Expression, extPragma);
115 BFN_PARSE(PragmaMaxLoopDepth, PARSE, Expression, extPragma);
116 BFN_PARSE(PragmaMinWidth, PARSE, Expression, extPragma);
117 BFN_PARSE(PragmaMode, PARSE, StringLiteral, intPragma);
118 BFN_PARSE_EMPTY(PragmaNoFieldInits, PARSE_EMPTY, extPragma);
119 BFN_PARSE_EMPTY(PragmaNoGatewayConversion, PARSE_EMPTY, extPragma);
120 BFN_PARSE_EMPTY(PragmaNotExtractedInEgress, PARSE_EMPTY, intPragma);
121 BFN_PARSE(PragmaOverridePhase0ActionName, PARSE, StringLiteral, extPragma);
122 BFN_PARSE(PragmaOverridePhase0TableName, PARSE, StringLiteral, extPragma);
123 BFN_PARSE(PragmaPack, PARSE, Expression, extPragma);
124 BFN_PARSE_EMPTY(PragmaPadding, PARSE_EMPTY, extPragma);
125 BFN_PARSE_EMPTY(PragmaPacketEntry, PARSE_EMPTY, extPragma);
126 BFN_PARSE(PragmaPhase0, PARSE_TRIPLE, Expression, extPragma);
127 BFN_PARSE_EMPTY(PragmaPlacementPriority, PARSE_EXPRESSION_LIST, extPragma);
128 BFN_PARSE(PragmaPreColor, PARSE, Expression, intPragma);
129 BFN_PARSE(PragmaProxyHashAlgorithm, PARSE, StringLiteral, extPragma);
130 BFN_PARSE(PragmaProxyHashWidth, PARSE, Expression, extPragma);
131 BFN_PARSE_EMPTY(PragmaPhvLimit, PARSE_SKIP, intPragma);
132 BFN_PARSE(PragmaRandomSeed, PARSE, Expression, intPragma);
133 BFN_PARSE(PragmaReductionOrGroup, PARSE, StringLiteral, intPragma);
134 BFN_PARSE(PragmaReg, PARSE, StringLiteral, intPragma);
135 BFN_PARSE(PragmaResidualChecksumParserUpdateLocation, PARSE, StringLiteral, intPragma);
136 BFN_PARSE(PragmaSelectorMaxGroupSize, PARSE, Expression, extPragma);
137 BFN_PARSE(PragmaSelectorNumMaxGroups, PARSE, Expression, extPragma);
138 BFN_PARSE(PragmaSelectorEnableScramble, PARSE, Expression, extPragma);
139 BFN_PARSE_EMPTY(PragmaSeparateGateway, PARSE_EMPTY, extPragma);
140 BFN_PARSE_EMPTY(PragmaStage, PARSE_EXPRESSION_LIST, extPragma);
141 BFN_PARSE(PragmaSymmetric, PARSE_PAIR, Expression, extPragma);
142 BFN_PARSE(PragmaTerminateParsing, PARSE, StringLiteral, extPragma);
143 BFN_PARSE(PragmaTernary, PARSE, Expression, intPragma); // unlikely to need it
144 BFN_PARSE(PragmaUseHashAction, PARSE, Expression, extPragma);
145 BFN_PARSE_EMPTY(PragmaUserAnnotation, PARSE_STRING_LITERAL_LIST, extPragma);
146 BFN_PARSE(PragmaWays, PARSE, Expression, extPragma);
147 BFN_PARSE(PragmaHashMask, PARSE, Expression, intPragma);
148
149 // Meter pragmas
150 BFN_PARSE(PragmaRed, PARSE, Expression, intPragma);
151 BFN_PARSE(PragmaYellow, PARSE, Expression, intPragma);
152 BFN_PARSE(PragmaGreen, PARSE, Expression, intPragma);
153 BFN_PARSE(PragmaMeterProfile, PARSE, Expression, extPragma);
154 BFN_PARSE_EMPTY(PragmaTrueEgressAccounting, PARSE_EMPTY, extPragma);
155
156 BFN_PARSE_EMPTY(PragmaHeaderChecksum, PARSE_EMPTY, intPragma);
157 BFN_PARSE_EMPTY(PragmaPayloadChecksum, PARSE_EMPTY, intPragma);
158
159 // pa_ pragmas
160 BFN_PARSE_EMPTY(PragmaAlias, PARSE_STRING_LITERAL_LIST, extPragma);
161 BFN_PARSE_EMPTY(PragmaAtomic, PARSE_STRING_LITERAL_LIST, extPragma);
162 BFN_PARSE_EMPTY(PragmaAutoInitMetadata, PARSE_EMPTY, extPragma);
163 BFN_PARSE_EMPTY(PragmaBytePack, PARSE_EXPRESSION_LIST, extPragma);
164 BFN_PARSE_EMPTY(PragmaContainerSize, PARSE_EXPRESSION_LIST, extPragma);
165 BFN_PARSE_EMPTY(PragmaContainerType, PARSE_STRING_LITERAL_LIST, extPragma);
166 // FIXME: is DisableDeparseZero internal?
167 BFN_PARSE_EMPTY(PragmaDisableDeparseZero, PARSE_STRING_LITERAL_LIST, intPragma);
168 BFN_PARSE_EMPTY(PragmaMutuallyExclusive, PARSE_STRING_LITERAL_LIST, extPragma);
169 BFN_PARSE_EMPTY(PragmaNoInit, PARSE_STRING_LITERAL_LIST, extPragma);
170 BFN_PARSE_EMPTY(PragmaNoOverlay, PARSE_STRING_LITERAL_LIST, extPragma);
171 BFN_PARSE_EMPTY(PragmaNoPack, PARSE_STRING_LITERAL_LIST, extPragma);
172 BFN_PARSE_EMPTY(PragmaNotDeparsed, PARSE_STRING_LITERAL_LIST, extPragma);
173 BFN_PARSE_EMPTY(PragmaNotParsed, PARSE_STRING_LITERAL_LIST, extPragma);
174 BFN_PARSE_EMPTY(PragmaParserBandwidthOpt, PARSE_EMPTY, extPragma);
175 BFN_PARSE_EMPTY(PragmaParserGroupMonogress, PARSE_EMPTY, extPragma);
176 BFN_PARSE_EMPTY(PragmaAllowPOVonMocha, PARSE_EMPTY, extPragma);
177 BFN_PARSE_EMPTY(PragmaPrioritizeARAinits, PARSE_EMPTY, extPragma);
178 BFN_PARSE_EMPTY(PragmaQuickPhvAlloc, PARSE_EMPTY, extPragma);
179 BFN_PARSE_EMPTY(PragmaSolitary, PARSE_STRING_LITERAL_LIST, extPragma);
180
181 // internal annotation to be removed
182 BFN_PARSE(PragmaActionSelectorHashFieldCalcName, PARSE, StringLiteral, intPragma);
183 BFN_PARSE(PragmaActionSelectorHashFieldCalcOutputWidth, PARSE, Expression, intPragma);
184 BFN_PARSE(PragmaActionSelectorHashFieldListName, PARSE, StringLiteral, intPragma);
185 BFN_PARSE(PragmaAlgorithm, PARSE, StringLiteral, intPragma);
186 }
187};
188
189} // namespace BFN
190
191#endif /* BACKENDS_TOFINO_BF_P4C_COMMON_PARSE_ANNOTATIONS_H_ */
Definition parseAnnotations.h:138
ParseAnnotations(bool warn=false)
Produces a pass that rewrites the spec-defined annotations.
Definition parseAnnotations.h:150
Definition pa_alias.h:38
Definition pa_atomic.h:30
Definition pa_byte_pack.h:39
Definition pa_container_size.h:39
Definition pa_container_type.h:35
do_not_use_clot pragma support.
Definition do_not_use_clot.h:37
Definition pa_mutually_exclusive.h:37
Definition pa_no_overlay.h:33
Definition pa_no_pack.h:28
Definition pa_solitary.h:27
Adds the no_init pragma to the specified fields with the specified gress.
Definition pa_no_init.h:35
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21