P4C
The P4 Compiler
Loading...
Searching...
No Matches
ubpfDeparser.h
1/*
2 * Copyright 2019 Orange
3 * SPDX-FileCopyrightText: 2019 Orange
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef BACKENDS_UBPF_UBPFDEPARSER_H_
9#define BACKENDS_UBPF_UBPFDEPARSER_H_
10
11#include "backends/ebpf/ebpfObject.h"
12#include "ir/ir.h"
13#include "ubpfHelpers.h"
14#include "ubpfProgram.h"
15
16namespace P4::UBPF {
17
18class UBPFDeparser;
19
20class UBPFDeparserTranslationVisitor : public EBPF::CodeGenInspector {
21 public:
22 const UBPFDeparser *deparser;
23 P4::P4CoreLibrary &p4lib;
24
25 explicit UBPFDeparserTranslationVisitor(const UBPFDeparser *deparser);
26
27 virtual void compileEmitField(const IR::Expression *expr, cstring field, unsigned alignment,
28 EBPF::EBPFType *type);
29 virtual void compileEmit(const IR::Vector<IR::Argument> *args);
30
31 bool notSupported(const IR::Expression *expression) {
32 ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: not supported in Deparser",
33 expression);
34 return false;
35 }
36
37 bool notSupported(const IR::StatOrDecl *statOrDecl) {
38 ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: not supported in Deparser",
39 statOrDecl);
40 return false;
41 }
42
43 bool preorder(const IR::MethodCallExpression *expression) override;
44 bool preorder(const IR::BaseAssignmentStatement *a) override { return notSupported(a); };
45 bool preorder(const IR::ExitStatement *s) override { return notSupported(s); };
46 bool preorder(UNUSED const IR::BlockStatement *s) override { return true; };
47 bool preorder(const IR::ReturnStatement *s) override { return notSupported(s); };
48 bool preorder(const IR::IfStatement *statement) override { return notSupported(statement); };
49 bool preorder(const IR::SwitchStatement *statement) override {
50 return notSupported(statement);
51 };
52 bool preorder(const IR::Operation_Binary *b) override { return notSupported(b); };
53};
54
55class UBPFDeparser : public EBPF::EBPFObject {
56 public:
57 const UBPFProgram *program;
58 const IR::ControlBlock *controlBlock;
59 const IR::Parameter *packet_out;
60 const IR::Parameter *headers;
61 const IR::Parameter *parserHeaders;
62
64
65 UBPFDeparser(const UBPFProgram *program, const IR::ControlBlock *block,
66 const IR::Parameter *parserHeaders)
67 : program(program), controlBlock(block), headers(nullptr), parserHeaders(parserHeaders) {}
68
69 bool build();
70 void emit(EBPF::CodeBuilder *builder);
71};
72} // namespace P4::UBPF
73
74#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 ir/vector.h:59
Definition coreLibrary.h:103
Definition ubpfDeparser.h:55
Definition ubpfDeparser.h:20
Definition ubpfProgram.h:28
Definition cstring.h:85
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:58