From: Gabe Black Date: Wed, 30 Sep 2020 04:11:19 +0000 (-0700) Subject: arch: Use finditer in the (Sub)OperandList classes. X-Git-Tag: develop-gem5-snapshot~637 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=14bdba8c66cd1252e5837e5a4ab77426b9541469;p=gem5.git 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 Maintainer: Jason Lowe-Power Tested-by: kokoro --- diff --git a/src/arch/isa_parser/operand_list.py b/src/arch/isa_parser/operand_list.py index 076b77e5a..86de5a51f 100755 --- a/src/arch/isa_parser/operand_list.py +++ b/src/arch/isa_parser/operand_list.py @@ -49,13 +49,9 @@ class OperandList(object): # 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 @@ class OperandList(object): 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 @@ class SubOperandList(OperandList): # 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 @@ class SubOperandList(OperandList): # 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