P4C
The P4 Compiler
Loading...
Searching...
No Matches
simplifySelectList.h
1/*
2 * Copyright 2017 VMware, Inc.
3 * SPDX-FileCopyrightText: 2017 VMware, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef MIDEND_SIMPLIFYSELECTLIST_H_
9#define MIDEND_SIMPLIFYSELECTLIST_H_
10
11#include "frontends/p4/typeChecking/typeChecker.h"
12#include "frontends/p4/typeMap.h"
13#include "ir/ir.h"
14
15namespace P4 {
16
22class SubstituteStructures : public Transform {
23 TypeMap *typeMap;
24
25 void explode(const IR::Expression *expression, const IR::Type *type,
26 IR::Vector<IR::Expression> *components);
27
28 public:
29 explicit SubstituteStructures(TypeMap *typeMap) : typeMap(typeMap) {
30 CHECK_NULL(typeMap);
31 setName("SubstituteStructures");
32 }
33
34 const IR::Node *postorder(IR::PathExpression *expression) override;
35};
36
54class UnnestSelectList : public Transform {
55 // Represent the nesting of lists inside of a selectExpression.
56 // E.g.: [__[__]_] for two nested lists.
57 // FIXME: Lots of terrible concatenations here, must be std::string
58 cstring nesting;
59
60 void flatten(const IR::Expression *expression, IR::Vector<IR::Expression> *output);
61 void flatten(const IR::Expression *expression, unsigned *nestingIndex,
63
64 public:
65 UnnestSelectList() { setName("UnnestSelectList"); }
66
67 const IR::Node *preorder(IR::SelectExpression *expression) override;
68 const IR::Node *preorder(IR::P4Control *control) override {
69 prune();
70 return control;
71 }
72};
73
74class SimplifySelectList : public PassManager {
75 public:
76 explicit SimplifySelectList(TypeMap *typeMap, TypeChecking *typeChecking = nullptr) {
77 if (!typeChecking) typeChecking = new TypeChecking(nullptr, typeMap);
78 passes.push_back(typeChecking);
79 passes.push_back(new SubstituteStructures(typeMap));
80 passes.push_back(typeChecking);
81 passes.push_back(new UnnestSelectList);
82 setName("SimplifySelectList");
83 }
84};
85
86} // namespace P4
87
88#endif /* MIDEND_SIMPLIFYSELECTLIST_H_ */
Definition node.h:53
Definition ir/vector.h:59
Definition simplifySelectList.h:22
Definition visitor.h:442
Definition typeChecker.h:55
Definition typeMap.h:32
Definition simplifySelectList.h:54
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13