From a4ea46cd5994695670a38d124daa445cb4727925 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Thu, 2 Apr 2020 16:12:10 +0100 Subject: [PATCH] Add a simple verilator simulator for module_wrap128_fromMem --- CMakeLists.txt | 13 +++++++++++++ sim_main.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 sim_main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..435fe43 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.16) +project(cap-lib-verilated) +set(CMAKE_CXX_STANDARD 14) +find_package(verilator HINTS $ENV{VERILATOR_ROOT}) +if (NOT verilator_FOUND) + message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable") +endif() +add_executable(cap128_fromMem sim_main.cpp) +if (APPLE) + # verilate() complains about --compiler appleclang otherwise + set(CMAKE_CXX_COMPILER_ID clang FORCE) +endif() +verilate(cap128_fromMem SOURCES module_wrap128_fromMem.v VERILATOR_ARGS --compiler clang) diff --git a/sim_main.cpp b/sim_main.cpp new file mode 100644 index 0000000..49e30af --- /dev/null +++ b/sim_main.cpp @@ -0,0 +1,27 @@ +#include "Vmodule_wrap128_fromMem.h" +#include "verilated.h" +#include "verilated_vpi.h" // Required to get definitions + +vluint64_t main_time = 0; // See comments in first example +double sc_time_stamp() { return main_time; } + +template constexpr size_t array_size(T (&)[N]) { return N; } + +int main(int argc, char** argv, char** env) { + Verilated::commandArgs(argc, argv); + Vmodule_wrap128_fromMem* top = new Vmodule_wrap128_fromMem; + Verilated::internalsDump(); // See scopes to help debug + for (int i = 0; i < array_size(top->wrap128_fromMem_mem_cap); i++) { + top->wrap128_fromMem_mem_cap[i] = 0; + printf("Input[%d]=%d\n", i, top->wrap128_fromMem_mem_cap[i]); + } + printf("Eval:\n"); + // while (!Verilated::gotFinish()) { + top->eval(); + //} + for (int i = 0; i < array_size(top->wrap128_fromMem); i++) { + printf("Output[%d]=%d\n", i, top->wrap128_fromMem[i]); + } + delete top; + exit(0); +}