Use corpus package
Allow using the existing `rtlil-parse` from the nix-shell instead of using cabal
This commit is contained in:
parent
5b84cc7a47
commit
6f8b8999b3
15
shell.nix
15
shell.nix
|
@ -6,10 +6,15 @@
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
haskellator = pkgs.callPackage ./default.nix {};
|
haskellator = pkgs.callPackage ./default.nix { };
|
||||||
|
corpus = pkgs.callPackage ./rtlil-corpus/default.nix { };
|
||||||
in
|
in
|
||||||
pkgs.mkShell {
|
pkgs.callPackage (
|
||||||
buildInputs = [
|
{ mkShell }:
|
||||||
haskellator
|
mkShell {
|
||||||
|
CORPUS = corpus;
|
||||||
|
nativeBuildInputs = [
|
||||||
|
haskellator
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
) { }
|
||||||
|
|
21
test.py
21
test.py
|
@ -1,13 +1,30 @@
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import argparse
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="Test rtlil-parse")
|
||||||
|
parser.add_argument("--corpus", default=os.environ.get('CORPUS'), required=False, help="Path to corpus dir.")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Define the directories
|
# Define the directories
|
||||||
corpus_dir = './rtlil-corpus/corpus/'
|
if args.corpus:
|
||||||
|
corpus_dir = args.corpus
|
||||||
|
else:
|
||||||
|
corpus_dir = './rtlil-corpus/corpus/'
|
||||||
|
|
||||||
parsed_dir = './parsed_rtlil'
|
parsed_dir = './parsed_rtlil'
|
||||||
|
|
||||||
# Create the parsed_rtlil directory if it doesn't exist
|
# Create the parsed_rtlil directory if it doesn't exist
|
||||||
os.makedirs(parsed_dir, exist_ok=True)
|
os.makedirs(parsed_dir, exist_ok=True)
|
||||||
|
|
||||||
|
# Use rtlil-parse from PATH if available.
|
||||||
|
rtil_parse_binary = shutil.which("rtlil-parse")
|
||||||
|
if rtil_parse_binary is None:
|
||||||
|
program = "cabal run rtlil-parse --"
|
||||||
|
else:
|
||||||
|
program = rtil_parse_binary
|
||||||
|
|
||||||
# Iterate over all .rtlil files in the corpus directory
|
# Iterate over all .rtlil files in the corpus directory
|
||||||
for file_name in os.listdir(corpus_dir):
|
for file_name in os.listdir(corpus_dir):
|
||||||
if file_name.endswith('.il'):
|
if file_name.endswith('.il'):
|
||||||
|
@ -16,7 +33,7 @@ for file_name in os.listdir(corpus_dir):
|
||||||
output_path = os.path.join(parsed_dir, output_file)
|
output_path = os.path.join(parsed_dir, output_file)
|
||||||
|
|
||||||
# Construct and run the command
|
# Construct and run the command
|
||||||
command = f"cabal run rtlil-parse -- {input_path} {output_path}"
|
command = f"{program} {input_path} {output_path}"
|
||||||
try:
|
try:
|
||||||
subprocess.run(command, shell=True, check=True)
|
subprocess.run(command, shell=True, check=True)
|
||||||
print(f"Processed: {input_path} -> {output_path}")
|
print(f"Processed: {input_path} -> {output_path}")
|
||||||
|
|
Loading…
Reference in a new issue