@@ -83,16 +83,11 @@ def canonical_immediate_names(
8383 field names from fieldo.
8484
8585 Supports several formats:
86-
87- 1. For branch instructions (name starts with 'b') and a 4-part compound format,
88- e.g. "31|7|30-25|11-8", it extracts the two parts using 'bimm' as the prefix.
89-
90- 2. For jump instructions (name starts with 'j') with a 4-part compound format,
91- e.g. "31|19-12|20|30-21", it extracts the overall high (from part 0) and low (from part 1)
92- and uses the 'jimm' prefix.
93-
94- 3. For a standard composite format "X-Y|Z-W", it compares the two ranges.
95- 4. For non-composite formats "X-Y", it does a simple lookup.
86+ 1. For branch instructions (name starts with 'b') with a 4‑part compound format.
87+ 2. For jump instructions (name starts with 'j') with a 4‑part compound format.
88+ 3. For composite immediates in the form "X-Y|Z-W".
89+ 4. For composite immediates in the form "X|Z-W" where the high part is a single number.
90+ 5. For non‐composite formats "X-Y".
9691 """
9792 parts = location .split ("|" )
9893 if len (parts ) == 4 and var_name == "imm" and instr_name .lower ().startswith ("b" ):
@@ -101,7 +96,6 @@ def canonical_immediate_names(
10196 high_msb = int (parts [0 ])
10297 high_lsb = int (parts [2 ].split ("-" )[- 1 ])
10398 low_msb = int (parts [3 ].split ("-" )[0 ])
104- # parts[1] should be a simple number when converting for branch immediates.
10599 low_lsb = int (parts [1 ])
106100 except Exception as e :
107101 print (
@@ -123,8 +117,6 @@ def canonical_immediate_names(
123117 elif len (parts ) == 4 and var_name == "imm" and instr_name .lower ().startswith ("j" ):
124118 # Jump compound format, e.g.: "31|19-12|20|30-21"
125119 try :
126- # For jump immediates, the canonical field typically covers the whole range.
127- # We extract the overall high (first part) and the lower end of the second part.
128120 high = int (parts [0 ])
129121 low = int (parts [1 ].split ("-" )[1 ])
130122 except Exception as e :
@@ -141,6 +133,58 @@ def canonical_immediate_names(
141133 )
142134 return []
143135 return [candidate ]
136+ elif "|" in location and len (parts ) == 2 :
137+ # New branch: composite immediate in the form "X|Z-W" (or "X|Z" if both parts are single numbers)
138+ # For a single number, treat it as "X-X".
139+ high_part = parts [0 ].strip ()
140+ low_part = parts [1 ].strip ()
141+ if "-" not in high_part :
142+ high_range = f"{ high_part } -{ high_part } "
143+ else :
144+ high_range = high_part
145+ if "-" not in low_part :
146+ low_range = f"{ low_part } -{ low_part } "
147+ else :
148+ low_range = low_part
149+ try :
150+ high_msb , high_lsb = map (int , high_range .split ("-" ))
151+ low_msb , low_lsb = map (int , low_range .split ("-" ))
152+ except Exception as e :
153+ print (
154+ f"Warning: invalid composite immediate format in location '{ location } ': { e } "
155+ )
156+ return []
157+ # Use "bimm" if the instruction starts with b, otherwise keep var_name (e.g. "imm")
158+ prefix = (
159+ "bimm"
160+ if var_name == "imm" and instr_name .lower ().startswith ("b" )
161+ else var_name
162+ )
163+ hi_candidate = lookup_immediate_by_range (
164+ prefix , high_msb , high_lsb , instr_name , left_shift = left_shift
165+ )
166+ lo_candidate = lookup_immediate_by_range (
167+ prefix , low_msb , low_lsb , instr_name , left_shift = left_shift
168+ )
169+ # NEW: if we found a hi candidate that ends with "hi", look for its complementary lo.
170+ if hi_candidate and hi_candidate .endswith ("hi" ):
171+ desired_lo = hi_candidate .replace ("hi" , "lo" )
172+ # Check if the desired lo exists in fieldo with the expected msb and lsb.
173+ try :
174+ if (
175+ desired_lo in fieldo
176+ and fieldo [desired_lo ].get ("msb" ) == low_msb
177+ and fieldo [desired_lo ].get ("lsb" ) == low_lsb
178+ ):
179+ lo_candidate = desired_lo
180+ except Exception :
181+ pass
182+ if hi_candidate is None or lo_candidate is None :
183+ print (
184+ f"Warning: composite immediate candidate not found in fieldo for { var_name } with location { location } "
185+ )
186+ return []
187+ return [hi_candidate , lo_candidate ]
144188 elif "|" in location :
145189 # Standard composite format, e.g.: "31-25|11-7"
146190 import re
0 commit comments