Added function "GetBinName" to CovPType
Why OSVVM™? › Forums › OSVVM › Added function "GetBinName" to CovPType
- This topic has 4 replies, 3 voices, and was last updated 9 years, 8 months ago by
Torsten.
-
AuthorPosts
-
March 1, 2016 at 01:47 #1135
Sebastian Dunst
MemberHello,
In my testbench I ran into the requirement to have access to the “BinName”. Therfore I added the impure function GetBinName to CovPType.
Here is the declaration:
impure function GetBinName ( BinIndex : integer ) return string;Here is the implementation:
impure function GetBinName ( BinIndex : integer ) return string isvariable buf : line;beginif CovBinPtr(BinIndex).Name.all /= "" thenswrite(buf, CovBinPtr(BinIndex).Name.all);elseswrite(buf, "Nameless Bin");end if;return buf.all;end function GetBinName;March 1, 2016 at 03:06 #1136
Jim LewisMemberHi Sebastian,
I can add that capability in the next release.
I note that in your code, you never deallocate buf and as a result have a memory leak. You can fix this by simplifying your code to:
impure function GetBinName ( BinIndex : integer ) return string is
begin
if CovBinPtr(BinIndex).Name.all /= "" then
return CovBinPtr(BinIndex).Name.all) ;
else
return "Nameless Bin" ;
end if;
end function GetBinName;
To be consistent with other OSVVM implementations, I will implement something like the following:impure function GetBinName ( BinIndex : integer; DefaultName : string := "" ) return string is
begin
if CovBinPtr(BinIndex).Name.all /= "" then
return CovBinPtr(BinIndex).Name.all) ;
else
return DefaultName ;
end if;
end function GetBinName;Cheers,
JimMarch 1, 2016 at 13:08 #1137
Jim LewisMemberHi Sebastian
I have implemented my 2nd solution and pushed the solution to my GitHub development branch. You can find it at: https://github.com/JimLewis/OSVVM/tree/Dev
Best Regards,
Jim
March 1, 2016 at 23:01 #1138Sebastian Dunst
MemberHi Jim,
thank you very much for adding this function.But I am a little afraid that there seems to be no easy solution for handling strings with an unknown length. This is a standard issue in most of my procedures or functions.
I always thought that a “local” variable inside a function or a procedure is stored on stack and is automatically freeed when running out of scope.
So there must be something special about the type “line”. Probably some kind of a pointer, which allocates memory in the background.
But what would be your advice for creating strings with an unknown length?Thanks,
SebastianMarch 2, 2016 at 23:56 #1139
TorstenMemberLine, as defined in textio package, is string access type:
type line is access string;When I have strings of unknown length, I also use an access type. But maybe there is another option, which I don’t know…
-
AuthorPosts
- You must be logged in to reply to this topic.