P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpf/lower.h
1/*
2Copyright 2017 VMware, 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_LOWER_H_
18#define BACKENDS_EBPF_LOWER_H_
19
20#include "frontends/common/resolveReferences/resolveReferences.h"
21#include "frontends/p4/typeChecking/typeChecker.h"
22#include "ir/ir.h"
23
24namespace P4::EBPF {
25
28 P4::TypeMap *typeMap;
30 const int maxShiftWidth = 5;
31 const IR::Expression *shift(const IR::Operation_Binary *expression) const;
32
33 public:
34 explicit LowerExpressions(P4::TypeMap *typeMap) : typeMap(typeMap) {
35 CHECK_NULL(typeMap);
36 setName("LowerExpressions");
37 }
38
39 const IR::Node *postorder(IR::Shl *expression) override { return shift(expression); }
40 const IR::Node *postorder(IR::Shr *expression) override { return shift(expression); }
41 const IR::Node *postorder(IR::Expression *expression) override;
42 const IR::Node *postorder(IR::Slice *expression) override;
43 const IR::Node *postorder(IR::Concat *expression) override;
44 const IR::Node *postorder(IR::Cast *expression) override;
45};
46
47class Lower : public PassManager {
48 public:
49 Lower(P4::ReferenceMap *refMap, P4::TypeMap *typeMap) {
50 setName("Lower");
51 passes.push_back(new P4::TypeChecking(refMap, typeMap));
52 passes.push_back(new LowerExpressions(typeMap));
53 }
54};
55
56} // namespace P4::EBPF
57
58#endif /* BACKENDS_EBPF_LOWER_H_ */
This pass rewrites expressions which are not supported natively on EBPF.
Definition ebpf/lower.h:27
Definition ebpf/lower.h:47
Definition node.h:95
Definition ir/pass_manager.h:40
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition visitor.h:424
Definition typeChecker.h:55
Definition typeMap.h:41
Definition codeGen.cpp:25