Skip to content

Commit

Permalink
[difftest] remove DPI C++ trampoline
Browse files Browse the repository at this point in the history
  • Loading branch information
FanShupei authored and sequencer committed Jul 20, 2024
1 parent 9f976f1 commit f07694a
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 278 deletions.
15 changes: 7 additions & 8 deletions difftest/online_drive/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ fn main() {
#[cfg(not(feature = "trace"))]
let dst = Config::new("dpi_c").very_verbose(true).always_configure(true).build();

println!("cargo:rustc-link-search=native={}/lib", dst.display());
println!("cargo::rustc-link-search=native={}/lib", dst.display());

// link order matters!
// verilator_main <- VTestBench <-- verilated <- dpi_c <- stdc++
// verilated <- libz
// that's why we must split verilator_main and dpi_c
println!("cargo:rustc-link-lib=static=dpi_pre_link");
println!("cargo:rustc-link-lib=static=VTestBench");
println!("cargo:rustc-link-lib=static=verilated");
println!("cargo:rustc-link-lib=static=dpi");
println!("cargo:rustc-link-lib=static=stdc++");
println!("cargo:rustc-link-lib=dylib=z");
println!("cargo:rerun-if-env-changed=VERILATED_LIB_DIR");
println!("cargo::rustc-link-lib=static=dpi_pre_link");
println!("cargo::rustc-link-lib=static=VTestBench");
println!("cargo::rustc-link-lib=static=verilated");
println!("cargo::rustc-link-lib=stdc++");
println!("cargo::rustc-link-lib=z");
println!("cargo::rerun-if-env-changed=VERILATED_LIB_DIR");
}
14 changes: 1 addition & 13 deletions difftest/online_drive/dpi_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ message(STATUS "Project '${PROJECT_NAME}' build type: ${CMAKE_BUILD_TYPE}")

set(THREADS_PREFER_PTHREAD_FLAG ON)

add_library(dpi
STATIC
dpi.cc
)

add_library(dpi_pre_link
STATIC
dpi_pre_link.cc
Expand All @@ -30,21 +25,14 @@ if (NOT DEFINED VERILATED_INC_DIR)
endif()
endif()

# include verilated headers
target_include_directories(dpi PUBLIC ${VERILATED_INC_DIR})
target_include_directories(dpi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# include verilator headers
find_package(verilator REQUIRED)
message(STATUS "Found verilator: ${verilator_DIR}")
target_include_directories(dpi PUBLIC ${verilator_DIR}/include)
target_include_directories(dpi PUBLIC ${verilator_DIR}/include/vltstd)
target_include_directories(dpi_pre_link PUBLIC ${verilator_DIR}/include)
target_include_directories(dpi_pre_link PUBLIC ${verilator_DIR}/include/vltstd)

if(DEFINED VM_TRACE)
target_compile_definitions(dpi PRIVATE VM_TRACE=1)
target_compile_definitions(dpi_pre_link PRIVATE VM_TRACE=1)
endif()

install(TARGETS dpi dpi_pre_link ARCHIVE)
install(TARGETS dpi_pre_link ARCHIVE)
96 changes: 0 additions & 96 deletions difftest/online_drive/dpi_c/dpi.cc

This file was deleted.

92 changes: 0 additions & 92 deletions difftest/online_drive/dpi_c/dpi.h

This file was deleted.

16 changes: 8 additions & 8 deletions difftest/online_drive/dpi_c/dpi_pre_link.cc
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#include <VTestBench.h>
#include <VTestBench__Dpi.h>

#include "dpi_pre_link.h"

class VTestBench;

VerilatedContext *contextp;
VTestBench *topp;
static VerilatedContext *contextp;
static VTestBench *topp;

int verilator_main_c(int argc, char **argv) {
extern "C" int verilator_main_c(int argc, char **argv) {
// Setup context, defaults, and parse command line
Verilated::debug(0);
contextp = new VerilatedContext();
contextp->fatalOnError(false);
contextp->commandArgs(argc, argv);
#ifdef VM_TRACE
contextp->traceEverOn(true);
#endif

// Construct the Verilated model, from Vtop.h generated from Verilating
topp = new VTestBench(contextp);
Expand Down Expand Up @@ -42,14 +43,13 @@ int verilator_main_c(int argc, char **argv) {
}

#ifdef VM_TRACE
void dump_wave_c(char *path) {
Verilated::traceEverOn(true);
extern "C" void dump_wave_c(char *path) {
svSetScope(svGetScopeFromName("TOP.TestBench.clockGen"));
dump_wave(path);
}
#endif

uint64_t get_t_c() {
extern "C" uint64_t get_t_c() {
if (contextp) {
return contextp->time();
} else { // before ctx is initialized
Expand Down
24 changes: 0 additions & 24 deletions difftest/online_drive/dpi_c/dpi_pre_link.h

This file was deleted.

Loading

0 comments on commit f07694a

Please sign in to comment.