P4C
The P4 Compiler
Loading...
Searching...
No Matches
dontcareArgs.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 FRONTENDS_P4_DONTCAREARGS_H_
9#define FRONTENDS_P4_DONTCAREARGS_H_
10
11#include "frontends/common/resolveReferences/resolveReferences.h"
12#include "frontends/p4/typeChecking/typeChecker.h"
13#include "ir/ir.h"
14
15namespace P4 {
16
19class DontcareArgs : public Transform, public ResolutionContext {
21 TypeMap *typeMap;
23
24 public:
25 explicit DontcareArgs(TypeMap *typeMap) : typeMap(typeMap) {
26 CHECK_NULL(typeMap);
27 setName("DontcareArgs");
28 }
29 const IR::Node *postorder(IR::MethodCallExpression *expression) override;
30 const IR::Node *postorder(IR::Function *function) override {
31 if (!toAdd.empty()) {
33 for (auto d : toAdd) body.push_back(d);
34 body.append(function->body->components);
35 function->body =
36 new IR::BlockStatement(function->body->srcInfo, function->body->annotations, body);
37 toAdd.clear();
38 }
39 return function;
40 }
41 const IR::Node *postorder(IR::P4Action *action) override {
42 if (!toAdd.empty()) {
44 for (auto d : toAdd) body.push_back(d);
45 body.append(action->body->components);
46 action->body =
47 new IR::BlockStatement(action->body->srcInfo, action->body->annotations, body);
48 toAdd.clear();
49 }
50 return action;
51 }
52 const IR::Node *postorder(IR::P4Parser *parser) override {
53 if (!toAdd.empty()) {
54 toAdd.append(parser->parserLocals);
55 parser->parserLocals = toAdd;
56 toAdd.clear();
57 }
58 return parser;
59 }
60 const IR::Node *postorder(IR::P4Control *control) override {
61 if (!toAdd.empty()) {
62 toAdd.append(control->controlLocals);
63 control->controlLocals = toAdd;
64 toAdd.clear();
65 }
66 return control;
67 }
68 profile_t init_apply(const IR::Node *node) override;
69};
70
71class RemoveDontcareArgs : public PassManager {
72 public:
73 explicit RemoveDontcareArgs(TypeMap *typeMap) {
74 passes.push_back(new TypeChecking(nullptr, typeMap));
75 passes.push_back(new DontcareArgs(typeMap));
76 passes.push_back(new ClearTypeMap(typeMap));
77 setName("RemoveDontcareArgs");
78 }
79};
80
81} // namespace P4
82
83#endif /* FRONTENDS_P4_DONTCAREARGS_H_ */
Definition typeChecker.h:32
Definition dontcareArgs.h:19
Definition indexed_vector.h:31
Definition node.h:53
Definition referenceMap.h:36
Definition visitor.h:442
Definition typeChecker.h:55
Definition typeMap.h:32
Definition visitor.h:78
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13