class ClassName
{
Class_contents;
}
Classes can contain the following primitives: THDL++ classes are similar to VHDL packages. They do not describe objects created and maintained during runtime. Instead they allow combining definitions of types, constants and algorithms inside a single named primitive. Entities templates and functions can accept classes as template arguments. Use the
THDL++ allows inheriting classes. Inheritance syntax is similar to C++/C#. Base class contents can be accessed from a child class using the
Note that THDL++ classes do not support private/protected/public modifiers. All class contents are always public.
You can define compile-time lists of classes and use them in generic statements (e.g.
Classes can be declared in the global scope, inside namespaces, other classes and entities.
class NormalMin
{
typedef logic[8] DataType;
bool CompareFunction(DataType a, DataType b)
{
return a lt b;
}
}
template<any _TypeInfo, int _InputCount> entity MinFinder
{
port in _TypeInfo.DataType[_InputCount] Inputs;
port out _TypeInfo.DataType Output;
process Compute (any)
{
for(...)
{
if (_TypeInfo.CompareFunction(x, cur_minimum))
cur_minimum = x;
}
}
}
When you instantiate a templated entity, specify the template arguments. E.g.:
MinFinder<NormalMin, 4> finder(...);
This will instantiate a minimum finder with 4 inputs based on the NormalMin definition.
class SuperMin : NormalMin
{
const int SuperMinValue = 0x55;
bool CompareFunction(DataType a, DataType b)
{
if (a == SuperMinValue)
return true;
else if (b == SuperMinValue)
return false;
else
return base.CompareFunction(a, b);
}
}
The instantiation should be changed accordingly:
MinFinder<SuperMin, 4> finder(...);
Note that the DataType definition was inherited from NormalMin and did not have to be redefined.
THDL++ compiler will convert functions defined in the classes to VHDL functions. Every function name will be prefixed by the fully qualified class name. If a class or a function is templated, one instance of VHDL function will be created for every combination of template arguments that is used in the code. See functions page for more details.