Pointer to record with discriminant
Is your capability/feature request related to a problem?
Pointer to record with discriminant Potential implementation for #69. This is intended as an additional use case to #156
Please also see: https://en.wikibooks.org/wiki/Ada_Programming/Types/record This shows how Ada handles discriminants
Describe the solution you'd like
After writing the first part, I realized that I really wanted an structure of pointers, for which the syntax is a little easier to deal with.
Variant Record and pointer to it
Without any special language features we could create a discriminated type and a pointer to it:
type TypeEnum is (IE, RE, SLE, SLVE) ;
type AnyType (TypeOfType : TypeEnum := IE) is record
case TypeOfType is
when IE =>
I : integer ;
when RE =>
R : real ;
when SLE =>
SL : std_logic ;
when SLVE =>
SLV : std_logic_vector ;
when others =>
end case ;
end record AnyType ;
type AnyPtrType is access AnyType ;
Usage:
variable ptr : AnyPtrType;
------
-- See https://en.wikibooks.org/wiki/Ada_Programming/Types/record
-- Specifying the discriminant is part of the aggregate
ptr := new AnyPtrType'(TypeOfType => SLVE, SLV => X"A5") ;
. . .
-- First part of this follows Ada for specifying a discriminant: AnyType(TypeOfType => SLVE)
-- The second part follows VHDL syntax for specifying a constraint on a composite: (SLV(7 downto 0)
ptr := new AnyType(TypeOfType => SLVE)(SLV(7 downto 0)) ;
ptr.SLV := X"A5" ;
Variant Record and whose types are pointers
type TypeEnum is (IE, RE, SLE, SLVE) ;
type IntegerPtrType is access integer ;
type RealPtrType is access real ;
type SlPtrType is access std_logic ;
type SlvPtrType is access std_logic_vector ;
type AnyPtrType (TypeOfType : TypeEnum := IE) is record
case TypeOfType is
when IE =>
I : IntegerPtrType ;
when RE =>
R : RealPtrType ;
when SLE =>
SL : SlPtrType ;
when SLVE =>
SLV : SlvPtrType ;
when others =>
end case ;
end record AnyPtrType ;
Usage:
variable AnyPtr : AnyPtrType;
------
AnyPtr := (TypeOfType => SLVE, SLV => new std_logic_vector'(X"A5")) ;
. . .
AnyPtr := AnyType(TypeOfType => SLVE, SLV => new std_logic_vector(7 downto 0)) ;
AnyPtr.SLV := X"A5" ;
From here we could create a FIFO that handles AnyPtrType.
Additional context
Potential implementation for #69
Describe alternatives you've considered
None here.
Additional context
Edited by JimLewis