17#ifndef FRONTENDS_P4_SPECIALIZEGENERICTYPES_H_
18#define FRONTENDS_P4_SPECIALIZEGENERICTYPES_H_
20#include "frontends/p4/typeChecking/typeChecker.h"
59 void dbprint(std::ostream &out)
const override {
77 std::string
name()
const;
94 static std::optional<SpecSignature>
get(
const IR::Type_Specialized *spec);
97std::string toString(
const SpecSignature &);
103 void add(
const IR::Type_Specialized *t,
const IR::Type_StructLike *decl,
107 void dbprint(std::ostream &out)
const override {
108 for (
auto it : map) {
109 out << toString(it.first) <<
" => " << it.second << std::endl;
118 void markDefined(
const IR::Type_Declaration *tdec);
121 friend class CreateSpecializedTypes;
122 void fillInsertionSet(
const IR::Type_StructLike *decl,
InsertionSet &insertion);
128class FindTypeSpecializations :
public Inspector, ResolutionContext {
135 setName(
"FindTypeSpecializations");
138 void postorder(
const IR::Type_Specialized *type)
override;
128class FindTypeSpecializations :
public Inspector, ResolutionContext {
…};
146class CreateSpecializedTypes :
public Modifier,
public ResolutionContext {
152 setName(
"CreateSpecializedTypes");
155 void postorder(IR::Type_Specialized *type)
override;
156 void postorder(IR::P4Program *prog)
override;
146class CreateSpecializedTypes :
public Modifier,
public ResolutionContext {
…};
168 setName(
"ReplaceTypeUses");
171 const IR::Node *postorder(IR::Type_Specialized *type)
override;
172 const IR::Node *postorder(IR::StructExpression *expresison)
override;
192class SpecializeGenericTypes :
public PassRepeated {
196 explicit SpecializeGenericTypes(
TypeMap *typeMap) {
197 passes.emplace_back(
new PassRepeated({
204 passes.emplace_back(
new TypeChecking(
nullptr, typeMap));
208 specMap.typeMap = typeMap;
209 setName(
"SpecializeGenericTypes");
210 setStopOnError(
true);
192class SpecializeGenericTypes :
public PassRepeated {
…};
219 const IR::Node *postorder(IR::Type_StructLike *type)
override {
220 if (!type->typeParameters->empty())
return nullptr;
223 const IR::Node *postorder(IR::Type_Stack *type)
override {
224 if (type->elementType->is<IR::Type_Specialized>())
return nullptr;
Definition typeChecker.h:32
Definition specializeGenericTypes.h:146
Definition specializeGenericTypes.h:128
Definition stringify.h:33
Definition ir/vector.h:59
Definition referenceMap.h:36
Definition referenceMap.h:29
Removes all structs or stacks that are generic.
Definition specializeGenericTypes.h:217
Definition specializeGenericTypes.h:163
Definition typeChecker.h:55
Definition ordered_map.h:32
Definition safe_vector.h:27
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
absl::flat_hash_set< P4::cstring > InsertionSet
Set of type declaration names that must be defined before the type can be inserted.
Definition specializeGenericTypes.h:26
std::ostream & format_container(std::ostream &out, const Cont &container, char lbrace, char rbrace)
Definition log.h:164
A signature of a concrete specialization. None of the parameters can be type variables or generic typ...
Definition specializeGenericTypes.h:69
cstring baseType
Name of the type declaration of the base (unspecialized) type (i.e. the struct/header)
Definition specializeGenericTypes.h:72
static std::optional< SpecSignature > get(const IR::Type_Specialized *spec)
Get a specialization signature if it is valid (i.e. the type is specialized only by concrete non-gene...
Definition specializeGenericTypes.cpp:229
std::string name() const
Get a candidate name for the instantiation.
Definition specializeGenericTypes.cpp:215
bool operator<(const SpecSignature &other) const
Order for the sake of std::map only, the requirements are:
Definition specializeGenericTypes.h:84
safe_vector< cstring > arguments
String representation of the type argument names.
Definition specializeGenericTypes.h:74
Definition specializeGenericTypes.h:28
const IR::Vector< IR::Type > * argumentTypes
Definition specializeGenericTypes.h:42
const IR::Type_StructLike * replacement
New synthesized type (created later)
Definition specializeGenericTypes.h:36
bool inserted
was this specialization already inserted?
Definition specializeGenericTypes.h:44
InsertionSet insertion
Definition specializeGenericTypes.h:39
const IR::Type_Declaration * declaration
Declaration of specialized type, which will be replaced.
Definition specializeGenericTypes.h:34
const IR::Type_Specialized * specialized
Type that is being specialized.
Definition specializeGenericTypes.h:32
cstring name
Name to use for specialized type.
Definition specializeGenericTypes.h:30
Definition specializeGenericTypes.h:99
void markDefined(const IR::Type_Declaration *tdec)
Mark the tdec as already present and therefore remove it from required definitions for specialization...
Definition specializeGenericTypes.cpp:36
const IR::Type_Declaration * nextAvailable()
Get a single specialization that is already available (i.e. it does not require any additional defini...
Definition specializeGenericTypes.cpp:24