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