P4C
The P4 Compiler
Loading...
Searching...
No Matches
action.h
1
/*
2
Copyright 2013-present Barefoot Networks, Inc.
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7
8
http://www.apache.org/licenses/LICENSE-2.0
9
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16
17
#ifndef BACKENDS_BMV2_COMMON_ACTION_H_
18
#define BACKENDS_BMV2_COMMON_ACTION_H_
19
20
#include "helpers.h"
21
#include "ir/ir.h"
22
23
namespace
P4::BMV2
{
24
28
struct
JumpLabelInfo
{
29
// The number of jump labels that have been created so far, for
30
// the current action where we are generating its primitives.
31
// Jump labels are allocated starting from 0 and incrementing from
32
// there.
33
int
numLabels;
34
// The jump label that is positioned at the end of the action
35
// body. This is needed if we wish to implement a 'return' or
36
// 'exit' statement within a conditionally executed part of an
37
// action body, to jump to the end of the action.
38
int
labelIdEndOfAction;
39
// Let F be the set of offsets in the action that contain a
40
// primitive "_jump" or _jump_if_zero". For each offset f in F,
41
// offsetToTargetLabelId[f] is the label ID to which the primitive
42
// should jump.
43
std::map<unsigned int, unsigned int> offsetToTargetLabelId;
44
// For each offset f in F, offsetToJumpParams[f] is the array
45
// of parameters that should be used as operands to the primitive,
46
// except for the offset, which will only be added at the end of
47
// method convertActionBodyTop.
48
std::map<unsigned int, Util::JsonArray *> offsetToJumpParams;
49
// labelIdToJumpOffset[labelId] equal to offset means that the
50
// position of that labelId within the array of primitives for an
51
// action is 'offset'. _jump and _jump_if_zero primitive actions
52
// must use 'offset' as their offset parameter in order to jump to
53
// that primitive.
54
std::map<unsigned int, unsigned int> labelIdToJumpOffset;
55
};
56
57
class
ActionConverter
:
public
Inspector
{
58
ConversionContext
*ctxt;
59
60
void
convertActionBodyTop(
const
IR::Vector<IR::StatOrDecl>
*body,
Util::JsonArray
*result);
61
void
convertActionBody(
const
IR::Vector<IR::StatOrDecl>
*body,
Util::JsonArray
*result,
62
bool
inConditional,
JumpLabelInfo
*
info
);
63
void
convertActionParams(
const
IR::ParameterList *parameters,
Util::JsonArray
*params);
64
cstring
jsonAssignment(
const
IR::Type *type);
65
void
postorder(
const
IR::P4Action *action)
override
;
66
67
public
:
68
const
bool
emitExterns;
69
explicit
ActionConverter
(
ConversionContext
*ctxt,
const
bool
&emitExterns_)
70
: ctxt(ctxt), emitExterns(emitExterns_) {
71
setName(
"ConvertActions"
);
72
}
73
};
74
75
}
// namespace P4::BMV2
76
77
#endif
/* BACKENDS_BMV2_COMMON_ACTION_H_ */
P4::BMV2::ActionConverter
Definition
action.h:57
P4::IR::Vector
Definition
vector.h:59
P4::Inspector
Definition
visitor.h:400
P4::Util::JsonArray
Definition
json.h:115
P4::cstring
Definition
cstring.h:85
P4::BMV2
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition
action.cpp:21
P4::BMV2::JumpLabelInfo
Definition
action.h:28
P4::info
void info(const int kind, const char *format, const T *node, Args &&...args)
Report info messages of type kind. Requires that the node argument have source info.
Definition
lib/error.h:148
P4::BMV2::ConversionContext
Definition
bmv2/common/helpers.h:297
backends
bmv2
common
action.h
Generated by
1.12.0