P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpfDeparser.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_EBPFDEPARSER_H_
18#define BACKENDS_EBPF_EBPFDEPARSER_H_
19
20#include "ebpfControl.h"
21
22namespace P4::EBPF {
23
24class EBPFDeparser;
25
28 protected:
29 const EBPFDeparser *deparser;
30
31 public:
32 explicit DeparserBodyTranslator(const EBPFDeparser *deparser);
33
34 bool preorder(const IR::MethodCallExpression *expression) override;
35};
36
39 protected:
40 const EBPFDeparser *deparser;
41
42 public:
43 explicit DeparserPrepareBufferTranslator(const EBPFDeparser *deparser);
44
45 void processMethod(const P4::ExternMethod *method) override;
46 bool preorder(const IR::BlockStatement *s) override;
47 bool preorder(const IR::MethodCallExpression *expression) override;
48};
49
52 protected:
53 const EBPFDeparser *deparser;
54
55 public:
56 explicit DeparserHdrEmitTranslator(const EBPFDeparser *deparser);
57
58 void processMethod(const P4::ExternMethod *method) override;
59 void emitField(CodeBuilder *builder, cstring field, const IR::Expression *hdrExpr,
60 unsigned alignment, EBPF::EBPFType *type);
61};
62
63class EBPFDeparser : public EBPFControl {
64 public:
65 const IR::Parameter *packet_out;
66
67 EBPFType *headerType;
68 cstring outerHdrOffsetVar, outerHdrLengthVar;
69 cstring returnCode;
70
71 EBPFDeparser(const EBPFProgram *program, const IR::ControlBlock *control,
72 const IR::Parameter *parserHeaders)
73 : EBPFControl(program, control, parserHeaders) {
74 codeGen = new DeparserBodyTranslator(this);
75 outerHdrOffsetVar = cstring("outHeaderOffset");
76 outerHdrLengthVar = cstring("outHeaderLength");
77 returnCode = cstring("returnCode");
78 }
79
80 bool build() override;
81 void emit(CodeBuilder *builder) override;
85 virtual void emitPreDeparser(CodeBuilder *builder) { (void)builder; }
86
87 virtual void emitDeparserExternCalls(CodeBuilder *builder) { (void)builder; }
88
89 void emitBufferAdjusts(CodeBuilder *builder) const;
90
91 DECLARE_TYPEINFO(EBPFDeparser, EBPFControl);
92};
93
94} // namespace P4::EBPF
95
96#endif /* BACKENDS_EBPF_EBPFDEPARSER_H_ */
Definition ebpf/codeGen.h:33
Definition ebpfControl.h:28
This translator emits deparser externs.
Definition ebpfDeparser.h:27
This translator emits headers.
Definition ebpfDeparser.h:51
This translator emits buffer preparation (eg. which headers will be emitted)
Definition ebpfDeparser.h:38
Definition ebpfControl.h:57
Definition ebpfDeparser.h:63
virtual void emitPreDeparser(CodeBuilder *builder)
Definition ebpfDeparser.h:85
Definition ebpfProgram.h:39
Base class for EBPF types.
Definition ebpfType.h:29
Definition methodInstance.h:168
Definition cstring.h:85
Definition codeGen.cpp:25