Skip to content

Commit e6f4a36

Browse files
committed
Prevent offsets from overlapping at the edges.
bytefield really handles this very poorly, so this is a hack by moving long offsets in a bit. Now some look a little odd with not much space between upper and lower offset, but at least there's no actual overlapping text anymore.
1 parent 7cbd0f9 commit e6f4a36

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

registers.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def symbols( self ):
213213

214214
def columnWidth( self ):
215215
"""Return the width of the column in boxes."""
216-
offsetCharWidth = .18
216+
offsetCharWidth = .26
217217
nameCharWidth = .33
218218
xlen_symbol = sympy.symbols('XLEN')
219219
lengthCharWidth = .22
@@ -226,7 +226,9 @@ def columnWidth( self ):
226226
if self.length() == 1:
227227
bitText = f"{self.lowBit}"
228228
else:
229-
bitText = f"{self.highBit} {self.lowBit}"
229+
# There is no dash in what we're displaying, but we want some space
230+
# for separation between the two values.
231+
bitText = f"{self.highBit} - {self.lowBit}"
230232
width = math.ceil(max(
231233
# Minimum length
232234
1,
@@ -891,10 +893,22 @@ def write_bytefield_row( fd, fields ):
891893
else:
892894
headers.append(f.lowBit)
893895
else:
894-
assert columnWidth >= 2
895-
headers.append(f.lowBit)
896-
headers += [""] * (columnWidth - 2)
897-
headers.append(f.highBit)
896+
# If low/high bit need more than 2 characters, place them one in
897+
# from the end so they don't overflow into the neighboring field.
898+
# Really this should be done with right/left alignment, but
899+
# bytefield doesn't seem to support that.
900+
if len(f.lowBit) > 2:
901+
start = ["", f.lowBit]
902+
else:
903+
start = [f.lowBit]
904+
if len(f.highBit) > 2:
905+
end = [f.highBit, ""]
906+
else:
907+
end = [f.highBit]
908+
assert columnWidth >= len(start) + len(end)
909+
headers += start
910+
headers += [""] * (columnWidth - len(start) - len(end))
911+
headers += end
898912
columnOffset += columnWidth
899913
# remove whitespace to save space
900914
headers = [h.replace(" ", "") for h in headers]

0 commit comments

Comments
 (0)