I'm trying to give simulation output file folder as a generic for testbench. The testbench would first set the generic to some globally available variable and then different blocks could access this variable to determine the output folder.
The reason for this is that now a do-file could start multiple simulations where the results would be put into different folders without the need to recompile VHDL.
Below is what I've managed to achieve so far and it works, but seems awfully clunky.
Is there a better way?
.do file:
set dirname ./SimsetSmall/
exec mkdir -p $dirname
vsim -G tb/gFolder=$dirname tb_opt ; run 1 us
MyPackage body:
type tProtectedFileName is protected
body
variable vF : tFileName := new string'("./");
impure function Get return string is
begin
return vF.all;
end function Get;
procedure Set (constant fIn : in string) is
begin
deallocate(vF);
vF := new string'(fIN);
end procedure Set;
end protected body tProtectedFileName;
shared variable svSimFolder : tProtectedFileName;
impure function ifGetSimFolder return string is
begin
return svSimFolder.Get;
end function ifGetSimFolder;
procedure pSetSimFolder (constant fIn : in string) is
begin
svSimFolder.Set(fIn);
end procedure pSetSimFolder;
And finally, the VHDL file:
library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;
use ieee.std_logic_textio.all;
use work.MyPackage.all;
entity tb is
generic (gFolder : string);
end entity tb;
architecture sim of tb is
begin
process
begin
pSetSimFolder(gFolder);
wait;
end process;
-- in some other entity without gFolder:
process
file f : text;
begin
wait for 1 ns;
file_open(f, ifGetSimFolder & "thissim.txt", write_mode);
file_close(f);
wait;
end process;
end architecture sim;
Specifically:
- Do I really need to have the procedure and impure function to call
the Set and Get in the protected shared variable and cannot access
them directly? - Are there other (simpler) mechanics to achieve the same?
- The Set procedure needs to dereference the vF access type. Is the deallocate/new the only/best way to do this?
I know I could propagate the top level generic down to all blocks, but that is what I try to avoid.