zachjs / sv2v

SystemVerilog to Verilog conversion
BSD 3-Clause "New" or "Revised" License
497 stars 50 forks source link

'parameter type' refers to wrong type #254

Closed elementary-particle closed 9 months ago

elementary-particle commented 9 months ago

I tried to convert the sources of cva6 https://github.com/openhwgroup/cva6.git (commit 5b37393a2ec3cac40bd46de055ea0344f662a71a) to verilog using the following command from the parent directory of cva6:

sv2v -w convert/ -Icva6/vendor/pulp-platform/common_cells/include/ -Icva6/vendor/pulp-platform/common_cells/src/ -Icva6/common/local/util/ cva6/vendor/pulp-platform/fpga-support/rtl/SyncDpRam.sv cva6/vendor/pulp-platform/fpga-support/rtl/AsyncDpRam.sv cva6/vendor/pulp-platform/fpga-support/rtl/AsyncThreePortRam.sv cva6/vendor/openhwgroup/cvfpu/src/fpnew_pkg.sv cva6/vendor/openhwgroup/cvfpu/src/fpnew_cast_multi.sv cva6/vendor/openhwgroup/cvfpu/src/fpnew_classifier.sv cva6/vendor/openhwgroup/cvfpu/src/fpnew_divsqrt_multi.sv cva6/vendor/openhwgroup/cvfpu/src/fpnew_fma_multi.sv cva6/vendor/openhwgroup/cvfpu/src/fpnew_fma.sv cva6/vendor/openhwgroup/cvfpu/src/fpnew_noncomp.sv cva6/vendor/openhwgroup/cvfpu/src/fpnew_opgroup_block.sv cva6/vendor/openhwgroup/cvfpu/src/fpnew_opgroup_fmt_slice.sv cva6/vendor/openhwgroup/cvfpu/src/fpnew_opgroup_multifmt_slice.sv cva6/vendor/openhwgroup/cvfpu/src/fpnew_rounding.sv cva6/vendor/openhwgroup/cvfpu/src/fpnew_top.sv cva6/vendor/openhwgroup/cvfpu/src/fpu_div_sqrt_mvp/hdl/defs_div_sqrt_mvp.sv cva6/vendor/openhwgroup/cvfpu/src/fpu_div_sqrt_mvp/hdl/control_mvp.sv cva6/vendor/openhwgroup/cvfpu/src/fpu_div_sqrt_mvp/hdl/div_sqrt_top_mvp.sv cva6/vendor/openhwgroup/cvfpu/src/fpu_div_sqrt_mvp/hdl/iteration_div_sqrt_mvp.sv cva6/vendor/openhwgroup/cvfpu/src/fpu_div_sqrt_mvp/hdl/norm_div_sqrt_mvp.sv cva6/vendor/openhwgroup/cvfpu/src/fpu_div_sqrt_mvp/hdl/nrbd_nrsc_mvp.sv cva6/vendor/openhwgroup/cvfpu/src/fpu_div_sqrt_mvp/hdl/preprocess_mvp.sv cva6/core/include/config_pkg.sv cva6/core/include/cv64a6_imafdc_sv39_config_pkg.sv cva6/core/include/riscv_pkg.sv cva6/core/include/ariane_pkg.sv cva6/vendor/pulp-platform/axi/src/axi_pkg.sv cva6/core/include/wt_cache_pkg.sv cva6/core/include/std_cache_pkg.sv cva6/core/include/instr_tracer_pkg.sv cva6/core/include/acc_pkg.sv cva6/core/include/cvxif_pkg.sv cva6/core/cvxif_example/include/cvxif_instr_pkg.sv cva6/core/cvxif_fu.sv cva6/core/cvxif_example/cvxif_example_coprocessor.sv cva6/core/cvxif_example/instr_decoder.sv cva6/vendor/pulp-platform/common_cells/src/cf_math_pkg.sv cva6/vendor/pulp-platform/common_cells/src/fifo_v3.sv cva6/vendor/pulp-platform/common_cells/src/lfsr.sv cva6/vendor/pulp-platform/common_cells/src/lfsr_8bit.sv cva6/vendor/pulp-platform/common_cells/src/stream_arbiter.sv cva6/vendor/pulp-platform/common_cells/src/stream_arbiter_flushable.sv cva6/vendor/pulp-platform/common_cells/src/stream_mux.sv cva6/vendor/pulp-platform/common_cells/src/stream_demux.sv cva6/vendor/pulp-platform/common_cells/src/lzc.sv cva6/vendor/pulp-platform/common_cells/src/rr_arb_tree.sv cva6/vendor/pulp-platform/common_cells/src/shift_reg.sv cva6/vendor/pulp-platform/common_cells/src/unread.sv cva6/vendor/pulp-platform/common_cells/src/popcount.sv cva6/vendor/pulp-platform/common_cells/src/exp_backoff.sv cva6/vendor/pulp-platform/common_cells/src/counter.sv cva6/vendor/pulp-platform/common_cells/src/delta_counter.sv cva6/core/cva6.sv cva6/core/alu.sv cva6/core/fpu_wrap.sv cva6/core/branch_unit.sv cva6/core/compressed_decoder.sv cva6/core/controller.sv cva6/core/csr_buffer.sv cva6/core/csr_regfile.sv cva6/core/decoder.sv cva6/core/ex_stage.sv cva6/core/instr_realign.sv cva6/core/id_stage.sv cva6/core/issue_read_operands.sv cva6/core/issue_stage.sv cva6/core/load_unit.sv cva6/core/load_store_unit.sv cva6/core/lsu_bypass.sv cva6/core/mult.sv cva6/core/multiplier.sv cva6/core/serdiv.sv cva6/core/perf_counters.sv cva6/core/ariane_regfile_ff.sv cva6/core/ariane_regfile_fpga.sv cva6/core/scoreboard.sv cva6/core/store_buffer.sv cva6/core/amo_buffer.sv cva6/core/store_unit.sv cva6/core/commit_stage.sv cva6/core/axi_shim.sv cva6/core/cva6_accel_first_pass_decoder_stub.sv cva6/core/acc_dispatcher.sv cva6/core/frontend/btb.sv cva6/core/frontend/bht.sv cva6/core/frontend/ras.sv cva6/core/frontend/instr_scan.sv cva6/core/frontend/instr_queue.sv cva6/core/frontend/frontend.sv cva6/core/cache_subsystem/wt_dcache_ctrl.sv cva6/core/cache_subsystem/wt_dcache_mem.sv cva6/core/cache_subsystem/wt_dcache_missunit.sv cva6/core/cache_subsystem/wt_dcache_wbuffer.sv cva6/core/cache_subsystem/wt_dcache.sv cva6/core/cache_subsystem/cva6_icache.sv cva6/core/cache_subsystem/wt_cache_subsystem.sv cva6/core/cache_subsystem/wt_axi_adapter.sv cva6/core/cache_subsystem/tag_cmp.sv cva6/core/cache_subsystem/axi_adapter.sv cva6/core/cache_subsystem/miss_handler.sv cva6/core/cache_subsystem/cache_ctrl.sv cva6/core/cache_subsystem/cva6_icache_axi_wrapper.sv cva6/core/cache_subsystem/std_cache_subsystem.sv cva6/core/cache_subsystem/std_nbdcache.sv cva6/core/pmp/src/pmp.sv cva6/core/pmp/src/pmp_entry.sv cva6/common/local/util/instr_tracer_if.sv cva6/common/local/util/instr_tracer.sv cva6/common/local/util/tc_sram_wrapper.sv cva6/vendor/pulp-platform/tech_cells_generic/src/rtl/tc_sram.sv cva6/common/local/util/sram.sv cva6/core/mmu_sv39/mmu.sv cva6/core/mmu_sv39/ptw.sv cva6/core/mmu_sv39/tlb.sv cva6/core/mmu_sv32/cva6_mmu_sv32.sv cva6/core/mmu_sv32/cva6_ptw_sv32.sv cva6/core/mmu_sv32/cva6_tlb_sv32.sv cva6/core/mmu_sv32/cva6_shared_tlb_sv32.sv -DVERILATOR -v

