@@ -39,11 +39,12 @@ class EBPFType : public EBPFObject {
3939 virtual void declareArray (CodeBuilder * /* builder*/ , cstring /* id*/ , unsigned /* size*/ ) {
4040 BUG (" %1%: unsupported array" , type);
4141 }
42+ cstring toString () const override { return " EBPFType" _cs; }
4243
4344 DECLARE_TYPEINFO (EBPFType, EBPFObject);
4445};
4546
46- class IHasWidth : public ICastable {
47+ class IHasWidth : virtual public ICastable {
4748 public:
4849 virtual ~IHasWidth () {}
4950 // / P4 width
@@ -79,6 +80,7 @@ class EBPFBoolType : public EBPFType, public IHasWidth {
7980 void emitInitializer (CodeBuilder *builder) override { builder->append (" 0" ); }
8081 unsigned widthInBits () const override { return 1 ; }
8182 unsigned implementationWidthInBits () const override { return 8 ; }
83+ cstring toString () const override { return " EBPFBoolType" _cs; }
8284
8385 DECLARE_TYPEINFO (EBPFBoolType, EBPFType, IHasWidth);
8486};
@@ -101,6 +103,7 @@ class EBPFStackType : public EBPFType, public IHasWidth {
101103 void emitInitializer (CodeBuilder *builder) override ;
102104 unsigned widthInBits () const override ;
103105 unsigned implementationWidthInBits () const override ;
106+ cstring toString () const override { return " EBPFStackType" _cs; }
104107
105108 DECLARE_TYPEINFO (EBPFStackType, EBPFType, IHasWidth);
106109};
@@ -123,6 +126,9 @@ class EBPFScalarType : public EBPFType, public IHasWidth {
123126 unsigned implementationWidthInBits () const override { return bytesRequired () * 8 ; }
124127 // True if this width is small enough to store in a machine scalar
125128 static bool generatesScalar (unsigned width) { return width <= 64 ; }
129+ cstring toString () const override {
130+ return " EBPFScalarType<width=" + Util::toString (width) + " >" ;
131+ }
126132
127133 DECLARE_TYPEINFO (EBPFScalarType, EBPFType, IHasWidth);
128134};
@@ -142,6 +148,7 @@ class EBPFTypeName : public EBPFType, public IHasWidth {
142148 unsigned widthInBits () const override ;
143149 unsigned implementationWidthInBits () const override ;
144150 void declareArray (CodeBuilder *builder, cstring id, unsigned size) override ;
151+ cstring toString () const override { return " EBPFTypeName<" _cs + type->path ->name .name + " >" ; }
145152
146153 template <typename T>
147154 bool canonicalTypeIs () const {
@@ -179,6 +186,7 @@ class EBPFStructType : public EBPFType, public IHasWidth {
179186 unsigned implementationWidthInBits () const override { return implWidth; }
180187 void emit (CodeBuilder *builder) override ;
181188 void declareArray (CodeBuilder *builder, cstring id, unsigned size) override ;
189+ cstring toString () const override { return " EBPFStructType<" _cs + name + " >" ; }
182190
183191 DECLARE_TYPEINFO (EBPFStructType, EBPFType, IHasWidth);
184192};
@@ -193,6 +201,7 @@ class EBPFEnumType : public EBPFType, public EBPF::IHasWidth {
193201 unsigned widthInBits () const override { return 32 ; }
194202 unsigned implementationWidthInBits () const override { return 32 ; }
195203 const IR::Type_Enum *getType () const { return type->to <IR::Type_Enum>(); }
204+ cstring toString () const override { return " EBPFEnumType<" _cs + getType ()->name .name + " >" ; }
196205
197206 DECLARE_TYPEINFO (EBPFEnumType, EBPFType, IHasWidth);
198207};
@@ -207,6 +216,7 @@ class EBPFErrorType : public EBPFType, public EBPF::IHasWidth {
207216 unsigned widthInBits () const override { return 32 ; }
208217 unsigned implementationWidthInBits () const override { return 32 ; }
209218 const IR::Type_Error *getType () const { return type->to <IR::Type_Error>(); }
219+ cstring toString () const override { return " EBPFErrorType" _cs; }
210220
211221 DECLARE_TYPEINFO (EBPFErrorType, EBPFType, IHasWidth);
212222};
@@ -222,6 +232,7 @@ class EBPFMethodDeclaration : public EBPFObject {
222232
223233 // / Emit the signature declaration of this method in C-style form.
224234 void emit (CodeBuilder *builder);
235+ cstring toString () const override { return " EBPFMethodDeclaration" _cs; }
225236
226237 DECLARE_TYPEINFO (EBPFMethodDeclaration, EBPFObject);
227238};
@@ -230,14 +241,17 @@ class EBPFScalarTypePNA : public EBPFScalarType {
230241 bool isPrimitiveByteAligned = false ;
231242
232243 public:
233- explicit EBPFScalarTypePNA (const IR::Type_Bits *bits) : EBPFScalarType(bits) {
234- isPrimitiveByteAligned = (width <= 8 || width <= 16 || (width > 24 && width <= 32 ) ||
235- (width > 56 && width <= 64 ));
236- }
244+ explicit EBPFScalarTypePNA (const IR::Type_Bits *bits)
245+ : EBPFScalarType(bits),
246+ isPrimitiveByteAligned(width <= 8 || width <= 16 || (width > 24 && width <= 32 ) ||
247+ (width > 56 && width <= 64 )) { }
237248 unsigned alignment () const ;
238- void declare (CodeBuilder *builder, cstring id, bool asPointer);
239- void declareInit (CodeBuilder *builder, cstring id, bool asPointer);
240- void emitInitializer (CodeBuilder *builder);
249+ void declare (CodeBuilder *builder, cstring id, bool asPointer) override ;
250+ void declareInit (CodeBuilder *builder, cstring id, bool asPointer) override ;
251+ void emitInitializer (CodeBuilder *builder) override ;
252+ cstring toString () const override {
253+ return " EBPFScalarTypePNA<width=" _cs + Util::toString (width) + " >" ;
254+ }
241255};
242256
243257} // namespace P4::EBPF
0 commit comments