Table of Contents Previous page Next page Index

ModelSim

Model Technology Inc.


mti_GetGenericList()

Gets a list of the VHDL generics defined for a region.

Syntax

generic_list = mti_GetGenericList( region_id ) 

Returns

Name
Type
Description
generic_list
mtiInterfaceListT *
A pointer to a NULL-terminated list of generics for the specified region or NULL if there are no generics in the specified region

Arguments

Name
Type
Description
region_id
mtiRegionIdT
A handle to a VHDL region

Description

mti_GetGenericList() returns a NULL-terminated list of the generics defined for the specified region. This list is in the same interface format as the C initialization function generics list. The caller is responsible for freeing each element in the list with mti_Free(). In order to use mti_GetGenericList() on a foreign architecture region there must be a "+" or "-" in front of the initialization function name in the foreign attribute.

If there are no generics in the region or if the region is a foreign architecture and there is neither a "+" nor a "-" in front of the initialization function name in the foreign attribute, then mti_GetGenericList() returns NULL.

Related functions

None

Example

FLI code

#include "mti.h"

void printGenericList( mtiInterfaceListT * generic_list, int free_it )
{
  mtiInterfaceListT * glp;
  mtiInterfaceListT * glp_next;

  for ( glp = generic_list; glp; glp = glp_next ) {
   mti_PrintFormatted( "    %s =", glp->name );
   switch ( mti_GetTypeKind( glp->type ) ) {
    case MTI_TYPE_ENUM:
    case MTI_TYPE_PHYSICAL:
    case MTI_TYPE_SCALAR:
     mti_PrintFormatted( " %d\n", glp->u.generic_value );
     break;
    case MTI_TYPE_REAL:
     mti_PrintFormatted( " %g\n", glp->u.generic_value_real );
     break;
    case MTI_TYPE_TIME:
     mti_PrintFormatted( " [%d,%d]\n",
                         MTI_TIME64_HI32(glp->u.generic_value_time),
                          MTI_TIME64_LO32(glp->u.generic_value_time) );
     break;
    case MTI_TYPE_ARRAY:
     {
      int        i;
      mtiInt32T  num_elems = mti_TickLength( glp->type );
      mtiTypeIdT elem_type = mti_GetArrayElementType( glp->type );

      switch ( mti_GetTypeKind( elem_type ) ) {
       case MTI_TYPE_PHYSICAL:
       case MTI_TYPE_SCALAR:
        {
         mtiInt32T * val = glp->u.generic_array_value;
         for ( i = 0; i < num_elems; i++ ) {
          mti_PrintFormatted( " %d", val[i] );
         }
        }
        break;
       case MTI_TYPE_ARRAY:
        mti_PrintFormatted( " ARRAY of ARRAYs" );
        break;
       case MTI_TYPE_RECORD:
        mti_PrintFormatted( " ARRAY of RECORDs" );
        break;
       case MTI_TYPE_ENUM:
        {
         char ** enum_values = mti_GetEnumValues( elem_type );
         char *  array_val = glp->u.generic_array_value;

         for ( i = 0; i < num_elems; i++ ) {
          mti_PrintFormatted( " %s",
                             enum_values[array_val[i]] );
         }
        }
        break;
       case MTI_TYPE_REAL:
        {
         double * val = glp->u.generic_array_value;
         for ( i = 0; i < num_elems; i++ ) {
          mti_PrintFormatted( " %g", val[i] );
         }
        }
        break;
       case MTI_TYPE_TIME:
        {
         mtiTime64T * val = glp->u.generic_array_value;
         for ( i = 0; i < num_elems; i++ ) {
          mti_PrintFormatted( " [%d,%d]",
                             MTI_TIME64_HI32(val[i]),
                             MTI_TIME64_LO32(val[i]) );
         }
        }
        break;
       default:
        break;
      }
      mti_PrintFormatted( "\n" );
     }
     break;
    default:
     mti_PrintFormatted( "\n" );
     break;
    }
    glp_next = glp->nxt;
    if ( free_it ) {
     mti_Free( glp );
    }
  }
}

void printRegionInfo( char * region_name )
{
  mtiInterfaceListT * generic_list;
  mtiRegionIdT        regid;

  regid = mti_FindRegion( region_name );
  if ( regid ) {
    region_name = mti_GetRegionFullName( regid );
    mti_PrintFormatted( "  Region %s:\n", region_name );
    mti_VsimFree( region_name );
    generic_list = mti_GetGenericList( regid );
    printGenericList( generic_list, 1 );
  }
}

void loadDoneCB( void * param )
{
  mti_PrintMessage( "\nLoad Done phase:\n" );
  printRegionInfo( "top" );
  printRegionInfo( "inst1" );
  printRegionInfo( "inst1/i1" );
  printRegionInfo( "inst1/flip" );
  printRegionInfo( "/top/inst1/toggle" );
}

