Skip to content

Commit 66ef487

Browse files
committed
Use AsmString instead of name
Signed-off-by: Afonso Oliveira <[email protected]>
1 parent a4b5c39 commit 66ef487

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed
221 Bytes
Binary file not shown.

ext/auto-inst/parsing.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -244,23 +244,37 @@ def get_repo_instructions(repo_directory):
244244

245245
def find_json_key(instr_name, json_data):
246246
"""
247-
Attempt to find a matching key in json_data for instr_name, considering different
248-
naming conventions: replacing '.' with '_', and trying various case transformations.
247+
Find a matching instruction in json_data by comparing against AsmString values.
248+
Returns the matching key if found, None otherwise.
249+
250+
Args:
251+
instr_name (str): The instruction name from YAML
252+
json_data (dict): The JSON data containing instruction information
253+
254+
Returns:
255+
str or None: The matching key from json_data if found, None otherwise
249256
"""
250-
lower_name = instr_name.lower()
251-
lower_name_underscore = lower_name.replace('.', '_')
252-
variants = {
253-
lower_name,
254-
lower_name_underscore,
255-
instr_name.upper(),
256-
instr_name.replace('.', '_').upper(),
257-
instr_name.capitalize(),
258-
instr_name.replace('.', '_').capitalize()
259-
}
260-
261-
for v in variants:
262-
if v in json_data:
263-
return v
257+
# First, normalize the instruction name for comparison
258+
instr_name = instr_name.lower().strip()
259+
260+
# Search through all entries in json_data
261+
for key, value in json_data.items():
262+
if not isinstance(value, dict):
263+
continue
264+
265+
# Get the AsmString value and normalize it
266+
asm_string = safe_get(value, 'AsmString', '').lower().strip()
267+
if not asm_string:
268+
continue
269+
270+
# Extract the base instruction name from AsmString
271+
# AsmString might be in format like "add $rd, $rs1, $rs2"
272+
# We want just "add"
273+
base_asm_name = asm_string.split()[0]
274+
275+
if base_asm_name == instr_name:
276+
return key
277+
264278
return None
265279

266280
def run_parser(json_file, repo_directory, output_file="output.txt"):

0 commit comments

Comments
 (0)