Forum Discussion
VHDL Function Overloading not working
- 4 years ago
Nurina,
Thank you for the feedback, this is very helpful.
Basically, if I can summarize your answer, the overloading functions need to have distinct Types for the arguments. From a function signature point of view:
my_function(arg1 : type1) return result type 1
should have an overloaded function type of :
my_function(arge1 : type2) return result type 2
Correct ?
On a background note:
I am updating a code base that someone else developed; I typically would not use overloaded functions. The design intent was to make the VHDL more readable; however I think the basic issue is that the same argument type is present in all three overloaded versions of the function, as you have illustrated. The design is large and there are many functions in packages meant to make the design more readable, however, there are always issues with VHDL conversions if one does not handle them carefully as appears to be the case here.
Thank you and Regards,
James
Hi,
You need to program it such a way that Quartus knows which bits function to use. The parameter types for all the bits function are the same, try put different parameter types so that Quartus can differentiate the overloaded functions.
For example the TO_INTEGER functions are overloaded in the NUMERIC_STD library like so:
function TO_INTEGER ( ARG: UNSIGNED) return NATURAL;
-- Result subtype: NATURAL. Value cannot be negative since parameter is an
-- UNSIGNED vector.
-- Result: Converts the UNSIGNED vector to an INTEGER.
-- Id: D.2
function TO_INTEGER ( ARG: SIGNED) return INTEGER;
-- Result subtype: INTEGER
-- Result: Converts a SIGNED vector to an INTEGER.
BTW the to_unsigned function takes in arguments that aren't declared as integers like so: TO_UNSIGNED ( ARG,SIZE: NATURAL)
Not sure why you use std_logic_vector(TO_UNSIGNED(L, S)) ? Why can't you just use TO_STDLOGICVECTOR?
You can refer here for the conversion functions: https://www.csee.umbc.edu/portal/help/VHDL/packages/numeric_std.vhd
Regards,
Nurina