P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpfObject.h
1/*
2 * SPDX-FileCopyrightText: 2013 Barefoot Networks, Inc.
3 * Copyright 2013-present Barefoot Networks, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef BACKENDS_EBPF_EBPFOBJECT_H_
9#define BACKENDS_EBPF_EBPFOBJECT_H_
10
11#include "codeGen.h"
12#include "ebpfModel.h"
13#include "frontends/p4/evaluator/evaluator.h"
14#include "frontends/p4/typeMap.h"
15#include "ir/ir.h"
16#include "lib/castable.h"
17#include "target.h"
18
19namespace P4::EBPF {
20
22class EBPFObject : public ICastable {
23 public:
24 virtual ~EBPFObject() {}
25
26 static cstring externalName(const IR::IDeclaration *declaration) {
27 cstring name = declaration->externalName();
28 return name.replace('.', '_');
29 }
30
31 static cstring getSpecializedTypeName(const IR::Declaration_Instance *di) {
32 if (auto typeSpec = di->type->to<IR::Type_Specialized>()) {
33 if (auto typeName = typeSpec->baseType->to<IR::Type_Name>()) {
34 return typeName->path->name.name;
35 }
36 }
37
38 return nullptr;
39 }
40
41 static cstring getTypeName(const IR::Declaration_Instance *di) {
42 if (auto typeName = di->type->to<IR::Type_Name>()) {
43 return typeName->path->name.name;
44 }
45
46 return nullptr;
47 }
48
49 DECLARE_TYPEINFO(EBPFObject);
50};
51
52} // namespace P4::EBPF
53
54#endif /* BACKENDS_EBPF_EBPFOBJECT_H_ */
Base class for EBPF objects.
Definition ebpfObject.h:22
Definition castable.h:27
The Declaration interface, representing objects with names.
Definition declaration.h:17
Definition cstring.h:76
Definition codeGen.cpp:14