From a800c2c4f5cc7380f2fc54d8c607e34366179394 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Tue, 13 Aug 2024 16:57:46 +0800 Subject: [PATCH] [nix] refactor whole test attribute under emulator Signed-off-by: Avimitin --- difftest/verilator.nix | 14 +++++------ nix/t1/default.nix | 55 +++++++++++++++++++++--------------------- nix/t1/vcs.nix | 4 +-- nix/t1/verilated.nix | 4 +-- 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/difftest/verilator.nix b/difftest/verilator.nix index ddf0263bf..febdaf102 100644 --- a/difftest/verilator.nix +++ b/difftest/verilator.nix @@ -11,7 +11,7 @@ , rust-bindgen , verilator -, verilated +, verilator-emu-rtl-verilated , cmake , clang-tools @@ -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 = ./.; @@ -38,7 +38,7 @@ let buildInputs = [ libspike_interfaces - verilated + verilator-emu-rtl-verilated ]; nativeBuildInputs = [ @@ -46,11 +46,11 @@ let 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 = @@ -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: { diff --git a/nix/t1/default.nix b/nix/t1/default.nix index 28d0378e8..b6bdead5c 100644 --- a/nix/t1/default.nix +++ b/nix/t1/default.nix @@ -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" @@ -76,15 +75,15 @@ 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"; @@ -92,13 +91,13 @@ lib.makeScope newScope 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" @@ -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" @@ -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; diff --git a/nix/t1/vcs.nix b/nix/t1/vcs.nix index a3b5a3131..11c18f29d 100644 --- a/nix/t1/vcs.nix +++ b/nix/t1/vcs.nix @@ -3,7 +3,7 @@ , bash , stdenv , configName -, rtl +, vcs-emu-rtl , vcs-dpi-lib , vcs-fhs-env , rtlDesignMetadata @@ -17,7 +17,7 @@ let __noChroot = true; dontPatchELF = true; - src = rtl; + src = vcs-emu-rtl; buildPhase = '' runHook preBuild diff --git a/nix/t1/verilated.nix b/nix/t1/verilated.nix index 498c2ea9b..45a285352 100644 --- a/nix/t1/verilated.nix +++ b/nix/t1/verilated.nix @@ -1,7 +1,7 @@ { lib , stdenv , configName -, rtl +, verilator-emu-rtl , verilator , enable-trace ? false , zlib @@ -9,7 +9,7 @@ stdenv.mkDerivation { name = "${configName}-verilated"; - src = rtl; + src = verilator-emu-rtl; nativeBuildInputs = [ verilator ];