P4C
The P4 Compiler
Loading...
Searching...
No Matches
convertErrors.h
1/*
2 * Copyright 2021 Intel Corporation
3 * SPDX-FileCopyrightText: 2021 Intel Corporation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef MIDEND_CONVERTERRORS_H_
9#define MIDEND_CONVERTERRORS_H_
10
11#include <map>
12
13#include "frontends/p4/typeChecking/typeChecker.h"
14#include "frontends/p4/typeMap.h"
15#include "ir/ir.h"
16#include "ir/node.h"
17#include "ir/pass_manager.h"
18#include "ir/visitor.h"
19#include "lib/cstring.h"
20#include "lib/null.h"
21#include "lib/safe_vector.h"
22#include "midend/convertEnums.h"
23
24namespace P4 {
25
32 public:
33 virtual ~ChooseErrorRepresentation() = default;
34
36 virtual bool convert(const IR::Type_Error *type) const = 0;
37
42 virtual unsigned errorSize(unsigned errorCount) const = 0;
43
46 virtual IR::IndexedVector<IR::SerEnumMember> *assignValues(IR::Type_Error *type,
47 unsigned width) const;
48};
49
50class DoConvertErrors : public Transform {
51 friend class ConvertErrors;
52
53 std::map<cstring, P4::EnumRepresentation *> repr;
55 P4::TypeMap *typeMap;
56
57 public:
58 DoConvertErrors(ChooseErrorRepresentation *policy, P4::TypeMap *typeMap)
59 : policy(policy), typeMap(typeMap) {
60 CHECK_NULL(policy);
61 CHECK_NULL(typeMap);
62 setName("DoConvertErrors");
63 }
64 const IR::Node *preorder(IR::Type_Error *type) override;
65 const IR::Node *postorder(IR::Type_Name *type) override;
66 const IR::Node *postorder(IR::Member *member) override;
67};
68
69class ConvertErrors : public PassManager {
70 DoConvertErrors *convertErrors{nullptr};
71
72 public:
73 using ErrorMapping = decltype(DoConvertErrors::repr);
74 ConvertErrors(P4::TypeMap *typeMap, ChooseErrorRepresentation *policy,
75 P4::TypeChecking *typeChecking = nullptr)
76 : convertErrors(new DoConvertErrors(policy, typeMap)) {
77 if (typeChecking == nullptr) {
78 typeChecking = new P4::TypeChecking(nullptr, typeMap);
79 }
80 passes.push_back(typeChecking);
81 passes.push_back(convertErrors);
82 passes.push_back(new P4::ClearTypeMap(typeMap));
83 setName("ConvertErrors");
84 }
85
86 ErrorMapping getErrorMapping() const { return convertErrors->repr; }
87};
88} // namespace P4
89
90#endif /* MIDEND_CONVERTERRORS_H_ */
Definition convertErrors.h:31
virtual unsigned errorSize(unsigned errorCount) const =0
virtual IR::IndexedVector< IR::SerEnumMember > * assignValues(IR::Type_Error *type, unsigned width) const
Definition convertErrors.cpp:74
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:50
Definition indexed_vector.h:31
Definition node.h:53
Definition visitor.h:442
Definition typeChecker.h:55
Definition typeMap.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13
unsigned errorCount()
Definition lib/error.h:34