Revision d634b4e0
b/lib/opcodes.py | ||
---|---|---|
245 | 245 |
COMMENT_ATTR = "comment" |
246 | 246 |
|
247 | 247 |
|
248 |
def _NameToId(name):
|
|
249 |
"""Convert an opcode class name to an OP_ID.
|
|
248 |
def _NameComponents(name):
|
|
249 |
"""Split an opcode class name into its components
|
|
250 | 250 |
|
251 | 251 |
@type name: string |
252 | 252 |
@param name: the class name, as OpXxxYyy |
253 |
@rtype: string
|
|
254 |
@return: the name in the OP_XXXX_YYYY format
|
|
253 |
@rtype: array of strings
|
|
254 |
@return: the components of the name
|
|
255 | 255 |
|
256 | 256 |
""" |
257 |
if not name.startswith("Op"): |
|
258 |
return None |
|
257 |
assert name.startswith("Op") |
|
259 | 258 |
# Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't |
260 | 259 |
# consume any input, and hence we would just have all the elements |
261 | 260 |
# in the list, one by one; but it seems that split doesn't work on |
... | ... | |
263 | 262 |
# bit |
264 | 263 |
name = _OPID_RE.sub(r"\1,\2", name) |
265 | 264 |
elems = name.split(",") |
266 |
return "_".join(n.upper() for n in elems) |
|
265 |
return elems |
|
266 |
|
|
267 |
|
|
268 |
def _NameToId(name): |
|
269 |
"""Convert an opcode class name to an OP_ID. |
|
270 |
|
|
271 |
@type name: string |
|
272 |
@param name: the class name, as OpXxxYyy |
|
273 |
@rtype: string |
|
274 |
@return: the name in the OP_XXXX_YYYY format |
|
275 |
|
|
276 |
""" |
|
277 |
if not name.startswith("Op"): |
|
278 |
return None |
|
279 |
return "_".join(n.upper() for n in _NameComponents(name)) |
|
280 |
|
|
281 |
|
|
282 |
def NameToReasonSrc(name): |
|
283 |
"""Convert an opcode class name to a source string for the reason trail |
|
284 |
|
|
285 |
@type name: string |
|
286 |
@param name: the class name, as OpXxxYyy |
|
287 |
@rtype: string |
|
288 |
@return: the name in the OP_XXXX_YYYY format |
|
289 |
|
|
290 |
""" |
|
291 |
if not name.startswith("Op"): |
|
292 |
return None |
|
293 |
return "%s:%s" % (constants.OPCODE_REASON_SRC_OPCODE, |
|
294 |
"_".join(n.lower() for n in _NameComponents(name))) |
|
267 | 295 |
|
268 | 296 |
|
269 | 297 |
def _GenerateObjectTypeCheck(obj, fields_types): |
Also available in: Unified diff