arch: Add some format strings to the parser for reg indexes.
authorGabe Black <gabe.black@gmail.com>
Sun, 1 Nov 2020 11:47:14 +0000 (03:47 -0800)
committerGabe Black <gabe.black@gmail.com>
Thu, 19 Nov 2020 02:52:05 +0000 (02:52 +0000)
There are two new strings, reg_idx_arr_decl which declares the source
and dest register index arrays, and set_reg_idx_arr which installs them
in the base class.

The set_reg_idx_arr code needs to implicitly figure out what type to use
based on the type of the "this" pointer. The name of the containing
class is not *necessarily* the same as class_name, since the generated
code can use that name, something based on that name, or whatever else
it wants. No other format string (other than class_name itself) uses the
class name internally, so we can't count on that working in existing ISA
definitions.

Change-Id: Id995a46896e71a2fcf3103c34a1e1e67e24f88f4
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/36878
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Maintainer: Giacomo Travaglini <giacomo.travaglini@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/arch/isa_parser/isa_parser.py

index 999d92f40b9ad98b58aa62dad9984e4e538bb6cd..ff54889fe74b8070dad6b78f824b94bdd8465acc 100755 (executable)
@@ -105,6 +105,21 @@ class Template(object):
 
             operands = SubOperandList(self.parser, compositeCode, d.operands)
 
+            myDict['reg_idx_arr_decl'] = \
+                'RegId srcRegIdxArr[%d]; RegId destRegIdxArr[%d]' % \
+                (d.operands.numSrcRegs, d.operands.numDestRegs)
+
+            # The reinterpret casts are largely because an array with a known
+            # size cannot be passed as an argument which is an array with an
+            # unknown size in C++.
+            myDict['set_reg_idx_arr'] = '''
+    setRegIdxArrays(
+        reinterpret_cast<RegIdArrayPtr>(
+            &std::remove_pointer_t<decltype(this)>::srcRegIdxArr),
+        reinterpret_cast<RegIdArrayPtr>(
+            &std::remove_pointer_t<decltype(this)>::destRegIdxArr));
+            '''
+
             myDict['op_decl'] = operands.concatAttrStrings('op_decl')
             if operands.readPC or operands.setPC:
                 myDict['op_decl'] += 'TheISA::PCState __parserAutoPCState;\n'