support easy testing of corpus

This commit is contained in:
Yehowshua Immanuel 2024-12-11 13:00:39 -05:00
parent d096c93434
commit 73deb95e04
5 changed files with 32 additions and 0 deletions

2
.gitignore vendored
View file

@ -1,6 +1,8 @@
# Created by https://www.toptal.com/developers/gitignore/api/haskell
# Edit at https://www.toptal.com/developers/gitignore?templates=haskell
parsed_rtlil/
### Haskell ###
dist
dist-*

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "rtlil-corpus"]
path = rtlil-corpus
url = git@github.com:JoyOfHardware/rtlil-corpus.git

View file

@ -45,6 +45,7 @@ The following will allow you to see a pretty printed
AST for the given input `il` file.
```bash
git clone --recursive git@github.com:JoyOfHardware/Haskellator.git
$ nix-shell
$ rtlil-parse
```

1
rtlil-corpus Submodule

@ -0,0 +1 @@
Subproject commit d60615be78cd1fc7173bff956d2b1a53f8235bb0

25
test.py Normal file
View file

@ -0,0 +1,25 @@
import os
import subprocess
# Define the directories
corpus_dir = './rtlil-corpus/corpus/'
parsed_dir = './parsed_rtlil'
# Create the parsed_rtlil directory if it doesn't exist
os.makedirs(parsed_dir, exist_ok=True)
# Iterate over all .rtlil files in the corpus directory
for file_name in os.listdir(corpus_dir):
if file_name.endswith('.il'):
input_path = os.path.join(corpus_dir, file_name)
output_file = os.path.splitext(file_name)[0] + '.hs'
output_path = os.path.join(parsed_dir, output_file)
# Construct and run the command
command = f"cabal run rtlil-parse -- {input_path} {output_path}"
try:
subprocess.run(command, shell=True, check=True)
print(f"Processed: {input_path} -> {output_path}")
except subprocess.CalledProcessError as e:
print(f"Error processing {input_path}: {e}")
break