From 1a88d9f46134872608110ba85a4c2b59810b4f5d Mon Sep 17 00:00:00 2001 From: Taichi Ishitani Date: Mon, 30 May 2022 20:41:20 +0900 Subject: [PATCH] support vivado simulator refs: https://github.com/rggen/rggen-sample-testbench/issues/5#issuecomment-1140579026 https://github.com/rggen/rggen-sample-testbench/issues/5#issuecomment-1140702586 --- rggen_backdoor.sv | 5 +-- rggen_backdoor_pkg.sv | 90 ++++++++++++++++++++++++++++--------------- 2 files changed, 62 insertions(+), 33 deletions(-) diff --git a/rggen_backdoor.sv b/rggen_backdoor.sv index 87d8b00..cae70c1 100644 --- a/rggen_backdoor.sv +++ b/rggen_backdoor.sv @@ -1,7 +1,6 @@ `ifdef RGGEN_ENABLE_BACKDOOR module rggen_backdoor #( - parameter int DATA_WIDTH = 32, - parameter bit INSIDE_VHDL_DESIGN = 0 + parameter int DATA_WIDTH = 32 )( input logic i_clk, input logic i_rst_n, @@ -39,7 +38,7 @@ module rggen_backdoor #( end initial begin - rggen_backdoor_pkg::set_backdoor_vif($sformatf("%m"), INSIDE_VHDL_DESIGN, backdoor_if); + rggen_backdoor_pkg::set_backdoor_vif($sformatf("%m"), backdoor_if); end endmodule `endif diff --git a/rggen_backdoor_pkg.sv b/rggen_backdoor_pkg.sv index 6c882c4..dce0576 100644 --- a/rggen_backdoor_pkg.sv +++ b/rggen_backdoor_pkg.sv @@ -4,43 +4,73 @@ `ifdef RGGEN_ENABLE_BACKDOOR package rggen_backdoor_pkg; typedef virtual rggen_backdoor_if rggen_backdoor_vif; - rggen_backdoor_vif backdoor_vif[string]; - function automatic void set_backdoor_vif( - string hdl_path, - bit inside_vhdl_design, - rggen_backdoor_vif vif - ); - string path; + class rggen_backdoor_if_store; +`ifndef XILINX_SIMULATOR + protected rggen_backdoor_vif vif[string]; - if (inside_vhdl_design) begin - path = normalize_hdl_path(hdl_path); - end - else begin - path = hdl_path; - end + function void set(string hdl_path, rggen_backdoor_vif vif); + string path; + path = normalize_hdl_path(hdl_path); + this.vif[path] = vif; + endfunction - backdoor_vif[path] = vif; - endfunction + function rggen_backdoor_vif get(string hdl_path); + return vif[hdl_path]; + endfunction +`else + class rggen_backdoor_if_wrapper; + rggen_backdoor_vif vif; + function new(rggen_backdoor_vif vif); + this.vif = vif; + endfunction + endclass + + protected rggen_backdoor_if_wrapper vif_wrapper[string]; - function automatic string normalize_hdl_path( - string original_path + function void set(string hdl_path, rggen_backdoor_vif vif); + string path; + path = normalize_hdl_path(hdl_path); + this.vif_wrapper[path] = new(vif); + endfunction + + function rggen_backdoor_vif get(string hdl_path); + return vif_wrapper[hdl_path].vif; + endfunction +`endif + protected function string normalize_hdl_path(string path); + string normalized_path; + for (int i = 0;i < path.len();++i) begin + if ((path[i] != "\\") && (path[i] != " ")) begin + normalized_path = {normalized_path, path[i]}; + end + end + return normalized_path.tolower(); + endfunction + + static protected rggen_backdoor_if_store store; + + static function rggen_backdoor_if_store get_store(); + if (store == null) begin + store = new; + end + return store; + endfunction + endclass + + function automatic void set_backdoor_vif( + string hdl_path, + rggen_backdoor_vif vif ); - string path; - path = original_path; - if (path[0] == "\\") begin - path = path.substr(1, path.len() - 1); - end - if (path[path.len()-1] == " ") begin - path = path.substr(0, path.len() - 2); - end - return path.tolower(); + rggen_backdoor_if_store store; + store = rggen_backdoor_if_store::get_store(); + store.set(hdl_path, vif); endfunction - function automatic rggen_backdoor_vif get_backdoor_vif( - string hdl_path - ); - return backdoor_vif[hdl_path]; + function automatic rggen_backdoor_vif get_backdoor_vif(string hdl_path); + rggen_backdoor_if_store store; + store = rggen_backdoor_if_store::get_store(); + return store.get(hdl_path); endfunction endpackage `endif