+#: OP_ID conversion regular expression
+_OPID_RE = re.compile("([a-z])([A-Z])")
+
+
+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
+ # 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
+ # non-consuming input, hence we have to process the input string a
+ # bit
+ name = _OPID_RE.sub(r"\1,\2", name)
+ elems = name.split(",")
+ return "_".join(n.upper() for n in elems)
+