-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
问题描述
由于chisel导出的verilog没有数组,所以chisel导出的verilog代码可能无法直接用于difftest仿真。
例如,直接用verilog描述的信号为:
Output [7:0] test [3:0];使用chisel的描述语句为
val test = Vec(4, UInt(8.W))将该代码生成verilog,声明的端口自动会转换为
...
output [7:0] test_0,
output [7:0] test_1,
output [7:0] test_2,
output [7:0] test_3,
...解决方法
最简单的解决方法是直接在生成的Verilog中对不符合接口规范的语句进行替换。
这是我用Python创建的修改脚本replace.py。
其中的几个变量str_tobe_replace_1 str_tobe_replace_2 str_tobe_replace_3需要根据你的实际代码进行一定的修改。
# 源文件路径(默认导出的文件覆盖原文件)
file_path = "./generated/oscpu2/SimTop.v"
str_tobe_replace_1 = ''' output [63:0] io_memAXI_0_w_bits_data_0,
output [63:0] io_memAXI_0_w_bits_data_1,
output [63:0] io_memAXI_0_w_bits_data_2,
output [63:0] io_memAXI_0_w_bits_data_3,'''
str_new_1 = ''' output [63:0] io_memAXI_0_w_bits_data [3:0], // !!! generated by python'''
str_tobe_replace_2 = ''' input [63:0] io_memAXI_0_r_bits_data_0,
input [63:0] io_memAXI_0_r_bits_data_1,
input [63:0] io_memAXI_0_r_bits_data_2,
input [63:0] io_memAXI_0_r_bits_data_3,'''
str_new_2 = ''' input [63:0] io_memAXI_0_r_bits_data [3:0], // !!! generated by python'''
str_tobe_replace_3 = ''' wire [63:0] axi_mem_io_mem_data_read; '''
str_new_3 = ''' wire [63:0] axi_mem_io_mem_data_read;
wire [63:0] io_memAXI_0_w_bits_data_0;
wire [63:0] io_memAXI_0_w_bits_data_1;
wire [63:0] io_memAXI_0_w_bits_data_2;
wire [63:0] io_memAXI_0_w_bits_data_3;
assign io_memAXI_0_w_bits_data[0] = io_memAXI_0_w_bits_data_0 ;
assign io_memAXI_0_w_bits_data[1] = io_memAXI_0_w_bits_data_1 ;
assign io_memAXI_0_w_bits_data[2] = io_memAXI_0_w_bits_data_2 ;
assign io_memAXI_0_w_bits_data[3] = io_memAXI_0_w_bits_data_3 ;
wire [63:0] io_memAXI_0_r_bits_data_0;
wire [63:0] io_memAXI_0_r_bits_data_1;
wire [63:0] io_memAXI_0_r_bits_data_2;
wire [63:0] io_memAXI_0_r_bits_data_3;
assign io_memAXI_0_r_bits_data_0 = io_memAXI_0_r_bits_data[0];
assign io_memAXI_0_r_bits_data_1 = io_memAXI_0_r_bits_data[1];
assign io_memAXI_0_r_bits_data_2 = io_memAXI_0_r_bits_data[2];
assign io_memAXI_0_r_bits_data_3 = io_memAXI_0_r_bits_data[3];
'''
file_content = ""
with open(file_path, "r") as f:
file_content = f.read()
file_content = file_content.replace(str_tobe_replace_1, str_new_1)
file_content = file_content.replace(str_tobe_replace_2, str_new_2)
file_content = file_content.replace(str_tobe_replace_3, str_new_3)
with open(file_path, "w+") as f:
f.write(file_content)同时为了方便将处理好的verilog源文件复制到进行difftest的仿真路径,可以使用下面的shell脚本,一键编译verilog和修改源码(需要根据实际目录修改一些路径)。
sbt "test:runMain oscpu2.verilog_TopMain_oscpu2"
python replace.py
sed -i '1i\`timescale 1ns / 10ps' ./generated/oscpu2/SimTop.v
cp ./generated/oscpu2/SimTop.v ../projects/czcpu_axi_diff/vsrc/SimTop.vReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels