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
46
47 std::vector<const IR::ExternBlock *> globals;
48
49 public:
50 PortableProgramStructure(P4::ReferenceMap *refMap, P4::TypeMap *typeMap)
51 : refMap(refMap), typeMap(typeMap) {
52 CHECK_NULL(refMap);
53 CHECK_NULL(typeMap);
54 }
55
56 std::set<cstring> non_pipeline_controls;
57 std::set<cstring> pipeline_controls;
58
59 bool hasVisited(const IR::Type_StructLike *st) {
60 if (auto h = st->to<IR::Type_Header>())
61 return header_types.count(h->getName());
62 else if (auto s = st->to<IR::Type_Struct>())
63 return metadata_types.count(s->getName());
64 else if (auto u = st->to<IR::Type_HeaderUnion>())
65 return header_union_types.count(u->getName());
66 return false;
67 }
68};
69
71 public:
72 bool preorder(const IR::ToplevelBlock *block) override;
73};
74
75class InspectPortableProgram : public Inspector {
76 protected:
77 P4::ReferenceMap *refMap;
78 P4::TypeMap *typeMap;
79
80 public:
81 InspectPortableProgram(P4::ReferenceMap *refMap, P4::TypeMap *typeMap)
82 : refMap(refMap), typeMap(typeMap) {
83 CHECK_NULL(refMap);
84 CHECK_NULL(typeMap);
85 }
86
87 bool isHeaders(const IR::Type_StructLike *st);
88};
89
90} // namespace P4
91
92#endif /* BACKENDS_COMMON_PORTABLEPROGRAMSTRUCTURE_H_ */
Definition visitor.h:418
Definition portableProgramStructure.h:70
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:67
Definition typeMap.h:32
Definition ordered_map.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13