P4C
The P4 Compiler
Loading...
Searching...
No Matches
removeExits.h
1/*
2Copyright 2017 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 MIDEND_REMOVEEXITS_H_
18#define MIDEND_REMOVEEXITS_H_
19
20#include "frontends/common/resolveReferences/resolveReferences.h"
21#include "frontends/p4/removeReturns.h"
22
23namespace P4 {
24
36 TypeMap *typeMap;
37 // In this class "Return" (inherited from RemoveReturns) should be read as "Exit"
38 std::set<const IR::Node *> callsExit; // actions, tables
39 void callExit(const IR::Node *node);
40
41 public:
42 explicit DoRemoveExits(TypeMap *typeMap) : DoRemoveReturns("hasExited"_cs), typeMap(typeMap) {
43 visitDagOnce = false;
44 CHECK_NULL(typeMap);
45 setName("DoRemoveExits");
46 }
47
48 const IR::Node *preorder(IR::ExitStatement *action) override;
49 const IR::Node *preorder(IR::P4Table *table) override;
50
51 const IR::Node *preorder(IR::BlockStatement *statement) override;
52 const IR::Node *preorder(IR::IfStatement *statement) override;
53 const IR::Node *preorder(IR::SwitchStatement *statement) override;
54 const IR::Node *preorder(IR::AssignmentStatement *statement) override;
55 const IR::Node *preorder(IR::MethodCallStatement *statement) override;
56
57 const IR::Node *preorder(IR::P4Action *action) override;
58 const IR::Node *preorder(IR::P4Control *control) override;
59};
60
61class RemoveExits : public PassManager {
62 public:
63 explicit RemoveExits(TypeMap *typeMap, TypeChecking *typeChecking = nullptr) {
64 if (!typeChecking) typeChecking = new TypeChecking(nullptr, typeMap);
65 passes.push_back(typeChecking);
66 passes.push_back(new DoRemoveExits(typeMap));
67 setName("RemoveExits");
68 }
69};
70
71} // namespace P4
72
73#endif /* MIDEND_REMOVEEXITS_H_ */
Definition removeExits.h:35
Definition removeReturns.h:121
Definition node.h:95
Definition ir/pass_manager.h:40
Definition removeExits.h:61
Visitor mixin for looking up names in enclosing scopes from the Visitor::Context.
Definition resolveReferences.h:35
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