P4C
The P4 Compiler
Loading...
Searching...
No Matches
portableProgramStructure.h
1/*
2 * Copyright 2024 Marvell Technology, Inc.
3 * SPDX-FileCopyrightText: 2024 Marvell Technology, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef BACKENDS_COMMON_PORTABLEPROGRAMSTRUCTURE_H_
9#define BACKENDS_COMMON_PORTABLEPROGRAMSTRUCTURE_H_
10
11#include "backends/common/programStructure.h"
12#include "frontends/common/resolveReferences/referenceMap.h"
13#include "frontends/p4/typeMap.h"
14#include "ir/ir.h"
15#include "lib/cstring.h"
16
18namespace P4 {
19
20class PortableProgramStructure : public P4::ProgramStructure {
21 public:
22 P4::ReferenceMap *refMap;
23 P4::TypeMap *typeMap;
24
28 unsigned scalars_width = 0;
29 unsigned bool_width = 1;
30
48
49 std::vector<const IR::ExternBlock *> globals;
50
51 public:
52 PortableProgramStructure(P4::ReferenceMap *refMap, P4::TypeMap *typeMap)
53 : refMap(refMap), typeMap(typeMap) {
54 CHECK_NULL(refMap);
55 CHECK_NULL(typeMap);
56 }
57
58 std::set<cstring> non_pipeline_controls;
59 std::set<cstring> pipeline_controls;
60
61 bool hasVisited(const IR::Type_StructLike *st) {
62 if (auto h = st->to<IR::Type_Header>())
63 return header_types.count(h->getName());
64 else if (auto s = st->to<IR::Type_Struct>())
65 return metadata_types.count(s->getName());
66 else if (auto u = st->to<IR::Type_HeaderUnion>())
67 return header_union_types.count(u->getName());
68 return false;
69 }
70};
71
73 public:
74 bool preorder(const IR::ToplevelBlock *block) override;
75};
76
77class InspectPortableProgram : public Inspector {
78 protected:
79 P4::ReferenceMap *refMap;
80 P4::TypeMap *typeMap;
81
82 public:
83 InspectPortableProgram(P4::ReferenceMap *refMap, P4::TypeMap *typeMap)
84 : refMap(refMap), typeMap(typeMap) {
85 CHECK_NULL(refMap);
86 CHECK_NULL(typeMap);
87 }
88
89 bool isHeaders(const IR::Type_StructLike *st);
90};
91
92} // namespace P4
93
94#endif /* BACKENDS_COMMON_PORTABLEPROGRAMSTRUCTURE_H_ */
Definition visitor.h:409
Definition portableProgramStructure.h:72
ordered_map< cstring, const IR::Declaration_Variable * > scalars
Definition portableProgramStructure.h:27
Definition backends/common/programStructure.h:23
Class used to encode maps from paths to declarations.
Definition referenceMap.h:58
Definition typeMap.h:32
Definition ordered_map.h:23
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13