summaryrefslogtreecommitdiff
path: root/bindings/python/llvm/core.py
diff options
context:
space:
mode:
Diffstat (limited to 'bindings/python/llvm/core.py')
-rw-r--r--bindings/python/llvm/core.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/bindings/python/llvm/core.py b/bindings/python/llvm/core.py
index e0f35203ba..6756637425 100644
--- a/bindings/python/llvm/core.py
+++ b/bindings/python/llvm/core.py
@@ -11,6 +11,8 @@ from .common import LLVMObject
from .common import c_object_p
from .common import get_library
+from . import enumerations
+
from ctypes import POINTER
from ctypes import byref
from ctypes import c_char_p
@@ -22,6 +24,42 @@ __all__ = [
lib = get_library()
+class OpCode(object):
+ """Represents an individual OpCode enumeration."""
+
+ _value_map = {}
+
+ def __init__(self, name, value):
+ self.name = name
+ self.value = value
+
+ def __repr__(self):
+ return 'OpCode.%s' % self.name
+
+ @staticmethod
+ def from_value(value):
+ """Obtain an OpCode instance from a numeric value."""
+ result = OpCode._value_map.get(value, None)
+
+ if result is None:
+ raise ValueError('Unknown OpCode: %d' % value)
+
+ return result
+
+ @staticmethod
+ def register(name, value):
+ """Registers a new OpCode enumeration.
+
+ This is called by this module for each enumeration defined in
+ enumerations. You should not need to call this outside this module.
+ """
+ if value in OpCode._value_map:
+ raise ValueError('OpCode value already registered: %d' % value)
+
+ opcode = OpCode(name, value)
+ OpCode._value_map[value] = opcode
+ setattr(OpCode, name, opcode)
+
class MemoryBuffer(LLVMObject):
"""Represents an opaque memory buffer."""
@@ -52,4 +90,9 @@ def register_library(library):
library.LLVMDisposeMemoryBuffer.argtypes = [MemoryBuffer]
+def register_enumerations():
+ for name, value in enumerations.OpCodes:
+ OpCode.register(name, value)
+
register_library(lib)
+register_enumerations()