diff --git a/lib/opcodes.py b/lib/opcodes.py index 8bf6c778e5d3bc6d671ff742a445bab855178157..74ebe9c5f0720a5a55e33c0d68385550bbec3d99 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -245,17 +245,16 @@ DEPEND_ATTR = "depends" COMMENT_ATTR = "comment" -def _NameToId(name): - """Convert an opcode class name to an OP_ID. +def _NameComponents(name): + """Split an opcode class name into its components @type name: string @param name: the class name, as OpXxxYyy - @rtype: string - @return: the name in the OP_XXXX_YYYY format + @rtype: array of strings + @return: the components of the name """ - if not name.startswith("Op"): - return None + assert name.startswith("Op") # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't # consume any input, and hence we would just have all the elements # in the list, one by one; but it seems that split doesn't work on @@ -263,7 +262,36 @@ def _NameToId(name): # bit name = _OPID_RE.sub(r"\1,\2", name) elems = name.split(",") - return "_".join(n.upper() for n in elems) + return elems + + +def _NameToId(name): + """Convert an opcode class name to an OP_ID. + + @type name: string + @param name: the class name, as OpXxxYyy + @rtype: string + @return: the name in the OP_XXXX_YYYY format + + """ + if not name.startswith("Op"): + return None + return "_".join(n.upper() for n in _NameComponents(name)) + + +def NameToReasonSrc(name): + """Convert an opcode class name to a source string for the reason trail + + @type name: string + @param name: the class name, as OpXxxYyy + @rtype: string + @return: the name in the OP_XXXX_YYYY format + + """ + if not name.startswith("Op"): + return None + return "%s:%s" % (constants.OPCODE_REASON_SRC_OPCODE, + "_".join(n.lower() for n in _NameComponents(name))) def _GenerateObjectTypeCheck(obj, fields_types):