P4C
The P4 Compiler
Loading...
Searching...
No Matches
convertErrors.h
1/* Copyright 2021 Intel Corporation
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14*/
15
16#ifndef MIDEND_CONVERTERRORS_H_
17#define MIDEND_CONVERTERRORS_H_
18
19#include <map>
20
21#include "frontends/common/resolveReferences/referenceMap.h"
22#include "frontends/p4/typeChecking/typeChecker.h"
23#include "frontends/p4/typeMap.h"
24#include "ir/ir.h"
25#include "ir/node.h"
26#include "ir/pass_manager.h"
27#include "ir/visitor.h"
28#include "lib/cstring.h"
29#include "lib/null.h"
30#include "lib/safe_vector.h"
31#include "midend/convertEnums.h"
32
33namespace P4 {
34
41 public:
42 virtual ~ChooseErrorRepresentation() = default;
43
45 virtual bool convert(const IR::Type_Error *type) const = 0;
46
51 virtual unsigned errorSize(unsigned errorCount) const = 0;
52
55 virtual IR::IndexedVector<IR::SerEnumMember> *assignValues(IR::Type_Error *type,
56 unsigned width) const;
57};
58
59class DoConvertErrors : public Transform {
60 friend class ConvertErrors;
61
62 std::map<cstring, P4::EnumRepresentation *> repr;
64 P4::TypeMap *typeMap;
65
66 public:
68 : policy(policy), typeMap(typeMap) {
69 CHECK_NULL(policy);
70 CHECK_NULL(typeMap);
71 setName("DoConvertErrors");
72 }
73 const IR::Node *preorder(IR::Type_Error *type) override;
74 const IR::Node *postorder(IR::Type_Name *type) override;
75 const IR::Node *postorder(IR::Member *member) override;
76};
77
78class ConvertErrors : public PassManager {
79 DoConvertErrors *convertErrors{nullptr};
80
81 public:
82 using ErrorMapping = decltype(DoConvertErrors::repr);
84 P4::TypeChecking *typeChecking = nullptr)
85 : convertErrors(new DoConvertErrors(policy, typeMap)) {
86 if (typeChecking == nullptr) {
87 typeChecking = new P4::TypeChecking(refMap, typeMap);
88 }
89 passes.push_back(typeChecking);
90 passes.push_back(convertErrors);
91 passes.push_back(new P4::ClearTypeMap(typeMap));
92 setName("ConvertErrors");
93 }
94
95 ErrorMapping getErrorMapping() const { return convertErrors->repr; }
96};
97} // namespace P4
98
99#endif /* MIDEND_CONVERTERRORS_H_ */
Definition convertErrors.h:40
virtual unsigned errorSize(unsigned errorCount) const =0
virtual IR::IndexedVector< IR::SerEnumMember > * assignValues(IR::Type_Error *type, unsigned width) const
Definition convertErrors.cpp:70
virtual bool convert(const IR::Type_Error *type) const =0
If true this type has to be converted.
Definition typeChecker.h:32
Definition convertErrors.h:78
Definition convertErrors.h:59
Definition node.h:52
Definition node.h:95
Definition 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
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
unsigned errorCount()
Definition error.h:35