summaryrefslogtreecommitdiff
path: root/bindings/python
diff options
context:
space:
mode:
authorMichael Gottesman <mgottesman@apple.com>2013-09-11 01:38:12 +0000
committerMichael Gottesman <mgottesman@apple.com>2013-09-11 01:38:12 +0000
commitabaa85d88d13f6efa99c61d206155678ccd5f118 (patch)
tree00619ac1bbdb1a2e7925264ac55688f7e8d8b5fe /bindings/python
parent73c382f7fdbe034383600c1ddd385aea0cd27221 (diff)
downloadllvm-abaa85d88d13f6efa99c61d206155678ccd5f118.tar.gz
llvm-abaa85d88d13f6efa99c61d206155678ccd5f118.tar.bz2
llvm-abaa85d88d13f6efa99c61d206155678ccd5f118.tar.xz
[python-bindings] Added support for getting/setting operands of values and getting the number of operands of a value.
Also in the process did some cleanups for BasicBlock. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190477 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python')
-rw-r--r--bindings/python/llvm/core.py36
-rw-r--r--bindings/python/llvm/tests/test_core.py6
2 files changed, 39 insertions, 3 deletions
diff --git a/bindings/python/llvm/core.py b/bindings/python/llvm/core.py
index 740ce47188..ebf57d4443 100644
--- a/bindings/python/llvm/core.py
+++ b/bindings/python/llvm/core.py
@@ -106,6 +106,15 @@ class Value(LLVMObject):
def dump(self):
lib.LLVMDumpValue(self)
+
+ def get_operand(self, i):
+ return Value(lib.LLVMGetOperand(self, i))
+
+ def set_operand(self, i, v):
+ return lib.LLVMSetOperand(self, i, v)
+
+ def __len__(self):
+ return lib.LLVMGetNumOperands(self)
class Module(LLVMObject):
"""Represents the top-level structure of an llvm program in an opaque object."""
@@ -264,12 +273,26 @@ class BasicBlock(LLVMObject):
i = lib.LLVMGetLastInstruction(self)
return i and Instruction(i)
+ def __as_value(self):
+ return Value(lib.LLVMBasicBlockAsValue(self))
+
@property
def name(self):
- return lib.LLVMGetValueName(Value(lib.LLVMBasicBlockAsValue(self)))
+ return lib.LLVMGetValueName(self.__as_value())
def dump(self):
- lib.LLVMDumpValue(Value(lib.LLVMBasicBlockAsValue(self)))
+ lib.LLVMDumpValue(self.__as_value())
+
+ def get_operand(self, i):
+ return Value(lib.LLVMGetOperand(self.__as_value(),
+ i))
+
+ def set_operand(self, i, v):
+ return lib.LLVMSetOperand(self.__as_value(),
+ i, v)
+
+ def __len__(self):
+ return lib.LLVMGetNumOperands(self.__as_value())
class __inst_iterator(object):
def __init__(self, bb, reverse=False):
@@ -448,6 +471,15 @@ def register_library(library):
library.LLVMDumpValue.argtypes = [Value]
library.LLVMDumpValue.restype = None
+ library.LLVMGetOperand.argtypes = [Value, c_uint]
+ library.LLVMGetOperand.restype = c_object_p
+
+ library.LLVMSetOperand.argtypes = [Value, Value, c_uint]
+ library.LLVMSetOperand.restype = None
+
+ library.LLVMGetNumOperands.argtypes = [Value]
+ library.LLVMGetNumOperands.restype = c_uint
+
# Basic Block Declarations.
library.LLVMGetFirstBasicBlock.argtypes = [Function]
library.LLVMGetFirstBasicBlock.restype = c_object_p
diff --git a/bindings/python/llvm/tests/test_core.py b/bindings/python/llvm/tests/test_core.py
index ec47c67bbc..63f84c828b 100644
--- a/bindings/python/llvm/tests/test_core.py
+++ b/bindings/python/llvm/tests/test_core.py
@@ -115,9 +115,13 @@ class TestCore(TestBase):
for inst in bb:
self.assertEqual(inst.name, inst_list[i][0])
self.assertEqual(inst.opcode, inst_list[i][1])
+ for op in range(len(inst)):
+ o = inst.get_operand(op)
+ print o.name
+ o.dump()
inst.dump()
i += 1
-
+
# Backwards
for inst in reversed(bb):
i -= 1