diff options
| author | Henry Gressmann <mail@henrygressmann.de> | 2024-02-27 17:04:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-27 17:04:23 +0100 |
| commit | ab2ae9b445268d503bde3dbb7a91886c55c19144 (patch) | |
| tree | b2644fc05d37b320035a2997867de61f804f5b6c /examples | |
| parent | 43e6d23ae8806c813dd5fa0663c17c1772ebf5a8 (diff) | |
| parent | 417bb70c0f8c8f8781f675481e5336affd209183 (diff) | |
feat: rework instructions (#4)
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/rust/analyze.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/rust/analyze.py b/examples/rust/analyze.py new file mode 100644 index 0000000..a450a1a --- /dev/null +++ b/examples/rust/analyze.py @@ -0,0 +1,36 @@ +import re +import sys +from collections import Counter + +seq_len = 5 + +# Check if a file path was provided +if len(sys.argv) < 2: + print("Usage: python script.py path/to/yourfile.wat") + sys.exit(1) + +# The first command line argument is the file path +file_path = sys.argv[1] + +# Regex to match WASM operators, adjust as necessary +operator_pattern = re.compile(r'\b[a-z0-9_]+\.[a-z0-9_]+\b') + +# Read the file +with open(file_path, 'r') as file: + content = file.read() + +# Find all operators +operators = operator_pattern.findall(content) + +# Generate sequences of three consecutive operators +sequences = [' '.join(operators[i:i+seq_len]) for i in range(len(operators) - 2)] + +# Count occurrences of each sequence +sequence_counts = Counter(sequences) + +# Sort sequences by their count, this time in ascending order for reverse display +sorted_sequences = sorted(sequence_counts.items(), key=lambda x: x[1]) + +# Print the sequences, now from least common to most common +for sequence, count in sorted_sequences: + print(f"{sequence}: {count}") |
