P4C
The P4 Compiler
Loading...
Searching...
No Matches
ubpfTable.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_UBPFTABLE_H_
18#define BACKENDS_UBPF_UBPFTABLE_H_
19
20#include "backends/ebpf/ebpfObject.h"
21#include "frontends/p4/methodInstance.h"
22#include "ubpfProgram.h"
23
24namespace P4::UBPF {
25
27 public:
28 const UBPFProgram *program;
29
30 cstring instanceName;
31 cstring keyTypeName;
32 cstring valueTypeName;
33 const IR::Type *keyType{};
34 const IR::Type *valueType{};
35 cstring dataMapName;
36 size_t size{};
38
39 void emitInstance(EBPF::CodeBuilder *pBuilder, EBPF::TableKind tableKind);
40
41 protected:
42 UBPFTableBase(const UBPFProgram *program, cstring instanceName, EBPF::CodeGenInspector *codeGen)
43 : program(program), instanceName(instanceName), codeGen(codeGen) {
44 CHECK_NULL(codeGen);
45 CHECK_NULL(program);
46 keyTypeName = program->refMap->newName(instanceName + "_key");
47 valueTypeName = program->refMap->newName(instanceName + "_value");
48 dataMapName = instanceName;
49 }
50};
51
52class UBPFTable final : public UBPFTableBase {
53 private:
54 void setTableSize(const IR::TableBlock *table);
55 void setTableKind();
56
57 public:
58 const IR::Key *keyGenerator;
59 const IR::ActionList *actionList;
60 const IR::TableBlock *table;
61 EBPF::TableKind tableKind;
62 cstring defaultActionMapName;
63 cstring actionEnumName;
64 cstring noActionName;
65 std::map<const IR::KeyElement *, cstring> keyFieldNames;
66 std::map<const IR::KeyElement *, EBPF::EBPFType *> keyTypes;
67
68 UBPFTable(const UBPFProgram *program, const IR::TableBlock *table,
69 EBPF::CodeGenInspector *codeGen);
70
71 cstring generateActionName(const IR::P4Action *action);
72 void emitInstance(EBPF::CodeBuilder *pBuilder);
73 void emitTypes(EBPF::CodeBuilder *builder);
74 void emitActionArguments(EBPF::CodeBuilder *builder, const IR::P4Action *action, cstring name);
75 void emitKeyType(EBPF::CodeBuilder *builder);
76 void emitValueType(EBPF::CodeBuilder *builder);
77 void emitKey(EBPF::CodeBuilder *builder, cstring keyName);
78 void emitAction(EBPF::CodeBuilder *builder, cstring valueName);
79 void emitInitializer(EBPF::CodeBuilder *builder);
80};
81
82} // namespace P4::UBPF
83
84#endif // BACKENDS_UBPF_UBPFTABLE_H_
Definition ebpf/codeGen.h:33
Definition ebpf/codeGen.h:41
Base class for EBPF objects.
Definition ebpfObject.h:31
cstring newName(std::string_view base) override
Generate a name from base that fresh for the program.
Definition referenceMap.cpp:96
Definition ubpfProgram.h:37
Definition ubpfTable.h:26
Definition ubpfTable.h:52
Definition cstring.h:85