arch: Use finditer in the (Sub)OperandList classes.
This method returns an iterator which goes through all the
non-overlapping matches for the given RE, without having to hand code
that same behavior with the more basic "search" method.
Change-Id: I4c4d95cfc8f72125566222aebb56604c3e9e2b03
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/35817
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/src/arch/isa_parser/operand_list.py b/src/arch/isa_parser/operand_list.py
index 076b77e..86de5a5 100755
--- a/src/arch/isa_parser/operand_list.py
+++ b/src/arch/isa_parser/operand_list.py
@@ -49,13 +49,9 @@
# delete strings and comments so we don't match on operands inside
for regEx in (stringRE, commentRE):
code = regEx.sub('', code)
+
# search for operands
- next_pos = 0
- while 1:
- match = parser.operandsRE().search(code, next_pos)
- if not match:
- # no more matches: we're done
- break
+ for match in parser.operandsRE().finditer(code):
op = match.groups()
# regexp groups are operand full name, base, and extension
(op_full, op_base, op_ext) = op
@@ -103,8 +99,7 @@
op_desc.elemExt = elem_op[1]
op_desc.active_elems = [elem_op]
self.append(op_desc)
- # start next search after end of current match
- next_pos = match.end()
+
self.sort()
# enumerate source & dest register operands... used in building
# constructor later
@@ -219,13 +214,9 @@
# delete strings and comments so we don't match on operands inside
for regEx in (stringRE, commentRE):
code = regEx.sub('', code)
+
# search for operands
- next_pos = 0
- while 1:
- match = parser.operandsRE().search(code, next_pos)
- if not match:
- # no more matches: we're done
- break
+ for match in parser.operandsRE().finditer(code):
op = match.groups()
# regexp groups are operand full name, base, and extension
(op_full, op_base, op_ext) = op
@@ -246,8 +237,6 @@
# if not, add a reference to it to this sub list
self.append(requestor_list.bases[op_base])
- # start next search after end of current match
- next_pos = match.end()
self.sort()
self.memOperand = None
# Whether the whole PC needs to be read so parts of it can be accessed