P4C
The P4 Compiler
Loading...
Searching...
No Matches
ubpf/target.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_TARGET_H_
9#define BACKENDS_UBPF_TARGET_H_
10
11#include "backends/ebpf/ebpfObject.h"
12#include "backends/ebpf/target.h"
13#include "ubpfHelpers.h"
14
15namespace P4::UBPF {
16
17using namespace P4::literals;
18
20
21class UbpfTarget : public EBPF::Target {
22 public:
23 UbpfTarget() : EBPF::Target("UBPF"_cs) {}
24
25 void emitLicense(Util::SourceCodeBuilder *, cstring) const override {};
26 void emitCodeSection(Util::SourceCodeBuilder *, cstring) const override {};
27 void emitIncludes(Util::SourceCodeBuilder *builder) const override;
28 void emitResizeBuffer(Util::SourceCodeBuilder *builder, cstring buffer,
29 cstring offsetVar) const override;
30 void emitTableLookup(Util::SourceCodeBuilder *builder, cstring tblName, cstring key,
31 cstring value) const override;
32 void emitTableUpdate(Util::SourceCodeBuilder *builder, cstring tblName, cstring key,
33 cstring value) const override;
34 void emitGetPacketData(Util::SourceCodeBuilder *builder, cstring ctxVar) const;
35 void emitGetFromStandardMetadata(Util::SourceCodeBuilder *builder, cstring stdMetadataVar,
36 cstring metadataField) const;
37 void emitUserTableUpdate(UNUSED Util::SourceCodeBuilder *builder, UNUSED cstring tblName,
38 UNUSED cstring key, UNUSED cstring value) const override {};
39 void emitTableDecl(Util::SourceCodeBuilder *builder, cstring tblName, EBPF::TableKind tableKind,
40 cstring keyType, cstring valueType, unsigned size) const override;
41 void emitMain(UNUSED Util::SourceCodeBuilder *builder, UNUSED cstring functionName,
42 UNUSED cstring argName) const override {};
43 void emitMain(Util::SourceCodeBuilder *builder, cstring functionName, cstring argName,
44 cstring standardMetadata) const;
45 void emitUbpfHelpers(EBPF::CodeBuilder *builder) const;
46 void emitChecksumHelpers(EBPF::CodeBuilder *builder) const;
47
48 cstring dataOffset(UNUSED cstring base) const override { return ""_cs; }
49 cstring dataEnd(UNUSED cstring base) const override { return ""_cs; }
50 cstring dataLength(UNUSED cstring base) const override { return ""_cs; }
51 cstring dropReturnCode() const override { return "0"_cs; }
52 cstring abortReturnCode() const override { return "1"_cs; }
53 cstring forwardReturnCode() const override { return "1"_cs; }
54 cstring sysMapPath() const override { return ""_cs; }
55 cstring packetDescriptorType() const override { return "void"_cs; }
56};
57
58} // namespace P4::UBPF
59
60#endif /* BACKENDS_UBPF_TARGET_H_ */
Definition ebpf/codeGen.h:33
Definition ebpf/target.h:44
Definition ubpfControl.h:18
Definition sourceCodeBuilder.h:29
Definition cstring.h:85