17#ifndef FRONTENDS_P4_SPECIALIZEGENERICTYPES_H_
18#define FRONTENDS_P4_SPECIALIZEGENERICTYPES_H_
20#include "frontends/p4/typeChecking/typeChecker.h"
54 void dbprint(std::ostream &out)
const override {
66 std::set<TypeSpecialization *> inserted;
68 void add(
const IR::Type_Specialized *t,
const IR::Type_StructLike *decl,
72 void dbprint(std::ostream &out)
const override {
74 out << dbp(it.first) <<
" => " << it.second << std::endl;
80 if (inserted.find(s.second) != inserted.end())
continue;
81 if (s.second->insertion == insertionPoint) {
83 LOG2(
"Will insert " << dbp(s.second->replacement) <<
" before "
84 << dbp(insertionPoint));
85 result->push_back(s.second->replacement);
86 inserted.emplace(s.second);
103 setName(
"FindTypeSpecializations");
106 void postorder(
const IR::Type_Specialized *type)
override;
120 setName(
"CreateSpecializedTypes");
124 const IR::Node *postorder(IR::Type_Declaration *type)
override;
125 const IR::Node *postorder(IR::Declaration *decl)
override {
return insert(decl); }
137 setName(
"ReplaceTypeUses");
140 const IR::Node *postorder(IR::Type_Specialized *type)
override;
141 const IR::Node *postorder(IR::StructExpression *expresison)
override;
173 passes.emplace_back(
new TypeChecking(
nullptr, typeMap));
177 specMap.typeMap = typeMap;
178 setName(
"SpecializeGenericTypes");
179 setStopOnError(
true);
188 const IR::Node *postorder(IR::Type_StructLike *type)
override {
189 if (!type->typeParameters->empty())
return nullptr;
192 const IR::Node *postorder(IR::Type_Stack *type)
override {
193 if (type->elementType->is<IR::Type_Specialized>())
return nullptr;
Definition typeChecker.h:32
Definition specializeGenericTypes.h:114
Definition specializeGenericTypes.h:96
Definition stringify.h:33
Definition referenceMap.h:36
Definition referenceMap.h:29
Definition ir/pass_manager.h:145
Removes all structs or stacks that are generic.
Definition specializeGenericTypes.h:186
Definition specializeGenericTypes.h:132
Specializes each generic type by substituting type parameters.
Definition specializeGenericTypes.h:161
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:25
const IR::Vector< IR::Type > * argumentTypes
Definition specializeGenericTypes.h:38
const IR::Type_StructLike * replacement
New synthesized type (created later)
Definition specializeGenericTypes.h:33
const IR::Type_Declaration * declaration
Declaration of specialized type, which will be replaced.
Definition specializeGenericTypes.h:31
const IR::Type_Specialized * specialized
Type that is being specialized.
Definition specializeGenericTypes.h:29
cstring name
Name to use for specialized type.
Definition specializeGenericTypes.h:27
const IR::Node * insertion
Insertion point.
Definition specializeGenericTypes.h:35
Definition specializeGenericTypes.h:60