我如何才能知道系统verilog中的当前路径?

问题描述 投票:2回答:3

我需要在我的系统verilog代码中打开一个文件,我需要知道它的相对路径才能使用$ fopen。首先,我需要知道我的立场。有没有知道我当前的目录路径? (通过使用$ display或者其他东西)

fopen relative-path system-verilog
3个回答
4
投票

基于另一个问题how-do-i-read-an-environment-variable-in-verilog-system-verilog

import "DPI-C" function string getenv(input string env_name);

module top;
  initial begin
    $write("env = %s\n", {getenv("HOME"), "/FileName"});
  end
endmodule

工作目录应该是$ PWD所以对于你的问题,你可以使用getenv("PWD")


3
投票

SystemVerilog语言中没有任何内容可以直接为您提供此信息。最简单的方法是使用$value$plusargs检索调用模拟器时从脚本中提供的命令行选项(例如+ current_directory = pathname)。

其他选择包括:

  • 导入返回当前工作目录的DPI C例程。该例程将特定于操作系统。
  • 使用特定于工具的构造,可以访问模拟命令行。 ModelSim有一个可以导入的mti_fli包,它允许您执行Tcl命令并将结果作为字符串返回。
  • 使用 `__ FILE__ 宏以获取它作为字符串出现的文件的路径,并以某种方式剥离到目录路径输出正在寻找。

1
投票

只是为了完成,这是一个如何从中提取路径的示例

`FILE

从该已知路径,用户可以创建到任何地方的相对路径。

path=get_path_from_file(`__FILE__);

function string get_path_from_file(string fullpath_filename);
    int i;
    int str_index;
    logic found_path;
    string ret="";


    for (i = fullpath_filename.len()-1; i>0; i=i-1) begin
        if (fullpath_filename[i] == "/") begin
            found_path=1;
            str_index=i;
            break;
        end
    end
    if (found_path==1) begin
        ret=fullpath_filename.substr(0,str_index);
    end else begin
       // `uvm_error("pve_get_path_from_file-1", $sformatf("Not found a valid path for this file: %s",fullpath_filename));
    end
        

    return ret;
endfunction
© www.soinside.com 2019 - 2024. All rights reserved.