P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpfPsaDeparser.h
1/*
2Copyright 2022-present Orange
3Copyright 2022-present Open Networking Foundation
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16*/
17#ifndef BACKENDS_EBPF_PSA_EBPFPSADEPARSER_H_
18#define BACKENDS_EBPF_PSA_EBPFPSADEPARSER_H_
19
20#include "backends/ebpf/ebpfDeparser.h"
21#include "backends/ebpf/psa/ebpfPsaParser.h"
22#include "backends/ebpf/psa/externs/ebpfPsaChecksum.h"
23#include "backends/ebpf/psa/externs/ebpfPsaDigest.h"
24#include "ebpfPsaControl.h"
25#include "lib/rtti.h"
26
27namespace P4::EBPF {
28
29class EBPFDeparserPSA;
30
32 public:
33 explicit DeparserBodyTranslatorPSA(const EBPFDeparserPSA *deparser);
34
35 void processFunction(const P4::ExternFunction *function) override;
36 void processMethod(const P4::ExternMethod *method) override;
37};
38
40 public:
41 const IR::Parameter *user_metadata;
42 const IR::Parameter *istd;
43 const IR::Parameter *resubmit_meta;
44 std::map<cstring, EBPFChecksumPSA *> checksums;
45 std::map<cstring, EBPFDigestPSA *> digests;
46
47 EBPFDeparserPSA(const EBPFProgram *program, const IR::ControlBlock *control,
48 const IR::Parameter *parserHeaders, const IR::Parameter *istd)
49 : EBPFDeparser(program, control, parserHeaders), istd(istd) {
50 codeGen = new DeparserBodyTranslatorPSA(this);
51 }
52
53 void emitTypes(CodeBuilder *builder) const;
54 void emitDigestInstances(CodeBuilder *builder) const;
55 void emitDeclaration(CodeBuilder *builder, const IR::Declaration *decl) override;
56
57 EBPFChecksumPSA *getChecksum(cstring name) const {
58 auto result = ::P4::get(checksums, name);
59 BUG_CHECK(result != nullptr, "No checksum named %1%", name);
60 return result;
61 }
62
63 EBPFDigestPSA *getDigest(cstring name) const {
64 auto result = ::P4::get(digests, name);
65 BUG_CHECK(result != nullptr, "No digest named %1%", name);
66 return result;
67 }
68
69 void emitDeparserExternCalls(EBPF::CodeBuilder *builder) override {
70 controlBlock->container->body->apply(*codeGen);
71 builder->newline();
72 }
73
74 DECLARE_TYPEINFO(EBPFDeparserPSA, EBPFDeparser);
75};
76
78 public:
79 IngressDeparserPSA(const EBPFProgram *program, const IR::ControlBlock *control,
80 const IR::Parameter *parserHeaders, const IR::Parameter *istd)
81 : EBPFDeparserPSA(program, control, parserHeaders, istd) {}
82
83 bool build() override;
84
85 DECLARE_TYPEINFO(IngressDeparserPSA, EBPFDeparserPSA);
86};
87
89 public:
90 EgressDeparserPSA(const EBPFProgram *program, const IR::ControlBlock *control,
91 const IR::Parameter *parserHeaders, const IR::Parameter *istd)
92 : EBPFDeparserPSA(program, control, parserHeaders, istd) {}
93
94 bool build() override;
95
96 DECLARE_TYPEINFO(EgressDeparserPSA, EBPFDeparserPSA);
97};
98
100 public:
101 TCIngressDeparserPSA(const EBPFProgram *program, const IR::ControlBlock *control,
102 const IR::Parameter *parserHeaders, const IR::Parameter *istd)
103 : IngressDeparserPSA(program, control, parserHeaders, istd) {}
104
105 void emitPreDeparser(CodeBuilder *builder) override;
106
107 DECLARE_TYPEINFO(TCIngressDeparserPSA, IngressDeparserPSA);
108};
109
111 public:
112 TCEgressDeparserPSA(const EBPFProgram *program, const IR::ControlBlock *control,
113 const IR::Parameter *parserHeaders, const IR::Parameter *istd)
114 : EgressDeparserPSA(program, control, parserHeaders, istd) {}
115
116 DECLARE_TYPEINFO(TCEgressDeparserPSA, EgressDeparserPSA);
117};
118
120 public:
122 const IR::ControlBlock *control,
123 const IR::Parameter *parserHeaders,
124 const IR::Parameter *istd)
125 : TCIngressDeparserPSA(program, control, parserHeaders, istd) {}
126 void emitPreDeparser(CodeBuilder *builder) override;
127 void emitDeparserExternCalls(CodeBuilder *builder) override {
128 (void)builder;
129 // do not emit deparser extern calls for TCIngressDeparserForTrafficManagerPSA
130 }
131
133};
134
136 public:
137 XDPIngressDeparserPSA(const EBPFProgram *program, const IR::ControlBlock *control,
138 const IR::Parameter *parserHeaders, const IR::Parameter *istd)
139 : IngressDeparserPSA(program, control, parserHeaders, istd) {}
140
141 void emitPreDeparser(CodeBuilder *builder) override;
142
143 DECLARE_TYPEINFO(XDPIngressDeparserPSA, IngressDeparserPSA);
144};
145
147 public:
148 XDPEgressDeparserPSA(const EBPFProgram *program, const IR::ControlBlock *control,
149 const IR::Parameter *parserHeaders, const IR::Parameter *istd)
150 : EgressDeparserPSA(program, control, parserHeaders, istd) {}
151
152 void emitPreDeparser(CodeBuilder *builder) override;
153
154 DECLARE_TYPEINFO(XDPEgressDeparserPSA, EgressDeparserPSA);
155};
156
157} // namespace P4::EBPF
158
159#endif /* BACKENDS_EBPF_PSA_EBPFPSADEPARSER_H_ */
Definition ebpf/codeGen.h:33
This translator emits deparser externs.
Definition ebpfDeparser.h:27
Definition ebpfPsaDeparser.h:31
Definition ebpfPsaChecksum.h:25
Definition ebpfDeparser.h:63
Definition ebpfPsaDeparser.h:39
Definition ebpfPsaDigest.h:27
Definition ebpfProgram.h:39
Definition ebpfPsaDeparser.h:88
Definition ebpfPsaDeparser.h:77
Definition ebpfPsaDeparser.h:110
Definition ebpfPsaDeparser.h:119
void emitPreDeparser(CodeBuilder *builder) override
Definition ebpfPsaDeparser.cpp:181
Definition ebpfPsaDeparser.h:99
void emitPreDeparser(CodeBuilder *builder) override
Definition ebpfPsaDeparser.cpp:137
Definition ebpfPsaDeparser.h:146
void emitPreDeparser(CodeBuilder *builder) override
Definition ebpfPsaDeparser.cpp:291
Definition ebpfPsaDeparser.h:135
void emitPreDeparser(CodeBuilder *builder) override
Definition ebpfPsaDeparser.cpp:196
Definition methodInstance.h:194
Definition methodInstance.h:168
Definition cstring.h:85
Definition codeGen.cpp:25