Skip to content

Commit

Permalink
[nix] refactor difftest to share common build logic
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Sep 8, 2024
1 parent ea7b59b commit e056a6f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 102 deletions.
18 changes: 11 additions & 7 deletions difftest/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -47,7 +51,7 @@ rustPlatform.buildRustPackage {
};

passthru = {
dpiLibPath = "/lib/libdpi_${buildType}.a";
dpiLibPath = "/lib/libdpi_${moduleType}.a";
inherit enableTrace;
};
}
38 changes: 0 additions & 38 deletions difftest/offline-checker-t1.nix

This file was deleted.

35 changes: 0 additions & 35 deletions difftest/offline-checker-t1rocket.nix

This file was deleted.

25 changes: 14 additions & 11 deletions nix/t1/t1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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 {
Expand All @@ -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

Expand Down
25 changes: 14 additions & 11 deletions nix/t1/t1rocket.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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;
Expand Down

0 comments on commit e056a6f

Please sign in to comment.