P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
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 BMV2 {
26
33 cstring filename;
34
35 bool convert(const IR::Type_Enum *type) const override {
36 if (type->srcInfo.isValid()) {
37 auto sourceFile = type->srcInfo.getSourceFile();
38 if (sourceFile.endsWith(filename))
39 // Don't convert any of the standard enums
40 return false;
41 }
42 return true;
43 }
44 unsigned enumSize(unsigned) const override { return 32; }
45
46 public:
49 explicit EnumOn32Bits(cstring filename) : filename(filename) {}
50};
51
52class MidEnd : public PassManager {
53 public:
54 // These will be accurate when the mid-end completes evaluation
55 P4::ReferenceMap refMap;
56 P4::TypeMap typeMap;
57 const IR::ToplevelBlock *toplevel = nullptr;
58 P4::ConvertEnums::EnumMapping enumMap;
59 bool isv1;
60
61 explicit MidEnd(CompilerOptions &options) {
62 isv1 = options.isv1();
63 refMap.setIsV1(isv1); // must be done BEFORE creating passes
64 }
65 const IR::ToplevelBlock *process(const IR::P4Program *&program) {
66 program = program->apply(*this);
67 return toplevel;
68 }
69};
70
71} // namespace BMV2
72
73#endif /* BACKENDS_BMV2_COMMON_MIDEND_H_ */
Definition midend.h:32
EnumOn32Bits(cstring filename)
Definition midend.h:49
Definition midend.h:52
Definition sharedActionSelectorCheck.h:40
Definition options.h:26
Definition convertEnums.h:29
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:42
Definition cstring.h:72