P4C
The P4 Compiler
Loading...
Searching...
No Matches
blockmap.h
1
19#ifndef BF_P4C_MIDEND_BLOCKMAP_H_
20#define BF_P4C_MIDEND_BLOCKMAP_H_
21
22#include "frontends/p4/evaluator/evaluator.h"
23#include "ir/ir.h"
24
25/* FIXME -- do we really need this pass? Expression::type fields are set by TypeInferencing */
26
27class FillFromBlockMap : public Transform {
28 P4::ReferenceMap *refMap = nullptr;
29 P4::TypeMap *typeMap = nullptr;
30
31 const IR::Expression *preorder(IR::Expression *exp) override {
32 if (exp->type == IR::Type::Unknown::get())
33 if (auto type = typeMap->getType(getOriginal())) exp->type = type;
34 return exp;
35 }
36
37 const IR::Type *preorder(IR::Type_Name *type) override {
38 if (auto decl = refMap->getDeclaration(type->path)) {
39 if (auto tdecl = decl->getNode()->to<IR::Type_Declaration>())
40 return transform_child(tdecl)->to<IR::Type>();
41 else
42 BUG("Type_Name %1% maps to %2% rather than a type decl", type, decl);
43 } else {
44 BUG("Type_Name %1% doesn't map to a declaration", type, decl);
45 }
46 }
47
48 const IR::StructExpression *preorder(IR::StructExpression *si) override {
49 // Don't visit typeName, but visit everything else.
50 preorder(static_cast<IR::Expression *>(si));
51 visit(si->components, "components");
52 prune();
53 return si;
54 }
55
56 const IR::TypeNameExpression *preorder(IR::TypeNameExpression *tn) override {
57 // Don't visit typeName, but visit everything else.
58 preorder(static_cast<IR::Expression *>(tn));
59 prune();
60 return tn;
61 }
62
63 const IR::Type_Specialized *preorder(IR::Type_Specialized *ts) override {
64 // Don't visit baseType, but visit everything else.
65 Transform::preorder(static_cast<IR::Type *>(ts));
66 visit(ts->arguments, "arguments");
67 prune();
68 return ts;
69 }
70
71 const IR::ConstructorCallExpression *preorder(IR::ConstructorCallExpression *ts) override {
72 // Don't visit constructedType, but visit everything else.
73 preorder(static_cast<IR::Expression *>(ts));
74 visit(ts->arguments, "arguments");
75 prune();
76 return ts;
77 }
78
79 public:
81 : refMap(refMap), typeMap(typeMap) {
82 dontForwardChildrenBeforePreorder = true;
83 }
84};
85
86#endif /* BF_P4C_MIDEND_BLOCKMAP_H_ */
Definition blockmap.h:27
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
const IR::IDeclaration * getDeclaration(const IR::Path *path, bool notNull=false) const override
Definition referenceMap.cpp:78
Definition typeMap.h:41