P4C
The P4 Compiler
Loading...
Searching...
No Matches
simplifyExternMethod.h
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef MIDEND_SIMPLIFYEXTERNMETHOD_H_
19#define MIDEND_SIMPLIFYEXTERNMETHOD_H_
20
21#include "frontends/common/resolveReferences/resolveReferences.h"
22#include "frontends/p4/typeChecking/typeChecker.h"
23#include "ir/ir.h"
24#include "ir/visitor.h"
25
26namespace P4 {
27
47
48class SimplifyExternMethodCalls : public Transform, public ResolutionContext {
49 // FIXME -- would prefer not to require the typemap, but the type in
50 // MethodCallExpressions has generally not been updated properly
51 TypeMap *typeMap;
53 std::vector<const IR::Declaration_Variable *> newTemps;
54 std::vector<const IR::AssignmentStatement *> newCopies;
55
56 Visitor::profile_t init_apply(const IR::Node *root) override {
57 Visitor::profile_t rv = Transform::init_apply(root);
58 root->apply(nameGen);
59 return rv;
60 }
61 void end_apply() override {
62 BUG_CHECK(newTemps.empty() && newCopies.empty(),
63 "Not all newly created statements found a home");
64 }
65
66 const IR::Expression *preorder(IR::MethodCallExpression *mce) override;
67 const IR::Node *postorder(IR::Statement *stmt) override;
68 const IR::BlockStatement *postorder(IR::BlockStatement *block) override;
69
70 // Don't touch parsers -- they have their own rules
71 const IR::P4Parser *preorder(IR::P4Parser *p) override {
72 prune();
73 return p;
74 }
75
76 public:
77 explicit SimplifyExternMethodCalls(TypeMap *tm) : typeMap(tm) {}
78};
79
80} // namespace P4
81
82#endif /* MIDEND_SIMPLIFYEXTERNMETHOD_H_ */
Definition node.h:94
Definition referenceMap.h:36
Definition visitor.h:437
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