P4C
The P4 Compiler
Loading...
Searching...
No Matches
inline_control_flow.h
1/*
2 * SPDX-FileCopyrightText: 2013 Barefoot Networks, Inc.
3 * Copyright 2013-present Barefoot Networks, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef FRONTENDS_P4_14_INLINE_CONTROL_FLOW_H_
9#define FRONTENDS_P4_14_INLINE_CONTROL_FLOW_H_
10
11#include "frontends/p4/evaluator/evaluator.h"
12#include "ir/ir.h"
13
14namespace P4 {
15
16class InlineControlFlow : public Transform {
17 public:
18 explicit InlineControlFlow(const IR::V1Program *gl) : global(gl) {
19 setName("InlineControlFlow");
20 }
21
22 private:
23 const IR::V1Program *global;
24
25 const IR::Node *preorder(IR::Apply *a) override {
26 if (global && !global->get<IR::V1Table>(a->name))
27 error("%s: No table named %s", a->srcInfo, a->name);
28 return a;
29 }
30 const IR::Node *preorder(IR::Primitive *p) override {
31 if (auto cf = global ? global->get<IR::V1Control>(p->name) : 0) {
32 const IR::V1Control *control;
33 if (auto act = findContext<IR::ActionFunction>())
34 error("%s: Trying to call control flow %s in action %s", p->srcInfo, p->name,
35 act->name);
36 else if (auto table = findContext<IR::V1Table>())
37 error("%s: Trying to call control flow %s in table %s", p->srcInfo, p->name,
38 table->name);
39 else if ((control = findContext<IR::V1Control>()) && control->name == p->name)
40 error("%s: Recursive call to control flow %s", p->srcInfo, p->name);
41 else
42 return cf->code;
43 }
44 return p;
45 }
46};
47
48} // namespace P4
49
50#endif /* FRONTENDS_P4_14_INLINE_CONTROL_FLOW_H_ */
Definition node.h:53
Definition visitor.h:442
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:58