P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpfObject.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
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_EBPF_EBPFOBJECT_H_
18#define BACKENDS_EBPF_EBPFOBJECT_H_
19
20#include "codeGen.h"
21#include "ebpfModel.h"
22#include "frontends/p4/evaluator/evaluator.h"
23#include "frontends/p4/typeMap.h"
24#include "ir/ir.h"
25#include "lib/castable.h"
26#include "target.h"
27
28namespace P4::EBPF {
29
31class EBPFObject : public ICastable {
32 public:
33 virtual ~EBPFObject() {}
34
35 static cstring externalName(const IR::IDeclaration *declaration) {
36 cstring name = declaration->externalName();
37 return name.replace('.', '_');
38 }
39
40 static cstring getSpecializedTypeName(const IR::Declaration_Instance *di) {
41 if (auto typeSpec = di->type->to<IR::Type_Specialized>()) {
42 if (auto typeName = typeSpec->baseType->to<IR::Type_Name>()) {
43 return typeName->path->name.name;
44 }
45 }
46
47 return nullptr;
48 }
49
50 static cstring getTypeName(const IR::Declaration_Instance *di) {
51 if (auto typeName = di->type->to<IR::Type_Name>()) {
52 return typeName->path->name.name;
53 }
54
55 return nullptr;
56 }
57
58 DECLARE_TYPEINFO(EBPFObject);
59};
60
61} // namespace P4::EBPF
62
63#endif /* BACKENDS_EBPF_EBPFOBJECT_H_ */
Base class for EBPF objects.
Definition ebpfObject.h:31
Definition castable.h:36
The Declaration interface, representing objects with names.
Definition declaration.h:26
Definition cstring.h:85
Definition codeGen.cpp:25