Abstract Packages


Proposal Editing Information

  • Who Updates: JimLewis, <Add YourName >, ...
  • Date Proposed: 2012-08-17
  • Date Last Updated: 2012-08-17
  • Priority:
  • Complexity:
  • Focus: Testbench

Requirement Summary

Abstract packages are intended to be used with formal package generics. Rather than being a package with generic inputs, they are a methodology that indicate what subprograms a package implements to support.

Related and/or Competing Issues: Protected Type Updates

Issue

A limitation to type generics is that we cannot make any assumptions about what operators and/or subprograms are supported for a given type. As a result, the type and subprograms must be passed as generics.

This is shown below on the interface to RandomGenericPkg.

package RandomGenericPkg is
generic (
    type RandomSeedType ;      -- base type for randomization
    procedure Uniform (Result : out real ;  Seed : inout RandomSeedType) ;
    function  GenRandSeed(IV : integer_vector) return RandomSeedType ;
    function  GenRandSeed(I : integer) return RandomSeedType ;
    function  GenRandSeed(S : string) return RandomSeedType 
) ;
. .  .
end package RandomGenericPkg ; 

Use Model 1:

The goal is to minimize the amount of information that needs to be sent.

package RandomGenericPkg is
generic (
    package RandomBasePkg is abstract work.RandomBaseAbsPkg 
) ;
use RandomBasePkg.all ; 
. . . 
end package RandomGenericPkg ; 
... 

package RandomBaseAbsPkg is abstract 
    type RandomSeedType ;      -- base type for randomization
    procedure Uniform (Result : out real ;  Seed : inout RandomSeedType) ;
    function  GenRandSeed(IV : integer_vector) return RandomSeedType ;
    function  GenRandSeed(I : integer) return RandomSeedType ;
    function  GenRandSeed(S : string) return RandomSeedType ;
end package RandomBaseAbsPkg ; 

... 
package RandomPkg is new RandomGenericPkg 
  generic map (RandomBaseAbsPkg => RandomBasePkg) ; 

Use Model 2:

-- There are issues in this that still need to be resolved.

When we work with math types, there may be more than one type defined in the package, such as ieee.numeric_std.unsigned and ieee.numeric_std.signed.

package NumericAbsPkg is abstract 
    type NumericType ;   
    function from_integer(I : integer) return NumericType ; 
    function to_integer(N : NumericType) return integer ; 
    function from_real(R : real) return NumericType ; 
    function to_real(N : NumericType) return NumericType ; 
    function  "+"(l, r : NumericType) return NumericType ;
    function  "+"(l : NumericType ; r : integer) return NumericType ;
    function  "+"(l : integer ; r : NumericType ) return NumericType ;
    function  "+"(l : NumericType ; r : real) return NumericType ;
    function  "+"(l : real; r : NumericType ) return NumericType ;
    function  "-"(l, r : NumericType) return NumericType ;
    function  "-"(l : NumericType ; r : integer) return NumericType ;
    function  "-"(l : integer ; r : NumericType ) return NumericType ;
    function  "-"(l : NumericType ; r : real) return NumericType ;
    function  "-"(l : real; r : NumericType ) return NumericType ;
end package NumericAbsPkg ; 

package ComplexMathGenericPkg is 
generic (
    package NumericPkg is abstract work.NumericAbsPkg 
) ;
use NumericPkg.all ; 
. . . 
end package ComplexMathGenericPkg ; 

. . . 
package ComplexMathUnsignedPkg is new ComplexMathGenericPkg 
  generic map (NumericPkg => ieee.numeric_std with (NumericType => Unsigned ) ; 
-- Issues - NumericType not identified as a type that may need to be mapped.
-- issues - from_real and from_integer need to be sized for array based types and 
--              perhaps does not work.  So mixed overloading may need to be omitted.

Proposal

Questions

General Comments

An essential companion to generics on packages.

Rust has a nice solution for this problem: https://doc.rust-lang.org/book/traits.html or on wikipedia the general description: https://en.wikipedia.org/wiki/Type_class

-- LievenLemiengre - 2016-04-07

Supporters

Add your signature here to indicate your support for the proposal

-- JimLewis - 2014-12-04

-- PatrickLehmann - 2016-02-19

Topic revision: r6 - 2020-02-17 - 15:34:49 - JimLewis
 
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback