8#ifndef FRONTENDS_P4_SPECIALIZEGENERICTYPES_H_
9#define FRONTENDS_P4_SPECIALIZEGENERICTYPES_H_
11#include "frontends/p4/typeChecking/typeChecker.h"
50 void dbprint(std::ostream &out)
const override {
68 std::string
name()
const;
85 static std::optional<SpecSignature>
get(
const IR::Type_Specialized *spec);
88std::string toString(
const SpecSignature &);
94 void add(
const IR::Type_Specialized *t,
const IR::Type_StructLike *decl,
98 void dbprint(std::ostream &out)
const override {
100 out << toString(it.first) <<
" => " << it.second << std::endl;
109 void markDefined(
const IR::Type_Declaration *tdec);
112 friend class CreateSpecializedTypes;
113 void fillInsertionSet(
const IR::Type_StructLike *decl,
InsertionSet &insertion);
119class FindTypeSpecializations :
public Inspector, ResolutionContext {
126 setName(
"FindTypeSpecializations");
129 void postorder(
const IR::Type_Specialized *type)
override;
137class CreateSpecializedTypes :
public Modifier,
public ResolutionContext {
143 setName(
"CreateSpecializedTypes");
146 void postorder(IR::Type_Specialized *type)
override;
147 void postorder(IR::P4Program *prog)
override;
159 setName(
"ReplaceTypeUses");
162 const IR::Node *postorder(IR::Type_Specialized *type)
override;
163 const IR::Node *postorder(IR::StructExpression *expresison)
override;
183class SpecializeGenericTypes :
public PassRepeated {
187 explicit SpecializeGenericTypes(
TypeMap *typeMap) {
188 passes.emplace_back(
new PassRepeated({
195 passes.emplace_back(
new TypeChecking(
nullptr, typeMap));
199 specMap.typeMap = typeMap;
200 setName(
"SpecializeGenericTypes");
201 setStopOnError(
true);
210 const IR::Node *postorder(IR::Type_StructLike *type)
override {
211 if (!type->typeParameters->empty())
return nullptr;
214 const IR::Node *postorder(IR::Type_Array *type)
override {
215 if (type->elementType->is<IR::Type_Specialized>())
return nullptr;
Definition typeChecker.h:32
Definition specializeGenericTypes.h:137
Definition specializeGenericTypes.h:119
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:208
Definition specializeGenericTypes.h:154
Definition typeChecker.h:55
Definition ordered_map.h:32
Definition safe_vector.h:18
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13
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:17
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:60
cstring baseType
Name of the type declaration of the base (unspecialized) type (i.e. the struct/header)
Definition specializeGenericTypes.h:63
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:218
std::string name() const
Get a candidate name for the instantiation.
Definition specializeGenericTypes.cpp:204
bool operator<(const SpecSignature &other) const
Order for the sake of std::map only, the requirements are:
Definition specializeGenericTypes.h:75
safe_vector< cstring > arguments
String representation of the type argument names.
Definition specializeGenericTypes.h:65
Definition specializeGenericTypes.h:19
const IR::Vector< IR::Type > * argumentTypes
Definition specializeGenericTypes.h:33
const IR::Type_StructLike * replacement
New synthesized type (created later)
Definition specializeGenericTypes.h:27
bool inserted
was this specialization already inserted?
Definition specializeGenericTypes.h:35
InsertionSet insertion
Definition specializeGenericTypes.h:30
const IR::Type_Declaration * declaration
Declaration of specialized type, which will be replaced.
Definition specializeGenericTypes.h:25
const IR::Type_Specialized * specialized
Type that is being specialized.
Definition specializeGenericTypes.h:23
cstring name
Name to use for specialized type.
Definition specializeGenericTypes.h:21
Definition specializeGenericTypes.h:90
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:25
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:13