P4C
The P4 Compiler
Loading...
Searching...
No Matches
header.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_HEADER_H_
9#define BACKENDS_BMV2_COMMON_HEADER_H_
10
11#include <list>
12
13#include "JsonObjects.h"
14#include "backends/bmv2/common/options.h"
15#include "backends/common/programStructure.h"
16#include "frontends/common/resolveReferences/referenceMap.h"
17#include "frontends/p4/typeMap.h"
18#include "helpers.h"
19#include "ir/ir.h"
20#include "lib/json.h"
21
22namespace P4::BMV2 {
23
24class Backend;
25
26class HeaderConverter : public Inspector {
28 cstring scalarsName;
29 cstring scalarsTypeName;
30 std::set<cstring> visitedHeaders;
31
32 const unsigned boolWidth = 1; // convert booleans to 1-bit integers
33 const unsigned errorWidth = 32; // convert errors to 32-bit integers
34 unsigned scalars_width = 0;
35
36 protected:
38 void addHeaderType(const IR::Type_StructLike *st);
39 void addHeaderField(const cstring &header, const cstring &name, int size, bool is_signed);
40 Util::JsonArray *addHeaderUnionFields(cstring hdrName, const IR::Type_HeaderUnion *type);
41
42 public:
43 void addTypesAndInstances(const IR::Type_StructLike *type, bool meta);
44 void addHeaderStacks(const IR::Type_Struct *type);
45 bool isHeaders(const IR::Type_StructLike *st);
46
47 Visitor::profile_t init_apply(const IR::Node *node) override;
48 void end_apply(const IR::Node *node) override;
49
50 bool preorder(const IR::Parameter *param) override;
51
52 HeaderConverter(ConversionContext *ctxt, cstring scalarsName);
53};
54
55} // namespace P4::BMV2
56
57#endif /* BACKENDS_BMV2_COMMON_HEADER_H_ */
Backend is a the base class for SimpleSwitchBackend and PortableSwitchBackend.
Definition bmv2/common/backend.h:51
Util::JsonArray * pushNewArray(Util::JsonArray *parent)
TODO(hanw): remove.
Definition header.cpp:14
Visitor::profile_t init_apply(const IR::Node *node) override
Definition header.cpp:307
void addTypesAndInstances(const IR::Type_StructLike *type, bool meta)
Definition header.cpp:28
bool preorder(const IR::Parameter *param) override
Definition header.cpp:424
Definition node.h:53
Definition lib/json.h:128
Definition visitor.h:78
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition action.cpp:9
Definition bmv2/common/helpers.h:288