在VHDL中,如何在打开文件之前检查文件是否存在?

pic*_*ico 1 vhdl

在Verilog中,我可以通过打开文件然后检查文件描述符是否为零以及是否不假设文件不存在来检查文件是否存在。例如,如下:

    module testbench;

    function file_exists;
        input [80*8:0] filename;        
        integer        file;
        integer        error;
    begin
        file = $fopen(filename, "r");
        if (!file) begin
           $display("\nFile Open Failed with Error Code = %x", error); 
           file_exists = 0;
        end
        else begin
           $fclose(file);
           file_exists = 1;
        end
    end
    endfunction

    integer x;
    initial begin
       x = file_exists("sdfsdf.txt");
       $display("x: %0b", x);          
    end

    endmodule
Run Code Online (Sandbox Code Playgroud)

如何在vhdl中做同样的事情?

las*_*und 5

打开文件时,例如:

file_open(status, file_handle, “my_file.txt”, read_mode);
Run Code Online (Sandbox Code Playgroud)

您的状态为file_open_status。它可以有多个值:open_okstatus_errorname_errormode_errorname_error如果找不到文件,您将得到