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