P4C
The P4 Compiler
Loading...
Searching...
No Matches
bmv2/common/midend.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_BMV2_COMMON_MIDEND_H_
18#define BACKENDS_BMV2_COMMON_MIDEND_H_
19
20#include "frontends/common/options.h"
21#include "ir/ir.h"
22#include "lower.h"
23#include "midend/convertEnums.h"
24
25namespace P4::BMV2 {
26
31 cstring filename;
32
33 bool convert(const IR::Type_Enum *type) const override {
34 if (type->srcInfo.isValid()) {
35 auto sourceFile = type->srcInfo.getSourceFile();
36 if (sourceFile.endsWith(filename))
37 // Don't convert any of the standard enums
38 return false;
39 }
40 return true;
41 }
42 unsigned enumSize(unsigned) const override { return 32; }
43
44 public:
47 explicit EnumOn32Bits(cstring filename) : filename(filename) {}
48};
49
50class MidEnd : public PassManager {
51 public:
54 P4::TypeMap typeMap;
55 const IR::ToplevelBlock *toplevel = nullptr;
56 P4::ConvertEnums::EnumMapping enumMap;
57 bool isv1;
58
59 explicit MidEnd(CompilerOptions &options) {
60 isv1 = options.isv1();
61 refMap.setIsV1(isv1); // must be done BEFORE creating passes
62 }
63 const IR::ToplevelBlock *process(const IR::P4Program *&program) {
64 program = program->apply(*this);
65 return toplevel;
66 }
67};
68
69} // namespace P4::BMV2
70
71#endif /* BACKENDS_BMV2_COMMON_MIDEND_H_ */
Definition bmv2/common/midend.h:30
EnumOn32Bits(cstring filename)
Definition bmv2/common/midend.h:47
Definition bmv2/common/midend.h:50
P4::ReferenceMap refMap
These will be accurate when the mid-end completes evaluation.
Definition bmv2/common/midend.h:53
Definition convertEnums.h:29
Definition frontends/common/options.h:30
bool isv1() const
True if we are compiling a P4 v1.0 or v1.1 program.
Definition parser_options.cpp:473
Definition ir/pass_manager.h:40
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
void setIsV1(bool isv1)
Set boolean indicating whether map is for a P4_14 program to isV1.
Definition referenceMap.h:105
Definition typeMap.h:41
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition action.cpp:21