P4C
The P4 Compiler
Loading...
Searching...
No Matches
p4-14/actionsInlining.h
1/*
2Copyright 2013-present Barefoot Networks, 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 FRONTENDS_P4_14_ACTIONSINLINING_H_
18#define FRONTENDS_P4_14_ACTIONSINLINING_H_
19
20#include "ir/ir.h"
21
22namespace P4::P4_14 {
23
25class InlineActions : public Transform {
26 const IR::V1Program *global;
27 class SubstActionArgs : public Transform {
28 const IR::ActionFunction *function;
29 const IR::Primitive *callsite;
30 const IR::Node *postorder(IR::ActionArg *arg) override {
31 for (unsigned i = 0; i < function->args.size(); ++i)
32 if (function->args[i] == getOriginal()) return callsite->operands[i];
33 BUG("Action arg not argument of action");
34 return arg;
35 }
36
37 public:
38 SubstActionArgs(const IR::ActionFunction *f, const IR::Primitive *c)
39 : function(f), callsite(c) {}
40 };
41
42 const IR::V1Program *preorder(IR::V1Program *gl) override { return global = gl; }
43 const IR::Node *preorder(IR::Primitive *p) override {
44 if (auto af = global->get<IR::ActionFunction>(p->name)) {
45 SubstActionArgs saa(af, p);
46 saa.setCalledBy(this);
47 return af->action.clone()->apply(saa);
48 }
49 return p;
50 }
51};
52
53} // namespace P4::P4_14
54
55#endif /* FRONTENDS_P4_14_ACTIONSINLINING_H_ */
Definition node.h:44
Special inliner which works directly on P4-14 representation.
Definition p4-14/actionsInlining.h:25