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/resolveReferences.h"
21#include "frontends/p4/typeChecking/typeChecker.h"
22#include "frontends/p4/typeMap.h"
23#include "ir/ir.h"
24
25namespace P4 {
26
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 explicit DoExpandLookahead(TypeMap *typeMap, bool expandHeader = true)
64 : typeMap(typeMap), expandHeader(expandHeader) {
65 CHECK_NULL(typeMap);
66 setName("DoExpandLookahead");
67 }
68 Visitor::profile_t init_apply(const IR::Node *node) override {
69 auto rv = Transform::init_apply(node);
70 node->apply(nameGen);
71
72 return rv;
73 }
74
75 const IR::Node *postorder(IR::AssignmentStatement *statement) override;
76 const IR::Node *postorder(IR::MethodCallStatement *statement) override;
77 const IR::Node *preorder(IR::P4Control *control) override {
78 prune();
79 return control;
80 }
81 const IR::Node *preorder(IR::P4Parser *parser) override {
82 newDecls.clear();
83 return parser;
84 }
85 const IR::Node *postorder(IR::P4Parser *parser) override {
86 if (!newDecls.empty()) parser->parserLocals.append(newDecls);
87 return parser;
88 }
89};
90
95 public:
96 explicit ExpandLookahead(TypeMap *typeMap, TypeChecking *typeChecking = nullptr,
97 bool expandHeader = true) {
98 if (!typeChecking) typeChecking = new TypeChecking(nullptr, typeMap);
99 passes.push_back(typeChecking);
100 passes.push_back(new DoExpandLookahead(typeMap, expandHeader));
101 setName("ExpandLookahead");
102 }
103};
104
105} // namespace P4
106
107#endif /* MIDEND_EXPANDLOOKAHEAD_H_ */
Definition expandLookahead.h:40
Definition expandLookahead.h:94
Definition node.h:52
Definition node.h:94
Definition referenceMap.h:36
Definition ir/pass_manager.h:40
Visitor mixin for looking up names in enclosing scopes from the Visitor::Context.
Definition resolveReferences.h:35
Definition visitor.h:424
Definition typeChecker.h:55
Definition typeMap.h:41
Definition visitor.h:78
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24