Skip to content

Commit

Permalink
[nix] refactor whole test attribute under emulator
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Aug 14, 2024
1 parent b269e1e commit a800c2c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
14 changes: 7 additions & 7 deletions difftest/verilator.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
, rust-bindgen

, verilator
, verilated
, verilator-emu-rtl-verilated
, cmake
, clang-tools

Expand All @@ -20,7 +20,7 @@

let
self = rustPlatform.buildRustPackage {
name = "verilator-emu" + (lib.optionalString verilated.enable-trace "-trace");
name = "verilator-emu" + (lib.optionalString verilator-emu-rtl-verilated.enable-trace "-trace");

src = with lib.fileset; toSource {
root = ./.;
Expand All @@ -38,19 +38,19 @@ let

buildInputs = [
libspike_interfaces
verilated
verilator-emu-rtl-verilated
];

nativeBuildInputs = [
verilator
cmake
];

buildFeatures = lib.optionals verilated.enable-trace [ "trace" ];
buildFeatures = lib.optionals verilator-emu-rtl-verilated.enable-trace [ "trace" ];

env = {
VERILATED_INC_DIR = "${verilated}/include";
VERILATED_LIB_DIR = "${verilated}/lib";
VERILATED_INC_DIR = "${verilator-emu-rtl-verilated}/include";
VERILATED_LIB_DIR = "${verilator-emu-rtl-verilated}/lib";
SPIKE_LIB_DIR = "${libspike}/lib";
SPIKE_INTERFACES_LIB_DIR = "${libspike_interfaces}/lib";
SPIKE_ISA_STRING =
Expand All @@ -77,7 +77,7 @@ let
});

inherit libspike_interfaces rtlDesignMetadata;
inherit (verilated) enable-trace;
inherit (verilator-emu-rtl-verilated) enable-trace;

# enable debug info for difftest itself and libspike
withDebug = self.overrideAttrs (old: {
Expand Down
55 changes: 27 additions & 28 deletions nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ lib.makeScope newScope
elaborateConfigJson = configPath;
elaborateConfig = builtins.fromJSON (lib.readFile configPath);

ip = rec {
ip = lib.makeScope innerSelf.newScope (ipSelf: {
recurseForDerivations = true;

# T1 RTL.
elaborate = innerSelf.callPackage ./elaborate.nix { target = "ip"; };
mlirbc = innerSelf.callPackage ./mlirbc.nix { inherit elaborate; };
rtl = innerSelf.callPackage ./rtl.nix {
inherit mlirbc;
elaborate = ipSelf.callPackage ./elaborate.nix { target = "ip"; };
mlirbc = ipSelf.callPackage ./mlirbc.nix { };
rtl = ipSelf.callPackage ./rtl.nix {
mfcArgs = lib.escapeShellArgs [
"-O=release"
"--disable-all-randomization"
Expand All @@ -76,29 +75,29 @@ lib.makeScope newScope
];
};

om = innerSelf.callPackage ./om.nix { inherit mlirbc; };
omreader = self.omreader-unwrapped.mkWrapper { inherit mlirbc; };
om = ipSelf.callPackage ./om.nix { };
omreader = self.omreader-unwrapped.mkWrapper { };

emu-om = innerSelf.callPackage ./om.nix { mlirbc = emu-mlirbc; };
emu-omreader = self.omreader-unwrapped.mkWrapper { mlirbc = emu-mlirbc; };
emu-om = ipSelf.callPackage ./om.nix { mlirbc = ipSelf.emu-mlirbc; };
emu-omreader = self.omreader-unwrapped.mkWrapper { mlirbc = ipSelf.emu-mlirbc; };
omGet = args: lib.fileContents (runCommand "get-${args}" { } ''
${emu-omreader}/bin/omreader ${args} > $out
${ipSelf.emu-omreader}/bin/omreader ${args} > $out
'');
rtlDesignMetadata = rec {
rtlDesignMetadata = with ipSelf; rec {
march = omGet "march";
extensions = builtins.fromJSON (omGet "extensionsJson");
vlen = omGet "vlen";
dlen = omGet "dlen";
xlen = if (lib.hasPrefix "rv32" march) then 32 else 64;
};

emu-elaborate = innerSelf.callPackage ./elaborate.nix { target = "ipemu"; };
emu-mlirbc = innerSelf.callPackage ./mlirbc.nix { elaborate = emu-elaborate; };
emu-elaborate = ipSelf.callPackage ./elaborate.nix { target = "ipemu"; };
emu-mlirbc = ipSelf.callPackage ./mlirbc.nix { elaborate = ipSelf.emu-elaborate; };

# T1 Verilator Emulator
verilator-emu-omreader = self.omreader-unwrapped.mkWrapper { mlirbc = emu-mlirbc; };
verilator-emu-rtl = innerSelf.callPackage ./rtl.nix {
mlirbc = emu-mlirbc;
verilator-emu-omreader = self.omreader-unwrapped.mkWrapper { mlirbc = ipSelf.emu-mlirbc; };
verilator-emu-rtl = ipSelf.callPackage ./rtl.nix {
mlirbc = ipSelf.emu-mlirbc;
mfcArgs = lib.escapeShellArgs [
"-O=release"
"--split-verilog"
Expand All @@ -108,16 +107,16 @@ lib.makeScope newScope
"--strip-debug-info"
];
};
verilator-emu-rtl-verilated = innerSelf.callPackage ./verilated.nix { rtl = verilator-emu-rtl; stdenv = moldStdenv; };
verilator-emu-rtl-verilated-trace = innerSelf.callPackage ./verilated.nix { rtl = verilator-emu-rtl; stdenv = moldStdenv; enable-trace = true; };
verilator-emu-rtl-verilated = ipSelf.callPackage ./verilated.nix { stdenv = moldStdenv; };
verilator-emu-rtl-verilated-trace = ipSelf.callPackage ./verilated.nix { stdenv = moldStdenv; enable-trace = true; };

verilator-emu = innerSelf.callPackage ../../difftest/verilator.nix { inherit rtlDesignMetadata; verilated = verilator-emu-rtl-verilated; };
verilator-emu-trace = innerSelf.callPackage ../../difftest/verilator.nix { inherit rtlDesignMetadata; verilated = verilator-emu-rtl-verilated-trace; };
verilator-emu = ipSelf.callPackage ../../difftest/verilator.nix { };
verilator-emu-trace = ipSelf.callPackage ../../difftest/verilator.nix { verilator-emu-rtl-verilated = ipSelf.verilator-emu-rtl-verilated-trace; };

# T1 VCS Emulator
vcs-emu-omreader = self.omreader-unwrapped.mkWrapper { mlirbc = emu-mlirbc; };
vcs-emu-rtl = innerSelf.callPackage ./rtl.nix {
mlirbc = emu-mlirbc;
vcs-emu-omreader = self.omreader-unwrapped.mkWrapper { mlirbc = ipSelf.emu-mlirbc; };
vcs-emu-rtl = ipSelf.callPackage ./rtl.nix {
mlirbc = ipSelf.emu-mlirbc;
mfcArgs = lib.escapeShellArgs [
"-O=release"
"--split-verilog"
Expand All @@ -127,12 +126,12 @@ lib.makeScope newScope
"--strip-debug-info"
];
};
vcs-dpi-lib = innerSelf.callPackage ../../difftest/online_vcs { };
vcs-dpi-lib-trace = vcs-dpi-lib.override { enable-trace = true; };
vcs-dpi-lib = ipSelf.callPackage ../../difftest/online_vcs { };
vcs-dpi-lib-trace = ipSelf.vcs-dpi-lib.override { enable-trace = true; };
# FIXME: vcs-emu should have offline check instead of using verilator one
vcs-emu = innerSelf.callPackage ./vcs.nix { inherit vcs-dpi-lib verilator-emu rtlDesignMetadata; rtl = vcs-emu-rtl; };
vcs-emu-trace = innerSelf.callPackage ./vcs.nix { inherit verilator-emu rtlDesignMetadata; vcs-dpi-lib = vcs-dpi-lib-trace; rtl = vcs-emu-rtl; };
};
vcs-emu = ipSelf.callPackage ./vcs.nix { };
vcs-emu-trace = ipSelf.callPackage ./vcs.nix { vcs-dpi-lib = ipSelf.vcs-dpi-lib-trace; };
});

subsystem = rec {
recurseForDerivations = true;
Expand Down
4 changes: 2 additions & 2 deletions nix/t1/vcs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
, bash
, stdenv
, configName
, rtl
, vcs-emu-rtl
, vcs-dpi-lib
, vcs-fhs-env
, rtlDesignMetadata
Expand All @@ -17,7 +17,7 @@ let
__noChroot = true;
dontPatchELF = true;

src = rtl;
src = vcs-emu-rtl;

buildPhase = ''
runHook preBuild
Expand Down
4 changes: 2 additions & 2 deletions nix/t1/verilated.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{ lib
, stdenv
, configName
, rtl
, verilator-emu-rtl
, verilator
, enable-trace ? false
, zlib
}:
stdenv.mkDerivation {
name = "${configName}-verilated";

src = rtl;
src = verilator-emu-rtl;

nativeBuildInputs = [ verilator ];

Expand Down

0 comments on commit a800c2c

Please sign in to comment.