P4C
The P4 Compiler
Loading...
Searching...
No Matches
ubpfControl.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_UBPFCONTROL_H_
9#define BACKENDS_UBPF_UBPFCONTROL_H_
10
11#include "backends/ebpf/ebpfControl.h"
12#include "ubpfRegister.h"
13
14namespace P4::UBPF {
15
16class UBPFControl;
17
18class UBPFControlBodyTranslator : public EBPF::ControlBodyTranslator {
19 public:
20 const UBPFControl *control;
21 std::set<const IR::Parameter *> toDereference;
22 std::vector<cstring> saveAction;
23 P4::P4CoreLibrary &p4lib;
24
25 std::vector<UBPFRegister *> registersLookups;
26
27 explicit UBPFControlBodyTranslator(const UBPFControl *control);
28 void processMethod(const P4::ExternMethod *method) override;
29 void processApply(const P4::ApplyMethod *method) override;
30 void processFunction(const P4::ExternFunction *function) override;
31 void processChecksumReplace2(const P4::ExternFunction *function);
32 void processChecksumReplace4(const P4::ExternFunction *function);
33 bool preorder(const IR::PathExpression *expression) override;
34 bool preorder(const IR::MethodCallStatement *s) override;
35 bool preorder(const IR::MethodCallExpression *expression) override;
36 bool preorder(const IR::BaseAssignmentStatement *a) override { return notSupported(a); }
37 bool preorder(const IR::AssignmentStatement *a) override;
38 bool preorder(const IR::BlockStatement *s) override;
39 bool preorder(const IR::ExitStatement *) override;
40 bool preorder(const IR::ReturnStatement *) override;
41 bool preorder(const IR::IfStatement *statement) override;
42 bool preorder(const IR::SwitchStatement *statement) override;
43 bool preorder(const IR::Operation_Binary *b) override;
44 bool comparison(const IR::Operation_Relation *b);
45 bool preorder(const IR::Member *expression) override;
46 cstring createHashKeyInstance(const P4::ExternFunction *function);
47 void emitAssignmentStatement(const IR::AssignmentStatement *a);
48 bool emitRegisterRead(const IR::AssignmentStatement *a, const IR::MethodCallExpression *method);
49};
50
51class UBPFControl : public EBPF::EBPFControl {
52 public:
53 const UBPFProgram *program;
54 const IR::ControlBlock *controlBlock;
55 const IR::Parameter *headers;
56 const IR::Parameter *parserHeaders;
57 // replace references to headers with references to parserHeaders
58 cstring passVariable;
60
61 std::set<const IR::Parameter *> toDereference;
62 std::map<cstring, UBPFTable *> tables;
63 std::map<cstring, UBPFRegister *> registers;
64
65 UBPFControl(const UBPFProgram *program, const IR::ControlBlock *block,
66 const IR::Parameter *parserHeaders);
67
68 void emit(EBPF::CodeBuilder *builder);
69 void emitDeclaration(EBPF::CodeBuilder *builder, const IR::Declaration *decl);
70 void emitTableTypes(EBPF::CodeBuilder *builder);
71 void emitTableInstances(EBPF::CodeBuilder *builder);
72 void emitTableInitializers(EBPF::CodeBuilder *builder);
73 bool build();
74
75 UBPFTable *getTable(cstring name) const {
76 auto result = ::P4::get(tables, name);
77 BUG_CHECK(result != nullptr, "No table named %1%", name);
78 return result;
79 }
80
81 UBPFRegister *getRegister(cstring name) const {
82 auto result = ::P4::get(registers, name);
83 BUG_CHECK(result != nullptr, "No register named %1%", name);
84 return result;
85 }
86
87 protected:
88 void scanConstants();
89};
90
91} // namespace P4::UBPF
92
93#endif /* BACKENDS_UBPF_UBPFCONTROL_H_ */
Definition methodInstance.h:129
Definition ebpf/codeGen.h:33
Definition ebpfControl.h:28
Definition ebpfControl.h:57
Definition methodInstance.h:194
Definition methodInstance.h:168
Definition coreLibrary.h:103
Definition ubpfControl.h:18
Definition ubpfControl.h:51
Definition ubpfProgram.h:28
Definition ubpfRegister.h:16
Definition ubpfTable.h:43
Definition cstring.h:85