P4C
The P4 Compiler
Loading...
Searching...
No Matches
expandLookahead.h
1/*
2Copyright 2016 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_EXPANDLOOKAHEAD_H_
18#define MIDEND_EXPANDLOOKAHEAD_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
41 P4::ReferenceMap *refMap;
42 P4::TypeMap *typeMap;
49 bool expandHeader = true;
50
51 struct ExpansionInfo {
52 const IR::Statement *statement;
53 unsigned width;
54 const IR::Type *origType;
55 const IR::PathExpression *tmp; // temporary used for result
56 };
57
58 void expand(const IR::PathExpression *bitvector, const IR::Type *type, unsigned *offset,
59 const IR::Expression *destination, IR::IndexedVector<IR::StatOrDecl> *output);
60 ExpansionInfo *convertLookahead(const IR::MethodCallExpression *expression);
61
62 public:
63 DoExpandLookahead(ReferenceMap *refMap, TypeMap *typeMap, bool expandHeader = true)
64 : refMap(refMap), typeMap(typeMap), expandHeader(expandHeader) {
65 CHECK_NULL(refMap);
66 CHECK_NULL(typeMap);
67 setName("DoExpandLookahead");
68 }
69 const IR::Node *postorder(IR::AssignmentStatement *statement) override;
70 const IR::Node *postorder(IR::MethodCallStatement *statement) override;
71 const IR::Node *preorder(IR::P4Control *control) override {
72 prune();
73 return control;
74 }
75 const IR::Node *preorder(IR::P4Parser *parser) override {
76 newDecls.clear();
77 return parser;
78 }
79 const IR::Node *postorder(IR::P4Parser *parser) override {
80 if (!newDecls.empty()) parser->parserLocals.append(newDecls);
81 return parser;
82 }
83};
84
89 public:
90 ExpandLookahead(ReferenceMap *refMap, TypeMap *typeMap, TypeChecking *typeChecking = nullptr,
91 bool expandHeader = true) {
92 if (!typeChecking) typeChecking = new TypeChecking(refMap, typeMap);
93 passes.push_back(typeChecking);
94 passes.push_back(new DoExpandLookahead(refMap, typeMap, expandHeader));
95 setName("ExpandLookahead");
96 }
97};
98
99} // namespace P4
100
101#endif /* MIDEND_EXPANDLOOKAHEAD_H_ */
Definition expandLookahead.h:40
Definition expandLookahead.h:88
Definition node.h:52
Definition node.h:95
Definition pass_manager.h:40
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
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