22import re
33import yaml
44from pathlib import Path
5-
5+ import pytest
66yaml_instructions = {}
77REPO_DIRECTORY = None
88
@@ -16,38 +16,39 @@ def safe_get(data, key, default=""):
1616 return default
1717
1818def get_json_path ():
19- """Get the path to the JSON file relative to the test file."""
20- current_dir = Path (__file__ ).parent
21- return str (current_dir / "/home/afonsoo/llvm-project/llvm-build/pretty.json" )
19+ env_path = os .environ .get ('LLVM_JSON' )
20+ if not env_path :
21+ print ("\n No LLVM path found in environment." )
22+ print ("Tests will be skipped.\n " )
23+ pytest .skip ("LLVM path not configured" )
24+ return env_path
2225
2326def get_yaml_directory ():
24- """Get the path to the YAML directory relative to the test file."""
25- current_dir = Path (__file__ ).parent
26- return str (current_dir / "../../arch/inst/" )
27+ return "arch/inst/"
2728
2829def load_inherited_variable (var_path , repo_dir ):
2930 """Load variable definition from an inherited YAML file."""
3031 try :
3132 path , anchor = var_path .split ('#' )
3233 if anchor .startswith ('/' ):
3334 anchor = anchor [1 :]
34-
35+
3536 full_path = os .path .join (repo_dir , path )
36-
37+
3738 if not os .path .exists (full_path ):
3839 print (f"Warning: Inherited file not found: { full_path } " )
3940 return None
40-
41+
4142 with open (full_path , 'r' ) as f :
4243 data = yaml .safe_load (f )
43-
44+
4445 for key in anchor .split ('/' ):
4546 if key in data :
4647 data = data [key ]
4748 else :
4849 print (f"Warning: Anchor path { anchor } not found in { path } " )
4950 return None
50-
51+
5152 return data
5253 except Exception as e :
5354 print (f"Error loading inherited variable { var_path } : { str (e )} " )
@@ -65,10 +66,10 @@ def parse_location(loc_str):
6566 """Parse location string that may contain multiple ranges."""
6667 if not loc_str :
6768 return []
68-
69+
6970 loc_str = str (loc_str ).strip ()
7071 ranges = []
71-
72+
7273 for range_str in loc_str .split ('|' ):
7374 range_str = range_str .strip ()
7475 if '-' in range_str :
@@ -81,7 +82,7 @@ def parse_location(loc_str):
8182 except ValueError :
8283 print (f"Warning: Invalid location format: { range_str } " )
8384 continue
84-
85+
8586 return ranges
8687
8788def load_yaml_encoding (instr_name ):
@@ -132,7 +133,7 @@ def compare_yaml_json_encoding(instr_name, yaml_match, yaml_vars, json_encoding_
132133 if not resolved_var or 'location' not in resolved_var :
133134 print (f"Warning: Could not resolve variable definition for { var .get ('name' , 'unknown' )} " )
134135 continue
135-
136+
136137 ranges = parse_location (resolved_var ['location' ])
137138 if ranges :
138139 yaml_var_positions [var ['name' ]] = ranges
@@ -217,4 +218,4 @@ def get_yaml_instructions(repo_directory):
217218 "yaml_vars" : yaml_vars
218219 }
219220
220- return instructions_with_encodings
221+ return instructions_with_encodings
0 commit comments