void initForeign(
  mtiRegionIdT       region,   /* The ID of the region in which this     */
                               /* foreign architecture is instantiated.  */
  char              *param,    /* The last part of the string in the     */
                               /* foreign attribute.                     */
  mtiInterfaceListT *generics, /* A list of generics for the foreign model.*/
  mtiInterfaceListT *ports     /* A list of ports for the foreign model.   */
)
{
  mti_AddLoadDoneCB( loadDoneCB, 0 );

  mti_PrintMessage( "\nElaboration phase:\n" );
  mti_PrintMessage( "  Foreign function generics:\n" );
  printGenericList( generics, 0 );
} 

HDL code

package my_pkg is
  type bigtime is range 0 to integer'high
    units
      hour;
      day   = 24 hour;
      week  = 7 day;
      month = 4 week;
      year  = 12 month;
    end units;

  type intarray     is array( 1 to 3 ) of integer;
  type realarray    is array( 0 to 2 ) of real;
  type timearray    is array( 2 to 4 ) of time;
  type bigtimearray is array( 1 to 3 ) of bigtime;
end my_pkg;

entity for_model is
  generic ( whoami : string := "Don't know" );
end for_model;

architecture a of for_model is
  attribute foreign of a : architecture is "+initForeign for_model.sl";
begin
end a;

entity inv is
  generic ( min_delay : time := 5 ns;
            max_delay : time := 10 ns );
  port ( a : in bit;
         b : out bit );
end inv;

architecture b of inv is
begin
  b <= a after min_delay;
end b;

use work.my_pkg.all;

entity mid is
  generic ( g1 : bit := '0';
            g2 : integer := 11;
            g3 : real := 12.97;
            g4 : bit_vector := "0010";
            g5 : intarray := ( 1, 2, 3 );
            g6 : realarray := ( 10.5, 16.8, 21.39 );
            g7 : timearray := ( 3 ns, 18 ns, 123 ns );
            g8 : bigtime := 13 hour;
            g9 : bigtimearray := ( 2 hour, 4 hour, 6 hour ) );
end mid;

architecture a of mid is

  signal s1 : bit := '0';
  signal s2 : bit := '0';
  signal s3 : bit := '0';
  signal s4 : bit := '0';

component for_model is
  generic ( whoami : string := "Didn't say" );
end component;

for all : for_model use entity work.for_model(a);

component inv is
  generic ( min_delay : time := 5 ns;
            max_delay : time := 10 ns );
  port ( a : in bit;
         b : out bit );
  end component;

begin

  flip : inv
    generic map ( 3 ns, 8 ns )
    port map ( s3, s4 );

  s1 <= not s1 after 5 ns;

  toggle : inv port map ( s1, s2 );

  i1 : for_model generic map ( "inst i1" );

end a;

use work.my_pkg.all;

entity top is
end top;

architecture a of top is

  component mid is
    generic ( g1 : bit := '0';
              g2 : integer := 11;
              g3 : real := 12.97;
              g4 : bit_vector := "101";
              g5 : intarray := ( 7, 9, 11 );
              g6 : realarray := ( 8.1, 6.2, 1.34 );
              g7 : timearray := ( 212 ns, 100 ns, 9 ns );
              g8 : bigtime := 40 hour;
              g9 : bigtimearray := ( 8 hour, 16 hour, 32 hour ) );
  end component;

begin

  inst1 : mid generic map ( '1', 42, 101.2, "101101" );

end a; 

Simulation output

% vsim -c top
Reading .../modeltech/sunos5/../tcl/vsim/pref.tcl 

# 5.4b

# vsim -c top 
# Loading .../modeltech/sunos5/../std.standard
# Loading work.my_pkg
# Loading work.top(a)
# Loading work.mid(a)
# Loading work.inv(b)
# Loading work.for_model(a)
# Loading ./for_model.sl
# 
# Elaboration phase:
#   Foreign function generics:
#     whoami = 'i' 'n' 's' 't' ' ' 'i' '1'
# 
# Load Done phase:
#   Region /top:
#   Region /top/inst1:
#     g1 = 1
#     g2 = 42
#     g3 = 101.2
#     g4 = '1' '0' '1' '1' '0' '1'
#     g5 = 7 9 11
#     g6 = 8.1 6.2 1.34
#     g7 = [0,212] [0,100] [0,9]
#     g8 = 40
#     g9 = 8 16 32
#   Region /top/inst1/i1:
#     whoami = 'i' 'n' 's' 't' ' ' 'i' '1'
#   Region /top/inst1/flip:
#     min_delay = [0,3]
#     max_delay = [0,8]
#   Region /top/inst1/toggle:
#     min_delay = [0,5]
#     max_delay = [0,10]
VSIM 1> run 10
VSIM 2> quit 


Model Technology Inc.
Voice: (503) 641-1340
Fax: (503)526-5410
http://www.model.com
sales@model.com
TOC PREV NEXT INDEX

ModelSim