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/p4/typeChecking/typeChecker.h"
22#include "frontends/p4/typeMap.h"
23#include "ir/ir.h"
24#include "ir/node.h"
25#include "ir/pass_manager.h"
26#include "ir/visitor.h"
27#include "lib/cstring.h"
28#include "lib/null.h"
29#include "lib/safe_vector.h"
30#include "midend/convertEnums.h"
31
32namespace P4 {
33
40 public:
41 virtual ~ChooseErrorRepresentation() = default;
42
44 virtual bool convert(const IR::Type_Error *type) const = 0;
45
50 virtual unsigned errorSize(unsigned errorCount) const = 0;
51
54 virtual IR::IndexedVector<IR::SerEnumMember> *assignValues(IR::Type_Error *type,
55 unsigned width) const;
56};
57
58class DoConvertErrors : public Transform {
59 friend class ConvertErrors;
60
61 std::map<cstring, P4::EnumRepresentation *> repr;
63 P4::TypeMap *typeMap;
64
65 public:
67 : policy(policy), typeMap(typeMap) {
68 CHECK_NULL(policy);
69 CHECK_NULL(typeMap);
70 setName("DoConvertErrors");
71 }
72 const IR::Node *preorder(IR::Type_Error *type) override;
73 const IR::Node *postorder(IR::Type_Name *type) override;
74 const IR::Node *postorder(IR::Member *member) override;
75};
76
77class ConvertErrors : public PassManager {
78 DoConvertErrors *convertErrors{nullptr};
79
80 public:
81 using ErrorMapping = decltype(DoConvertErrors::repr);
83 P4::TypeChecking *typeChecking = nullptr)
84 : convertErrors(new DoConvertErrors(policy, typeMap)) {
85 if (typeChecking == nullptr) {
86 typeChecking = new P4::TypeChecking(nullptr, typeMap);
87 }
88 passes.push_back(typeChecking);
89 passes.push_back(convertErrors);
90 passes.push_back(new P4::ClearTypeMap(typeMap));
91 setName("ConvertErrors");
92 }
93
94 ErrorMapping getErrorMapping() const { return convertErrors->repr; }
95};
96} // namespace P4
97
98#endif /* MIDEND_CONVERTERRORS_H_ */
Definition convertErrors.h:39
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:77
Definition convertErrors.h:58
Definition node.h:52
Definition node.h:94
Definition ir/pass_manager.h:40
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 lib/error.h:35