Allow access and protected type parameters on function interfaces
Proposal Information
- Current Owner: JimLewis, ...
- Contributors: JimLewis, ...
- Date Proposed: 2012-Aug-16
- Date Last Updated: 2012-Aug-16
- Priority:
- Complexity:
- Focus: Testbench
- Related Issues: None
- Competing Issues: None
Language Change Specification Link
LCS-2016-002
Requirement Summary
Allow access and protected types on function interfaces.
Allowed for ADA functions. See:
http://en.wikibooks.org/wiki/Ada_Programming/Subprograms#Functions
Use Model: Access Types
Currently it is not possible to create an EmptyLine (named consistent with EndFile and original name before removed) Usage:
next when EmptyLine(buf) ;
function EmptyLine (
variable L : inout Line
) return boolean is
variable Valid : boolean ;
variable Char : character ;
begin
skip_whitespace(L) ;
return L = null or L.all'length = 0 ;
end function EmptyLine ;
Then we would also be able to create a to_string for type line that also deallocates a line:
function to_string( variable L : inout line ) return string is
variable result : string(L'range) ;
begin
result := L.all ;
deallocate(L) ;
return result ;
end function to_string ;
Then to create a to_string for composite types, such as integer_vector, where "write" is already defined can be done as follows:
function to_string( IV : in integer_vector ) return string is
variable L : line ;
begin
write(L, IV) ;
return to_string(L) ;
end function to_string ;
Or alternately we can leverage generics:
function generic_to_string
generic(
type AType ;
procedure write(L : inout line ; A : AType ; JUSTIFIED : SIDE := right; FIELD : WIDTH := 0) is <>
) ;
parameter(
A : in AType
) return string is
variable L : line ;
begin
write(L, A) ;
return to_string(L) ;
end function generic_to_string ;
With generics, a to_string function for integer_vector becomes:
function to_string is new generic_to_string
generic map (AType => integer_vector) ;
Another usage is within coverage modeling for the OSVVM package "CoveragePkg", however, the background information for the justification dives deeply into data structures for coverage modeling.
Extend Concatenation
Allow concatenation of types that are access types or composites that contain access types.
Use Model: Protected Type
Motivation: Local customizations and extensions to a protected type interface
Layering on top of CoveragePkg and RandomPkg
function RandCovPoint(
variable RV : inout RandomPType ;
constant Bin : in RangeArrayType
) return integer_vector is
variable result : integer_vector(Bin'range) ;
begin
for i in Bin'range loop
result(i) := RV.RandInt(Bin(i).min, Bin(i).max) ;
end loop ;
return result ;
end procedure RandCovPoint ;
Modeling Semaphores
See
SemaphoreDataStructure
Currently VHDL functions do not allow either access types or Protected Type inputs. ADA removed the requirement for not allowing access type inputs in ADA-95. This would allow overloads like the non-protected type procedure
TryGet [SemaphorePType, Boolean, Integer] to be re-expressed as a function
TryGet [SemaphorePType, Integer return boolean] which is a more natural way to use it. The code is as follows
function TryGet (Semaphore : SemaphorePType ; Count : Integer := 1 ) return boolean is
begin
return Semaphore.TryGet(Count) ;
end function TryGet ;
Proposal
Comments
This relaxation should be limited to impure functions, because the function may have side effects. --
PeterFlake - 2014-12-18
General
Arguments Against
Supporters
Add your signature here to indicate your support for the proposal
--
JimLewis
--
KevinJennings - 2013-04-12
--
Brent Hayhoe - 2014-12-23
--
MortenZilmer - 2015-01-21
--
PatrickLehmann - 2016-02-19
--
TorstenMeissner - 2016-05-18