diff --git a/backends/bmv2/psa_switch/psaSwitch.h b/backends/bmv2/psa_switch/psaSwitch.h index 4dafba5c69..dce1d9ba1d 100644 --- a/backends/bmv2/psa_switch/psaSwitch.h +++ b/backends/bmv2/psa_switch/psaSwitch.h @@ -39,7 +39,9 @@ class PsaSwitchExpressionConverter : public ExpressionConverter { auto jsn = new Util::JsonObject(); jsn->emplace("name", param->toString()); jsn->emplace("type", "hexstr"); - auto bitwidth = param->type->width_bits(); + // FIXME -- how big is a PSA_CounterType_t? Being an enum type, we can't + // sensibly call param->width_bits() here. + auto bitwidth = 0; // encode the counter type from enum -> int if (fieldName == "BYTES") { diff --git a/ir/base.def b/ir/base.def index a1e6d3f29e..7e7cf52abf 100644 --- a/ir/base.def +++ b/ir/base.def @@ -36,7 +36,7 @@ abstract Type { typedef Type_Void Void; #end /// Well-defined only for types with fixed width - virtual int width_bits() const { return 0; } + virtual int width_bits() const { BUG("width_bits() on type with unknown size: %1%", this); } /// When possible returns the corresponding type that can be inserted /// in a P4 program; may return a Type_Name virtual const Type* getP4Type() const = 0; diff --git a/ir/expression.def b/ir/expression.def index 7c6c0ccd63..26d52462a5 100644 --- a/ir/expression.def +++ b/ir/expression.def @@ -321,7 +321,7 @@ class TypeNameExpression : Expression { dbprint{ out << typeName; } toString { return typeName->toString(); } validate { BUG_CHECK(typeName->is() || typeName->is(), - "%1 unexpected type in TypeNameExpression", typeName); } + "%1% unexpected type in TypeNameExpression", typeName); } } class Slice : Operation_Ternary { diff --git a/ir/type.def b/ir/type.def index 1bc9920f13..4a2842e2ae 100644 --- a/ir/type.def +++ b/ir/type.def @@ -182,6 +182,7 @@ class Type_Varbits : Type_Base { static Type_Varbits get(); toString{ return "varbit<"_cs + Util::toString(size) + ">"_cs; } dbprint { out << "varbit<" << size << ">"; } + int width_bits() const override { return size; } } class Parameter : Declaration, IAnnotated { @@ -268,6 +269,7 @@ class Type_InfInt : Type, ITypeVar { return true; /* ignore declid */ } const Type* getP4Type() const override { return this; } + int width_bits() const override { return 0; } } class Type_Dontcare : Type_Base { @@ -583,6 +585,7 @@ class Type_Stack : Type_Indexed, Type { static const cstring pop_front; const Type* getP4Type() const override { return new IR::Type_Stack(srcInfo, elementType->getP4Type(), size); } + int width_bits() const override { return getSize() * elementType->width_bits(); } } /** Given a declaration @@ -680,6 +683,7 @@ class Type_SerEnum : Type_Declaration, ISimpleNamespace, IAnnotated { return members.getDeclaration(name); } #nodbprint validate{ members.check_null(); } + int width_bits() const override { return type->width_bits(); } } class Type_Table : Type, IApply {