diff --git a/difftest/default.nix b/difftest/default.nix index 621458011..2234a7ce6 100644 --- a/difftest/default.nix +++ b/difftest/default.nix @@ -6,13 +6,17 @@ }: { outputName -, emuType -, buildType +, emuType ? "" +, moduleType , enableTrace ? false }: -assert lib.assertMsg (lib.elem emuType [ "verilator" "vcs" ]) "emuType is either 'vcs' nor 'verilator'"; -assert lib.assertMsg (lib.elem buildType [ "t1" "t1rocket" ]) "emuType is either 't1' nor 't1rocket'"; +assert let + available = [ "dpi_t1" "dpi_t1rocket" "offline_t1" "offline_t1rocket" ]; +in +lib.assertMsg (lib.elem moduleType available) "emuType is not in ${lib.concatStringsSep ", " available}"; +# if emuType is empty, then moduleType must be offline-*, or user should give valid emuType +assert lib.assertMsg ((emuType == "" && lib.hasPrefix "offline" moduleType) || (lib.elem emuType [ "verilator" "vcs" ])) "emuType is either 'vcs' nor 'verilator'"; rustPlatform.buildRustPackage { name = outputName; @@ -31,8 +35,8 @@ rustPlatform.buildRustPackage { ]; }; - buildFeatures = [ "dpi_common/${emuType}" ] ++ lib.optionals enableTrace [ "dpi_common/trace" ]; - buildAndTestSubdir = "./dpi_${buildType}"; + buildFeatures = [ ] ++ lib.optionals (lib.hasPrefix "dpi" moduleType) [ "dpi_common/${emuType}" ] ++ lib.optionals enableTrace [ "dpi_common/trace" ]; + buildAndTestSubdir = "./${moduleType}"; env = { SPIKE_LIB_DIR = "${libspike}/lib"; @@ -47,7 +51,7 @@ rustPlatform.buildRustPackage { }; passthru = { - dpiLibPath = "/lib/libdpi_${buildType}.a"; + dpiLibPath = "/lib/libdpi_${moduleType}.a"; inherit enableTrace; }; } diff --git a/difftest/offline-checker-t1.nix b/difftest/offline-checker-t1.nix deleted file mode 100644 index bdb498074..000000000 --- a/difftest/offline-checker-t1.nix +++ /dev/null @@ -1,38 +0,0 @@ -{ lib -, rustPlatform -, libspike -, libspike_interfaces -, rtlDesignMetadata -}: - -rustPlatform.buildRustPackage { - name = "offline-checker-t1"; - src = with lib.fileset; toSource { - root = ./.; - fileset = unions [ - ./spike_rs - ./offline_t1 - ./dpi_common - ./dpi_t1 - ./dpi_t1rocket - ./test_common - ./Cargo.lock - ./Cargo.toml - ]; - }; - - buildFeatures = [ ]; - buildAndTestSubdir = "./offline_t1"; - - env = { - SPIKE_LIB_DIR = "${libspike}/lib"; - SPIKE_INTERFACES_LIB_DIR = "${libspike_interfaces}/lib"; - DESIGN_VLEN = rtlDesignMetadata.vlen; - DESIGN_DLEN = rtlDesignMetadata.dlen; - SPIKE_ISA_STRING = rtlDesignMetadata.march; - }; - - cargoLock = { - lockFile = ./Cargo.lock; - }; -} diff --git a/difftest/offline-checker-t1rocket.nix b/difftest/offline-checker-t1rocket.nix deleted file mode 100644 index 76f6cc5ec..000000000 --- a/difftest/offline-checker-t1rocket.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ lib -, rustPlatform -, libspike -, libspike_interfaces -, rtlDesignMetadata -}: - -rustPlatform.buildRustPackage { - name = "offline-checker-t1rocket"; - src = with lib.fileset; toSource { - root = ./.; - fileset = unions [ - ./spike_rs - ./offline_t1rocket - ./test_common - ./Cargo.lock - ./Cargo.toml - ]; - }; - - buildFeatures = [ ]; - buildAndTestSubdir = "./offline_t1rocket"; - - env = { - SPIKE_LIB_DIR = "${libspike}/lib"; - SPIKE_INTERFACES_LIB_DIR = "${libspike_interfaces}/lib"; - DESIGN_VLEN = rtlDesignMetadata.vlen; - DESIGN_DLEN = rtlDesignMetadata.dlen; - SPIKE_ISA_STRING = rtlDesignMetadata.march; - }; - - cargoLock = { - lockFile = ./Cargo.lock; - }; -} diff --git a/nix/t1/t1.nix b/nix/t1/t1.nix index 51e31309f..3f6daa337 100644 --- a/nix/t1/t1.nix +++ b/nix/t1/t1.nix @@ -97,17 +97,17 @@ lib.mapAttrs # --------------------------------------------------------------------------------- # VERILATOR # --------------------------------------------------------------------------------- - makeDPI = ipScope.callPackage ../../difftest { }; + makeDifftest = ipScope.callPackage ../../difftest { }; - verilator-dpi-lib = ipScope.makeDPI { + verilator-dpi-lib = ipScope.makeDifftest { outputName = "t1-verilator-dpi-lib"; emuType = "verilator"; - buildType = "t1"; + moduleType = "dpi_t1"; }; - verilator-dpi-lib-trace = ipScope.makeDPI { + verilator-dpi-lib-trace = ipScope.makeDifftest { outputName = "t1-verilator-trace-dpi-lib"; emuType = "verilator"; - buildType = "t1"; + moduleType = "dpi_t1"; enableTrace = true; }; @@ -126,16 +126,21 @@ lib.mapAttrs # --------------------------------------------------------------------------------- # VCS # --------------------------------------------------------------------------------- - vcs-dpi-lib = ipScope.makeDPI { + vcs-dpi-lib = ipScope.makeDifftest { outputName = "t1-vcs-dpi-lib"; emuType = "vcs"; - buildType = "t1"; + moduleType = "dpi_t1"; }; - vcs-dpi-lib-trace = ipScope.makeDPI { + vcs-dpi-lib-trace = ipScope.makeDifftest { outputName = "t1-vcs-dpi-trace-lib"; emuType = "vcs"; enableTrace = true; - buildType = "t1"; + moduleType = "dpi_t1"; + }; + + offline-checker = ipScope.makeDifftest { + outputName = "t1-offline-checker"; + moduleType = "offline_t1"; }; vcs-emu = t1Scope.sv-to-vcs-simulator { @@ -150,8 +155,6 @@ lib.mapAttrs vcsLinkLibs = [ "${ipScope.vcs-dpi-lib-trace}/lib/libdpi_t1.a" ]; }; - offline-checker = ipScope.callPackage ../../difftest/offline-checker-t1.nix { }; - run = ipScope.callPackage ./run { }; }); # end of ipScope diff --git a/nix/t1/t1rocket.nix b/nix/t1/t1rocket.nix index a00c017e0..14beac45d 100644 --- a/nix/t1/t1rocket.nix +++ b/nix/t1/t1rocket.nix @@ -41,14 +41,14 @@ ]; }; - makeDPI = scope.callPackage ../../difftest { }; - verilator-dpi-lib = scope.makeDPI { + mkDifftest = scope.callPackage ../../difftest { }; + verilator-dpi-lib = scope.makeDifftest { outputName = "t1rocket-verilator-dpi-lib"; - buildType = "t1rocket"; + moduleType = "dpi_t1rocket"; }; - verilator-dpi-lib-trace = scope.makeDPI { + verilator-dpi-lib-trace = scope.makeDifftest { outputName = "t1rocket-verilator-trace-dpi-lib"; - buildType = "t1rocket"; + moduleType = "dpi_t1rocket"; enableTrace = true; }; @@ -72,20 +72,23 @@ ]; }; - offline-checker = scope.callPackage ../../difftest/offline-checker-t1rocket { }; - - vcs-dpi-lib = scope.makeDPI { + vcs-dpi-lib = scope.makeDifftest { outputName = "t1rocket-vcs-dpi-lib"; - buildType = "t1rocket"; + moduleType = "dpi_t1rocket"; emuType = "vcs"; }; - vcs-dpi-lib-trace = scope.makeDPI { + vcs-dpi-lib-trace = scope.makeDifftest { outputName = "t1rocket-vcs-dpi-trace-lib"; - buildType = "t1rocket"; + moduleType = "dpi_t1rocket"; emuType = "vcs"; enableTrace = true; }; + offline-checker = scope.makeDifftest { + outputName = "t1rocket-offline-checker"; + moduleType = "offline_t1rocket"; + }; + vcs-emu = sv-to-vcs-simulator { mainProgram = "t1rocket-vcs-simulator"; rtl = scope.rtl;