P4C
The P4 Compiler
Loading...
Searching...
No Matches
action.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 BACKENDS_BMV2_COMMON_ACTION_H_
9
#define BACKENDS_BMV2_COMMON_ACTION_H_
10
11
#include "helpers.h"
12
#include "ir/ir.h"
13
14
namespace
P4::BMV2
{
15
19
struct
JumpLabelInfo
{
20
// The number of jump labels that have been created so far, for
21
// the current action where we are generating its primitives.
22
// Jump labels are allocated starting from 0 and incrementing from
23
// there.
24
int
numLabels;
25
// The jump label that is positioned at the end of the action
26
// body. This is needed if we wish to implement a 'return' or
27
// 'exit' statement within a conditionally executed part of an
28
// action body, to jump to the end of the action.
29
int
labelIdEndOfAction;
30
// Label ID for the end of the innermost enclosing loop (break target).
31
// -1 means we are not inside any loop.
32
int
labelIdBreak = -1;
33
// Label ID for the update section of the innermost enclosing loop (continue target).
34
// -1 means we are not inside any loop.
35
int
labelIdContinue = -1;
36
// Let F be the set of offsets in the action that contain a
37
// primitive "_jump" or _jump_if_zero". For each offset f in F,
38
// offsetToTargetLabelId[f] is the label ID to which the primitive
39
// should jump.
40
std::map<unsigned int, unsigned int> offsetToTargetLabelId;
41
// For each offset f in F, offsetToJumpParams[f] is the array
42
// of parameters that should be used as operands to the primitive,
43
// except for the offset, which will only be added at the end of
44
// method convertActionBodyTop.
45
std::map<unsigned int, Util::JsonArray *> offsetToJumpParams;
46
// labelIdToJumpOffset[labelId] equal to offset means that the
47
// position of that labelId within the array of primitives for an
48
// action is 'offset'. _jump and _jump_if_zero primitive actions
49
// must use 'offset' as their offset parameter in order to jump to
50
// that primitive.
51
std::map<unsigned int, unsigned int> labelIdToJumpOffset;
52
};
53
54
class
ActionConverter :
public
Inspector {
55
ConversionContext
*ctxt;
56
57
void
convertActionBodyTop(
const
IR::Vector<IR::StatOrDecl>
*body,
Util::JsonArray
*result);
58
void
convertActionBody(
const
IR::Vector<IR::StatOrDecl>
*body,
Util::JsonArray
*result,
59
bool
inConditional,
JumpLabelInfo
*
info
);
60
void
convertActionParams(
const
IR::ParameterList *parameters,
Util::JsonArray
*params);
61
cstring
jsonAssignment(
const
IR::Type *type);
62
void
postorder(
const
IR::P4Action *action)
override
;
63
64
public
:
65
const
bool
emitExterns;
66
explicit
ActionConverter(
ConversionContext
*ctxt,
const
bool
&emitExterns_)
67
: ctxt(ctxt), emitExterns(emitExterns_) {
68
setName(
"ConvertActions"
);
69
}
70
};
71
72
}
// namespace P4::BMV2
73
74
#endif
/* BACKENDS_BMV2_COMMON_ACTION_H_ */
P4::IR::Vector
Definition
ir/vector.h:59
P4::Util::JsonArray
Definition
lib/json.h:128
P4::cstring
Definition
cstring.h:85
P4::BMV2
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition
action.cpp:9
P4::BMV2::JumpLabelInfo
Definition
action.h:19
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:167
P4::BMV2::ConversionContext
Definition
bmv2/common/helpers.h:288
backends
bmv2
common
action.h
Generated by
1.13.2