P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpf/psa/backend.h
1/*
2 * SPDX-FileCopyrightText: 2022 Open Networking Foundation
3 * SPDX-FileCopyrightText: 2022 Orange
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7#ifndef BACKENDS_EBPF_PSA_BACKEND_H_
8#define BACKENDS_EBPF_PSA_BACKEND_H_
9
10#include "ebpfPsaGen.h"
11
12namespace P4::EBPF {
13
14class PSASwitchBackend {
15 public:
16 const EbpfOptions &options;
17 P4::ReferenceMap *refMap;
18 P4::TypeMap *typeMap;
19 P4::P4CoreLibrary &corelib;
20 const IR::ToplevelBlock *toplevel = nullptr;
21
22 Target *target;
23 const PSAEbpfGenerator *ebpf_program = nullptr;
24
25 PSASwitchBackend(const EbpfOptions &options, Target *target, P4::ReferenceMap *refMap,
26 P4::TypeMap *typeMap)
27 : options(options),
28 refMap(refMap),
29 typeMap(typeMap),
30 corelib(P4::P4CoreLibrary::instance()),
31 target(target) {
32 refMap->setIsV1(options.isv1());
33 }
34
35 void convert(const IR::ToplevelBlock *tlb);
36 void codegen(std::ostream &cstream) const {
37 CodeBuilder c(target);
38 // Instead of generating two files, put all the code in a single file.
39 ebpf_program->emit(&c);
40 cstream << c.toString();
41 }
42};
43
44} // namespace P4::EBPF
45
46#endif /* BACKENDS_EBPF_PSA_BACKEND_H_ */
Definition ebpf/codeGen.h:33
Definition ebpfPsaGen.h:37
Definition ebpf/target.h:44
Definition ebpfOptions.h:26
Definition coreLibrary.h:103
Class used to encode maps from paths to declarations.
Definition referenceMap.h:67
Definition typeMap.h:32
Definition codeGen.cpp:25