是否有可能在vhdl中有泛型类型? [英] Is it possible to have generic type in vhdl?

查看:174
本文介绍了是否有可能在vhdl中有泛型类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VHDL中有一种方法可以使用泛型类型吗?因此,例如我想调用一个过程,但我不确定信号的类型是否需要作为参数,是否可以将参数声明为泛型?
就像在C ++中一样,你可以使用一个Template。

  procedure eq_checker(name:string; sig:ANYTHING);应该:任何;在时间)是
,如果(在=现在)然后是
,如果sig =应该那么
报告具有相同的值严重性记录;
else
报告具有不同的值严重性注意事项;
结束if;
结束if;
结束检查;

至少应该可以使用不同的信号类型作为sig。

解决方案


$ b $ Peter Hehenden和Jim Lewis书籍VHDL-2008 - Just the new stuff b


第1章:增强的泛型

1.1泛型

,如果您的工具正确支持VHDL-2008,现在可以声明泛型类型,并且可以在子程序(不仅仅是实体)上声明泛型。

如果他们遵循Ada模型,那么当您第一次编译它们时,将会检查泛型,而不是在您实例化它们时进行检查,以便编译的任何实例化都可以工作,与使用C ++模板的情况不同,在这种情况下,除非您以特定方式实例化它们,否则错误可能处于休眠状态(因为C ++模板比真正的泛型元编程更接近于宏)



示例:未经测试,但是按照上述书籍的第17页上的示例编写...

  procedure eq_checker 
generic(type任何)
参数(name:string; sig,should:ANYTHING; at:time)是
begin
if(at = now)then
if sig = should然后
报告具有相同的值严重性注意事项;
else
报告具有不同的值严重性注意事项;
结束if;
结束if;
结束程序eq_checker;


Is there a way in VHDL to have generic types? So for example I want to call a procedure but I'm not sure what type the signal has I want to give as paarameter, is it possible to declare the parameter as generic? Like in C++ you would use a Template.

procedure eq_checker(name : string; sig : ANYTHING); should : ANYTHING; at : time) is
  if (at = now) then
    if sig = should then
      report "has same value" severity note;
    else
      report "has not same value" severity note;
    end if;
  end if;
end checker;

At least it should be possible to use different signal types as "sig".

解决方案

The Peter Ashenden and Jim Lewis book "VHDL-2008 - Just the new stuff" opens with

Chapter 1 : Enhanced Generics
1.1 Generic Types

So, if your tool supports VHDL-2008 properly, you can now declare generic types, and you can declare generics on subprograms (not just entities).

And if they have followed the Ada model, the generics will be checked when you first compile them, not when you instantiate them, so that any instantiation that compiles will work, unlike the situation with C++ templates where bugs can lie dormant for years until you instantiate them in a particular way (because C++ templates are closer to macros than true generic metaprogramming)

Example : untested, but written following examples on p.17 of aforementioned book...

procedure eq_checker
         generic  (type ANYTHING) 
         parameter(name : string; sig,should : ANYTHING; at : time) is
begin
  if (at = now) then
    if sig = should then
      report "has same value" severity note;
    else
      report "has not same value" severity note;
    end if;
  end if;
end procedure eq_checker;

这篇关于是否有可能在vhdl中有泛型类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