VHDL 中有没有办法拥有泛型类型?因此,例如我想调用一个过程,但我不确定我想提供的信号类型作为参数,是否可以将参数声明为泛型?
就像在 C++ 中一样,您将使用模板。
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;
至少应该可以使用不同的信号类型作为“sig”。
最佳答案
Peter Ashenden 和 Jim Lewis 的书“VHDL-2008 - Just the new stuff”以
Chapter 1 : Enhanced Generics
1.1 Generic Types
因此,如果您的工具正确支持 VHDL-2008,您现在可以声明泛型类型,并且可以在子程序(不仅仅是实体)上声明泛型。
如果它们遵循 Ada 模型,那么在您第一次编译它们时会检查泛型,而不是在实例化它们时,这样任何编译的实例化都将起作用,这与 C++ 模板的情况不同,在这种情况下,错误可能会潜伏多年,直到您以特定方式实例化它们(因为 C++ 模板比真正的通用元编程更接近宏)
示例:未经测试,但在上述书的第 17 页上编写了以下示例...
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;
关于templates - 是否可以在 vhdl 中使用泛型类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15382791/