28class ConstantTypeSubstitution :
public Transform, ResolutionContext {
35 : subst(subst), typeMap(typeMap), tc(tc) {
39 LOG3(
"ConstantTypeSubstitution " << subst);
42 const IR::Node *postorder(IR::Constant *cst)
override {
43 auto cstType = typeMap->getType(getOriginal(),
true);
44 if (!cstType->is<IR::ITypeVar>())
return cst;
46 while (repl->is<IR::ITypeVar>()) {
47 auto next = subst->get(repl->to<IR::ITypeVar>());
48 BUG_CHECK(next != repl,
"Cycle in substitutions: %1%", next);
52 if (repl != cstType) {
54 LOG2(
"Inferred type " << repl <<
" for " << cst);
55 cst =
new IR::Constant(cst->srcInfo, repl, cst->value, cst->base);
57 LOG2(
"No type inferred for " << cst <<
" repl is " << repl);
62 const IR::Expression *convert(
const IR::Expression *expr,
const Visitor::Context *ctxt) {
63 auto result = expr->apply(*
this, ctxt)->
to<IR::Expression>();
64 if (result != expr && (
::P4::errorCount() == 0)) tc->learn(result,
this, ctxt);
68 const Visitor::Context *ctxt) {
70 if (result != vec) tc->learn(result,
this, ctxt);
74 const Visitor::Context *ctxt) {
76 if (result != vec) tc->learn(result,
this, ctxt);
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24