P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
ubpfType.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_UBPFTYPE_H_
18#define BACKENDS_UBPF_UBPFTYPE_H_
19
20#include "backends/ebpf/ebpfType.h"
21#include "lib/sourceCodeBuilder.h"
22
23namespace UBPF {
24
26 public:
27 explicit UBPFTypeFactory(const P4::TypeMap *typeMap) : EBPF::EBPFTypeFactory(typeMap) {}
28
29 static void createFactory(const P4::TypeMap *typeMap) {
30 EBPF::EBPFTypeFactory::instance = new UBPFTypeFactory(typeMap);
31 }
32
33 static EBPFTypeFactory *getInstance() { return EBPF::EBPFTypeFactory::instance; }
34
35 EBPF::EBPFType *create(const IR::Type *type) override;
36};
37
39 public:
41
42 void emit(EBPF::CodeBuilder *builder) override { builder->append("uint8_t"); }
43
44 DECLARE_TYPEINFO(UBPFBoolType, EBPF::EBPFBoolType);
45};
46
48 public:
49 explicit UBPFScalarType(const IR::Type_Bits *bits) : EBPF::EBPFScalarType(bits) {}
50
51 void emit(EBPF::CodeBuilder *builder) override;
52
53 cstring getAsString();
54
55 void declare(EBPF::CodeBuilder *builder, cstring id, bool asPointer) override;
56 void declareInit(EBPF::CodeBuilder *builder, cstring id, bool asPointer) override;
57
58 DECLARE_TYPEINFO(UBPFScalarType, EBPF::EBPFScalarType);
59};
60
62 public:
63 explicit UBPFStructType(const IR::Type_StructLike *strct) : EBPF::EBPFStructType(strct) {}
64 void emit(EBPF::CodeBuilder *builder) override;
65 void declare(EBPF::CodeBuilder *builder, cstring id, bool asPointer) override;
66 void declareInit(EBPF::CodeBuilder *builder, cstring id, bool asPointer) override;
67
68 DECLARE_TYPEINFO(UBPFStructType, EBPF::EBPFStructType);
69};
70
72 public:
73 explicit UBPFEnumType(const IR::Type_Enum *strct) : EBPF::EBPFEnumType(strct) {}
74
75 void emit(EBPF::CodeBuilder *builder) override;
76
77 DECLARE_TYPEINFO(UBPFEnumType, EBPF::EBPFEnumType);
78};
79
81 class UBPFListElement : public ICastable {
82 public:
83 EBPFType *type;
84 const cstring name;
85
86 UBPFListElement(EBPFType *type, const cstring name) : type(type), name(name) {}
87 virtual ~UBPFListElement() {} // to make UBPFListElement polymorphic.
88
89 DECLARE_TYPEINFO(UBPFListElement);
90 };
91
92 class Padding : public UBPFListElement {
93 public:
94 unsigned widthInBytes;
95
96 Padding(const cstring name, unsigned widthInBytes)
97 : UBPFListElement(nullptr, name), widthInBytes(widthInBytes) {}
98
99 DECLARE_TYPEINFO(Padding, UBPFListElement);
100 };
101
102 public:
103 cstring kind;
104 cstring name;
105 std::vector<UBPFListElement *> elements;
106 unsigned width;
107 unsigned implWidth;
108
109 explicit UBPFListType(const IR::Type_List *lst);
110 void emitPadding(EBPF::CodeBuilder *builder, Padding *padding);
111 void declare(EBPF::CodeBuilder *builder, cstring id, bool asPointer) override;
112 void declareInit(EBPF::CodeBuilder *builder, cstring id, bool asPointer) override;
113 void emitInitializer(EBPF::CodeBuilder *builder) override;
114 unsigned widthInBits() const override { return width; }
115 unsigned implementationWidthInBits() const override { return implWidth; }
116 void emit(EBPF::CodeBuilder *builder) override;
117
118 DECLARE_TYPEINFO(UBPFListType, EBPF::EBPFType, EBPF::IHasWidth);
119};
120
121} // namespace UBPF
122
123#endif /* BACKENDS_UBPF_UBPFTYPE_H_ */
Definition codeGen.h:33
Definition ebpfType.h:71
Definition ebpfType.h:183
Definition ebpfType.h:106
Definition ebpfType.h:153
Definition ebpfType.h:58
Definition ebpfType.h:29
Definition ebpfType.h:46
Definition castable.h:34
Definition typeMap.h:42
Definition ubpfType.h:38
Definition ubpfType.h:71
Definition ubpfType.h:80
Definition ubpfType.h:47
Definition ubpfType.h:61
Definition ubpfType.h:25
Definition cstring.h:72