P4C
The P4 Compiler
Loading...
Searching...
No Matches
ubpfDeparser.h
1/*
2Copyright 2019 Orange
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef BACKENDS_UBPF_UBPFDEPARSER_H_
18#define BACKENDS_UBPF_UBPFDEPARSER_H_
19
20#include "backends/ebpf/ebpfObject.h"
21#include "ir/ir.h"
22#include "ubpfHelpers.h"
23#include "ubpfProgram.h"
24
25namespace P4::UBPF {
26
27class UBPFDeparser;
28
30 public:
31 const UBPFDeparser *deparser;
32 P4::P4CoreLibrary &p4lib;
33
34 explicit UBPFDeparserTranslationVisitor(const UBPFDeparser *deparser);
35
36 virtual void compileEmitField(const IR::Expression *expr, cstring field, unsigned alignment,
37 EBPF::EBPFType *type);
38 virtual void compileEmit(const IR::Vector<IR::Argument> *args);
39
40 bool notSupported(const IR::Expression *expression) {
41 ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: not supported in Deparser",
42 expression);
43 return false;
44 }
45
46 bool notSupported(const IR::StatOrDecl *statOrDecl) {
47 ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: not supported in Deparser",
48 statOrDecl);
49 return false;
50 }
51
52 bool preorder(const IR::MethodCallExpression *expression) override;
53 bool preorder(const IR::AssignmentStatement *a) override { return notSupported(a); };
54 bool preorder(const IR::ExitStatement *s) override { return notSupported(s); };
55 bool preorder(UNUSED const IR::BlockStatement *s) override { return true; };
56 bool preorder(const IR::ReturnStatement *s) override { return notSupported(s); };
57 bool preorder(const IR::IfStatement *statement) override { return notSupported(statement); };
58 bool preorder(const IR::SwitchStatement *statement) override {
59 return notSupported(statement);
60 };
61 bool preorder(const IR::Operation_Binary *b) override { return notSupported(b); };
62};
63
65 public:
66 const UBPFProgram *program;
67 const IR::ControlBlock *controlBlock;
68 const IR::Parameter *packet_out;
69 const IR::Parameter *headers;
70 const IR::Parameter *parserHeaders;
71
73
74 UBPFDeparser(const UBPFProgram *program, const IR::ControlBlock *block,
75 const IR::Parameter *parserHeaders)
76 : program(program), controlBlock(block), headers(nullptr), parserHeaders(parserHeaders) {}
77
78 bool build();
79 void emit(EBPF::CodeBuilder *builder);
80};
81} // namespace P4::UBPF
82
83#endif /* BACKENDS_UBPF_UBPFDEPARSER_H_ */
Definition ebpf/codeGen.h:33
Definition ebpf/codeGen.h:41
Base class for EBPF objects.
Definition ebpfObject.h:31
Base class for EBPF types.
Definition ebpfType.h:29
Definition vector.h:59
Definition coreLibrary.h:103
Definition ubpfDeparser.h:64
Definition ubpfDeparser.h:29
Definition ubpfProgram.h:37
Definition cstring.h:85
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:51