[otbn] Fix disassembly for glued operands
This broke when I added padding to mnemonics back in August. Oops!
Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
diff --git a/hw/ip/otbn/util/shared/insn_yaml.py b/hw/ip/otbn/util/shared/insn_yaml.py
index d9ebaee..f3fe784 100644
--- a/hw/ip/otbn/util/shared/insn_yaml.py
+++ b/hw/ip/otbn/util/shared/insn_yaml.py
@@ -193,13 +193,22 @@
(not encoded values). mnem_width is the width to pad the mnemonic to.
'''
- padded_mnem = self.mnemonic
- if len(padded_mnem) < mnem_width:
- padded_mnem += ' ' * (mnem_width - len(padded_mnem))
+ hunks = self.syntax.render(cur_pc, op_vals, self.name_to_operand)
+ mnem = self.mnemonic
+ if hunks and self.glued_ops:
+ mnem += hunks[0] + ' '
+ hunks = hunks[1:]
+ else:
+ mnem += ' '
- return (padded_mnem +
- ('' if self.glued_ops else ' ') +
- self.syntax.render(cur_pc, op_vals, self.name_to_operand))
+ if len(mnem) < mnem_width:
+ mnem += ' ' * (mnem_width - len(mnem))
+
+ # The lstrip here deals with a tricky corner case for instructions like
+ # bn.mulqacc if the .z option isn't supplied. In that case, the syntax
+ # for the operands starts with a space (following the optional .z that
+ # isn't there) and would mess up our alignment.
+ return mnem + ''.join(hunks).lstrip()
def find_ambiguous_encodings(insns: List[Insn]) -> List[Tuple[str, str, int]]:
diff --git a/hw/ip/otbn/util/shared/syntax.py b/hw/ip/otbn/util/shared/syntax.py
index eaf6e90..acbe5db 100644
--- a/hw/ip/otbn/util/shared/syntax.py
+++ b/hw/ip/otbn/util/shared/syntax.py
@@ -361,9 +361,11 @@
def render(self,
cur_pc: int,
op_vals: Dict[str, int],
- operands: Dict[str, Operand]) -> str:
- '''Return an assembly listing for the given operand fields'''
- parts = []
- for hunk in self.hunks:
- parts.append(hunk.render(cur_pc, op_vals, operands))
- return ''.join(parts)
+ operands: Dict[str, Operand]) -> List[str]:
+ '''Return an assembly listing for the given operand fields
+
+ The listings for hunks are returned separately (to allow an instruction
+ to support glued_ops). To generate the final listing, concatenate them.
+
+ '''
+ return [hunk.render(cur_pc, op_vals, operands) for hunk in self.hunks]