P4C
The P4 Compiler
Loading...
Searching...
No Matches
ir-traversal.h
1/*
2Copyright 2024-present Intel Corporation.
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*/
24#ifndef IR_IR_TRAVERSAL_H_
25#define IR_IR_TRAVERSAL_H_
26#define IR_IR_TRAVERSAL_INTERNAL_ENABLE
27
28#include <cstddef>
29
30namespace P4::IR::Traversal {
31
35template <typename T>
36struct Assign {
37 explicit Assign(const T &value) : value(value) {}
38 T value;
39};
40
50struct Index {
51 explicit Index(size_t value) : value(value) {}
52 size_t value;
53};
54
55} // namespace P4::IR::Traversal
56
57// Put the internals out of the main file to increase its readability.
58#include "ir-traversal-internal.h"
59
60namespace P4::IR::Traversal {
61
120template <typename Obj, typename... Selectors>
121Obj *modify(Obj *obj, Selectors &&...selectors) {
122 return Detail::Traverse::modify(obj, std::forward<Selectors>(selectors)...);
123}
124
127template <typename Obj, typename... Selectors>
128Obj *apply(const Obj *obj, Selectors &&...selectors) {
129 return Detail::Traverse::modify(obj->clone(), std::forward<Selectors>(selectors)...);
130}
131
132} // namespace P4::IR::Traversal
133
134#undef IR_IR_TRAVERSAL_INTERNAL_ENABLE
135#endif // IR_IR_TRAVERSAL_H_
A selector used at the end of selector chain to assign to the current sub-object. e....
Definition ir-traversal.h:36
Select an index of a integer-indexed sub-object. This is useful e.g. to select first parameter of a m...
Definition ir-traversal.h:50