17#ifndef FRONTENDS_P4_SPECIALIZEGENERICTYPES_H_
18#define FRONTENDS_P4_SPECIALIZEGENERICTYPES_H_
20#include "frontends/common/resolveReferences/referenceMap.h"
21#include "frontends/p4/typeChecking/typeChecker.h"
55 void dbprint(std::ostream &out)
const override {
67 std::set<TypeSpecialization *> inserted;
69 void add(
const IR::Type_Specialized *t,
const IR::Type_StructLike *decl,
73 void dbprint(std::ostream &out)
const override {
75 out << dbp(it.first) <<
" => " << it.second << std::endl;
81 if (inserted.find(s.second) != inserted.end())
continue;
82 if (s.second->insertion == insertionPoint) {
84 LOG2(
"Will insert " << dbp(s.second->replacement) <<
" before "
85 << dbp(insertionPoint));
86 result->push_back(s.second->replacement);
87 inserted.emplace(s.second);
104 setName(
"FindTypeSpecializations");
107 void postorder(
const IR::Type_Specialized *type)
override;
121 setName(
"CreateSpecializedTypes");
125 const IR::Node *postorder(IR::Type_Declaration *type)
override;
126 const IR::Node *postorder(IR::Declaration *decl)
override {
return insert(decl); }
138 setName(
"ReplaceTypeUses");
141 const IR::Node *postorder(IR::Type_Specialized *type)
override;
142 const IR::Node *postorder(IR::StructExpression *expresison)
override;
162class SpecializeGenericTypes :
public PassRepeated {
166 explicit SpecializeGenericTypes(
TypeMap *typeMap) {
167 passes.emplace_back(
new PassRepeated({
174 passes.emplace_back(
new TypeChecking(
nullptr, typeMap));
178 specMap.typeMap = typeMap;
179 setName(
"SpecializeGenericTypes");
180 setStopOnError(
true);
189 const IR::Node *postorder(IR::Type_StructLike *type)
override {
190 if (!type->typeParameters->empty())
return nullptr;
193 const IR::Node *postorder(IR::Type_Stack *type)
override {
194 if (type->elementType->is<IR::Type_Specialized>())
return nullptr;
Definition typeChecker.h:32
Definition specializeGenericTypes.h:115
Definition specializeGenericTypes.h:97
Definition stringify.h:33
Definition referenceMap.h:36
Definition referenceMap.h:29
Removes all structs or stacks that are generic.
Definition specializeGenericTypes.h:187
Definition specializeGenericTypes.h:133
Definition typeChecker.h:55
Definition ordered_map.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition specializeGenericTypes.h:26
const IR::Vector< IR::Type > * argumentTypes
Definition specializeGenericTypes.h:39
const IR::Type_StructLike * replacement
New synthesized type (created later)
Definition specializeGenericTypes.h:34
const IR::Type_Declaration * declaration
Declaration of specialized type, which will be replaced.
Definition specializeGenericTypes.h:32
const IR::Type_Specialized * specialized
Type that is being specialized.
Definition specializeGenericTypes.h:30
cstring name
Name to use for specialized type.
Definition specializeGenericTypes.h:28
const IR::Node * insertion
Insertion point.
Definition specializeGenericTypes.h:36
Definition specializeGenericTypes.h:61