P4C
The P4 Compiler
Loading...
Searching...
No Matches
header.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
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*/
16
17#ifndef BACKENDS_BMV2_COMMON_HEADER_H_
18#define BACKENDS_BMV2_COMMON_HEADER_H_
19
20#include <list>
21
22#include "JsonObjects.h"
23#include "backends/bmv2/common/options.h"
24#include "backends/common/programStructure.h"
25#include "frontends/common/resolveReferences/referenceMap.h"
26#include "frontends/p4/typeMap.h"
27#include "helpers.h"
28#include "ir/ir.h"
29#include "lib/json.h"
30
31namespace P4::BMV2 {
32
33class Backend;
34
35class HeaderConverter : public Inspector {
37 cstring scalarsName;
38 cstring scalarsTypeName;
39 std::set<cstring> visitedHeaders;
40
41 const unsigned boolWidth = 1; // convert booleans to 1-bit integers
42 const unsigned errorWidth = 32; // convert errors to 32-bit integers
43 unsigned scalars_width = 0;
44
45 protected:
47 void addHeaderType(const IR::Type_StructLike *st);
48 void addHeaderField(const cstring &header, const cstring &name, int size, bool is_signed);
49 Util::JsonArray *addHeaderUnionFields(cstring hdrName, const IR::Type_HeaderUnion *type);
50
51 public:
52 void addTypesAndInstances(const IR::Type_StructLike *type, bool meta);
53 void addHeaderStacks(const IR::Type_Struct *type);
54 bool isHeaders(const IR::Type_StructLike *st);
55
56 Visitor::profile_t init_apply(const IR::Node *node) override;
57 void end_apply(const IR::Node *node) override;
58
59 bool preorder(const IR::Parameter *param) override;
60
61 HeaderConverter(ConversionContext *ctxt, cstring scalarsName);
62};
63
64} // namespace P4::BMV2
65
66#endif /* BACKENDS_BMV2_COMMON_HEADER_H_ */
Definition header.h:35
Util::JsonArray * pushNewArray(Util::JsonArray *parent)
TODO(hanw): remove.
Definition header.cpp:25
Visitor::profile_t init_apply(const IR::Node *node) override
Definition header.cpp:318
void addTypesAndInstances(const IR::Type_StructLike *type, bool meta)
Definition header.cpp:39
bool preorder(const IR::Parameter *param) override
Definition header.cpp:435
Definition node.h:94
Definition visitor.h:400
Definition json.h:115
Definition visitor.h:78
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition action.cpp:21
Definition bmv2/common/helpers.h:297