P4C
The P4 Compiler
Loading...
Searching...
No Matches
defaultValues.h
1/*
2Copyright 2023 VMWare, 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 P4_DEFAULTVALUES_H_
18#define P4_DEFAULTVALUES_H_
19
20#include "frontends/common/resolveReferences/referenceMap.h"
21#include "frontends/p4/typeChecking/typeChecker.h"
22#include "frontends/p4/typeMap.h"
23#include "ir/ir.h"
24
25namespace P4 {
26
30class DoDefaultValues final : public Transform {
31 TypeMap *typeMap;
32
33 const IR::Expression *defaultValue(const IR::Expression *expression, const IR::Type *type);
34
35 public:
36 explicit DoDefaultValues(TypeMap *typeMap) : typeMap(typeMap) { CHECK_NULL(typeMap); }
37 const IR::Node *postorder(IR::Dots *dots) override;
38 const IR::Node *postorder(IR::StructExpression *expression) override;
39 const IR::Node *postorder(IR::ListExpression *expression) override;
40 const IR::Node *postorder(IR::HeaderStackExpression *expression) override;
41};
42
43class DefaultValues : public PassManager {
44 public:
45 explicit DefaultValues(TypeMap *typeMap, TypeChecking *typeChecking = nullptr) {
46 if (typeMap != nullptr) {
47 if (!typeChecking) typeChecking = new TypeChecking(nullptr, typeMap, true);
48 passes.push_back(typeChecking);
49 }
50 passes.push_back(new DoDefaultValues(typeMap));
51 }
52};
53
54} // namespace P4
55
56#endif /* P4_DEFAULTVALUES_H_ */
Definition defaultValues.h:43
Definition defaultValues.h:30
Definition node.h:95
Definition 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