P4C
The P4 Compiler
Loading...
Searching...
No Matches
bmv2/common/midend.h
1/*
2 * SPDX-FileCopyrightText: 2013 Barefoot Networks, Inc.
3 * Copyright 2013-present Barefoot Networks, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef BACKENDS_BMV2_COMMON_MIDEND_H_
9#define BACKENDS_BMV2_COMMON_MIDEND_H_
10
11#include "frontends/common/options.h"
12#include "ir/ir.h"
13#include "lower.h"
14#include "midend/convertEnums.h"
15
16namespace P4::BMV2 {
17
22 cstring filename;
23
24 bool convert(const IR::Type_Enum *type) const override {
25 if (type->srcInfo.isValid()) {
26 auto sourceFile = type->srcInfo.getSourceFile();
27 if (sourceFile.endsWith(filename))
28 // Don't convert any of the standard enums
29 return false;
30 }
31 return true;
32 }
33 unsigned enumSize(unsigned) const override { return 32; }
34
35 public:
38 explicit EnumOn32Bits(cstring filename) : filename(filename) {}
39};
40
41class MidEnd : public PassManager {
42 public:
45 P4::TypeMap typeMap;
46 const IR::ToplevelBlock *toplevel = nullptr;
47 P4::ConvertEnums::EnumMapping enumMap;
48 bool isv1;
49
50 explicit MidEnd(CompilerOptions &options) {
51 isv1 = options.isv1();
52 refMap.setIsV1(isv1); // must be done BEFORE creating passes
53 }
54 const IR::ToplevelBlock *process(const IR::P4Program *&program) {
55 program = program->apply(*this);
56 return toplevel;
57 }
58};
59
60} // namespace P4::BMV2
61
62#endif /* BACKENDS_BMV2_COMMON_MIDEND_H_ */
EnumOn32Bits(cstring filename)
Definition bmv2/common/midend.h:38
P4::ReferenceMap refMap
These will be accurate when the mid-end completes evaluation.
Definition bmv2/common/midend.h:44
Definition convertEnums.h:20
Definition frontends/common/options.h:31
Class used to encode maps from paths to declarations.
Definition referenceMap.h:67
Definition typeMap.h:32
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition action.cpp:9