bmv2
Designing your own switch target with bmv2
Loading...
Searching...
No Matches
conditionals.h
1/* Copyright 2013-present Barefoot Networks, Inc.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/*
17 * Antonin Bas (antonin@barefootnetworks.com)
18 *
19 */
20
21#ifndef BM_BM_SIM_CONDITIONALS_H_
22#define BM_BM_SIM_CONDITIONALS_H_
23
24#include <memory>
25#include <string>
26#include <utility>
27
28#include "phv.h"
29#include "control_flow.h"
30#include "expressions.h"
31
32namespace bm {
33
34class Conditional
35 : public ControlFlowNode, public Expression {
36 public:
37 Conditional(const std::string &name, p4object_id_t id)
38 : ControlFlowNode(name, id) {}
39 Conditional(const std::string &name, p4object_id_t id,
40 std::unique_ptr<SourceInfo> source_info)
41 : ControlFlowNode(name, id, std::move(source_info)) {}
42
43 bool eval(const PHV &phv) const {
44 return eval_bool(phv);
45 }
46
47 void set_next_node_if_true(ControlFlowNode *next_node) {
48 true_next = next_node;
49 }
50
51 void set_next_node_if_false(ControlFlowNode *next_node) {
52 false_next = next_node;
53 }
54
55 // return pointer to next control flow node
56 const ControlFlowNode *operator()(Packet *pkt) const override;
57
58 Conditional(const Conditional &other) = delete;
59 Conditional &operator=(const Conditional &other) = delete;
60
61 Conditional(Conditional &&other) /*noexcept*/ = default;
62 Conditional &operator=(Conditional &&other) /*noexcept*/ = default;
63
64 private:
65 ControlFlowNode *true_next{nullptr};
66 ControlFlowNode *false_next{nullptr};
67};
68
69} // namespace bm
70
71#endif // BM_BM_SIM_CONDITIONALS_H_
NamedP4Object & operator=(const NamedP4Object &other)=delete
Deleted copy assignment operator.