However, the program wrongly considers the parameter type acc_req_t in module acc_dispatcher(cva6/core/acc_dispatcher.sv) which is of type acc_pkg::accelerator_req_t as of cvxif_pkg::cvxif_req_t, causing an error on line 210 of cva6/core/acc_dispatcher.sv.

sv2v: field 'insn' not found in struct packed { logic x_compressed_valid; struct packed { logic [15:0] instr; logic [1:0] mode; logic [acc_dispatcher_71D35.acc_req_t_cvxif_pkg_X_ID_WIDTH - 1:0] id; } x_compressed_req; logic x_issue_valid; struct packed { logic [31:0] instr; logic [1:0] mode; logic [acc_dispatcher_71D35.acc_req_t_cvxif_pkg_X_ID_WIDTH - 1:0] id; logic [acc_dispatcher_71D35.acc_req_t_cvxif_pkg_X_NUM_RS - 1:0][acc_dispatcher_71D35.acc_req_t_cvxif_pkg_X_RFR_WIDTH - 1:0] rs; logic [acc_dispatcher_71D35.acc_req_t_cvxif_pkg_X_NUM_RS - 1:0] rs_valid; } x_issue_req; logic x_commit_valid; struct packed { logic [acc_dispatcher_71D35.acc_req_t_cvxif_pkg_X_ID_WIDTH - 1:0] id; logic x_commit_kill; } x_commit; logic x_mem_ready; struct packed { logic exc; logic [5:0] exccode; } x_mem_resp; logic x_mem_result_valid; struct packed { logic [acc_dispatcher_71D35.acc_req_t_cvxif_pkg_X_ID_WIDTH - 1:0] id; logic [acc_dispatcher_71D35.acc_req_t_cvxif_pkg_X_MEM_WIDTH - 1:0] rdata; logic err; } x_mem_result; logic x_result_ready; }, in expression acc_req_o.insn, within scope acc_dispatcher_71D35, near cva6/core/acc_dispatcher.sv:210:3 CallStack (from HasCallStack): error, called at src/Convert/Scoper.hs:377:22 in main:Convert.Scoper

elementary-particle commented 9 months ago

I was using the released Linux version sv2v v0.0.11-0-g6082cae

zachjs commented 9 months ago

In cva6.sv, acc_dispatcher is indeed instantiated with cvxif_req_t = cvxif_pkg::cvxif_req_t. The complaint about acc_dispatcher_71D35 is referring to this instantiation of acc_dispatcher that references a struct field that doesn't seem to exist. I think this error is genuine. Am I missing something? See #155 for some additional background on this error checking.

elementary-particle commented 9 months ago

Sorry, you are right, I was too confident with the code in the repository, I'll double check next time I submit a issue. Thanks for your reply!