19class ConstantTypeSubstitution :
public Transform, ResolutionContext {
27 : subst(subst), typeMap(typeMap), tc(tc) {
31 LOG3(
"ConstantTypeSubstitution " << subst);
34 const IR::Node *postorder(IR::Constant *cst)
override {
35 auto cstType = typeMap->getType(getOriginal(),
true);
36 if (!cstType || !cstType->is<IR::ITypeVar>())
return cst;
38 while (repl->is<IR::ITypeVar>()) {
39 auto next = subst->get(repl->to<IR::ITypeVar>());
40 BUG_CHECK(next != repl,
"Cycle in substitutions: %1%", next);
44 if (repl != cstType) {
46 LOG2(
"Inferred type " << repl <<
" for " << cst);
47 cst =
new IR::Constant(cst->srcInfo, repl, cst->value, cst->base);
49 LOG2(
"No type inferred for " << cst <<
" repl is " << repl);
54 const IR::Expression *convert(
const IR::Expression *expr,
const Visitor::Context *ctxt) {
55 auto result = expr->apply(*
this, ctxt)->to<IR::Expression>();
56 if (result != expr && (
::P4::errorCount() == 0)) tc->learn(result,
this, ctxt);
60 const Visitor::Context *ctxt) {
62 if (result != vec) tc->learn(result,
this, ctxt);
66 const Visitor::Context *ctxt) {
68 if (result != vec) tc->learn(result,
this, ctxt);
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13