mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-28 22:24:28 +00:00
[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
This commit is contained in:
@ -107,6 +107,15 @@ class Value(LLVMObject):
|
|||||||
def dump(self):
|
def dump(self):
|
||||||
lib.LLVMDumpValue(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):
|
class Module(LLVMObject):
|
||||||
"""Represents the top-level structure of an llvm program in an opaque object."""
|
"""Represents the top-level structure of an llvm program in an opaque object."""
|
||||||
|
|
||||||
@ -264,12 +273,26 @@ class BasicBlock(LLVMObject):
|
|||||||
i = lib.LLVMGetLastInstruction(self)
|
i = lib.LLVMGetLastInstruction(self)
|
||||||
return i and Instruction(i)
|
return i and Instruction(i)
|
||||||
|
|
||||||
|
def __as_value(self):
|
||||||
|
return Value(lib.LLVMBasicBlockAsValue(self))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return lib.LLVMGetValueName(Value(lib.LLVMBasicBlockAsValue(self)))
|
return lib.LLVMGetValueName(self.__as_value())
|
||||||
|
|
||||||
def dump(self):
|
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):
|
class __inst_iterator(object):
|
||||||
def __init__(self, bb, reverse=False):
|
def __init__(self, bb, reverse=False):
|
||||||
@ -448,6 +471,15 @@ def register_library(library):
|
|||||||
library.LLVMDumpValue.argtypes = [Value]
|
library.LLVMDumpValue.argtypes = [Value]
|
||||||
library.LLVMDumpValue.restype = None
|
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.
|
# Basic Block Declarations.
|
||||||
library.LLVMGetFirstBasicBlock.argtypes = [Function]
|
library.LLVMGetFirstBasicBlock.argtypes = [Function]
|
||||||
library.LLVMGetFirstBasicBlock.restype = c_object_p
|
library.LLVMGetFirstBasicBlock.restype = c_object_p
|
||||||
|
@ -115,6 +115,10 @@ class TestCore(TestBase):
|
|||||||
for inst in bb:
|
for inst in bb:
|
||||||
self.assertEqual(inst.name, inst_list[i][0])
|
self.assertEqual(inst.name, inst_list[i][0])
|
||||||
self.assertEqual(inst.opcode, inst_list[i][1])
|
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()
|
inst.dump()
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user