Fixes various problem in llvm.core
This commit is contained in:
parent
230583f42d
commit
0681d2f37e
1 changed files with 35 additions and 35 deletions
70
llvm/core.py
70
llvm/core.py
|
|
@ -318,7 +318,7 @@ class Module(llvm.Wrapper):
|
||||||
ll = str(module_obj)
|
ll = str(module_obj)
|
||||||
print module_obj # same as `print ll'
|
print module_obj # same as `print ll'
|
||||||
"""
|
"""
|
||||||
return str(self.ptr)
|
return str(self._ptr)
|
||||||
|
|
||||||
def __eq__(self, rhs):
|
def __eq__(self, rhs):
|
||||||
if isinstance(rhs, Module):
|
if isinstance(rhs, Module):
|
||||||
|
|
@ -331,20 +331,20 @@ class Module(llvm.Wrapper):
|
||||||
|
|
||||||
|
|
||||||
def _get_target(self):
|
def _get_target(self):
|
||||||
return self.ptr.getTargetTriple()
|
return self._ptr.getTargetTriple()
|
||||||
|
|
||||||
def _set_target(self, value):
|
def _set_target(self, value):
|
||||||
return self.ptr.setTargetTriple(value)
|
return self._ptr.setTargetTriple(value)
|
||||||
|
|
||||||
target = property(_get_target, _set_target,
|
target = property(_get_target, _set_target,
|
||||||
doc="The target triple string describing the target host.")
|
doc="The target triple string describing the target host.")
|
||||||
|
|
||||||
|
|
||||||
def _get_data_layout(self):
|
def _get_data_layout(self):
|
||||||
return self.ptr.getDataLayout()
|
return self._ptr.getDataLayout()
|
||||||
|
|
||||||
def _set_data_layout(self, value):
|
def _set_data_layout(self, value):
|
||||||
return self.ptr.setDataLayout(value)
|
return self._ptr.setDataLayout(value)
|
||||||
|
|
||||||
data_layout = property(_get_data_layout, _set_data_layout,
|
data_layout = property(_get_data_layout, _set_data_layout,
|
||||||
doc = """The data layout string for the module's target platform.
|
doc = """The data layout string for the module's target platform.
|
||||||
|
|
@ -383,7 +383,7 @@ class Module(llvm.Wrapper):
|
||||||
raise llvm.LLVMException(errmsg)
|
raise llvm.LLVMException(errmsg)
|
||||||
|
|
||||||
def get_type_named(self, name):
|
def get_type_named(self, name):
|
||||||
typ = self.ptr.getTypeByName(name)
|
typ = self._ptr.getTypeByName(name)
|
||||||
return StructType(typ)
|
return StructType(typ)
|
||||||
|
|
||||||
def add_global_variable(self, ty, name, addrspace=0):
|
def add_global_variable(self, ty, name, addrspace=0):
|
||||||
|
|
@ -405,12 +405,12 @@ class Module(llvm.Wrapper):
|
||||||
|
|
||||||
def get_global_variable_named(self, name):
|
def get_global_variable_named(self, name):
|
||||||
"""Return a GlobalVariable object for the given name."""
|
"""Return a GlobalVariable object for the given name."""
|
||||||
ptr = self.ptr.getNamedGlobal(name)
|
ptr = self._ptr.getNamedGlobal(name)
|
||||||
return GlobalVariable(ptr)
|
return GlobalVariable(ptr)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def global_variables(self):
|
def global_variables(self):
|
||||||
return self.ptr.list_globals()
|
return self._ptr.list_globals()
|
||||||
|
|
||||||
def add_function(self, ty, name):
|
def add_function(self, ty, name):
|
||||||
"""Add a function of given type with given name."""
|
"""Add a function of given type with given name."""
|
||||||
|
|
@ -421,7 +421,7 @@ class Module(llvm.Wrapper):
|
||||||
|
|
||||||
def get_function_named(self, name):
|
def get_function_named(self, name):
|
||||||
"""Return a Function object representing function with given name."""
|
"""Return a Function object representing function with given name."""
|
||||||
fn = self.ptr.getFunction(name)
|
fn = self._ptr.getFunction(name)
|
||||||
if fn is None:
|
if fn is None:
|
||||||
return None
|
return None
|
||||||
return Function(fn)
|
return Function(fn)
|
||||||
|
|
@ -429,14 +429,14 @@ class Module(llvm.Wrapper):
|
||||||
def get_or_insert_function(self, ty, name):
|
def get_or_insert_function(self, ty, name):
|
||||||
"""Like get_function_named(), but does add_function() first, if
|
"""Like get_function_named(), but does add_function() first, if
|
||||||
function is not present."""
|
function is not present."""
|
||||||
constant = self.ptr.getOrInsertFunction(name, ty._ptr)
|
constant = self._ptr.getOrInsertFunction(name, ty._ptr)
|
||||||
fn = constant._downcast(api.llvm.Function)
|
fn = constant._downcast(api.llvm.Function)
|
||||||
return Function(fn)
|
return Function(fn)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def functions(self):
|
def functions(self):
|
||||||
"""All functions in this module."""
|
"""All functions in this module."""
|
||||||
return map(Function, self.ptr.list_functions())
|
return map(Function, self._ptr.list_functions())
|
||||||
|
|
||||||
def verify(self):
|
def verify(self):
|
||||||
"""Verify module.
|
"""Verify module.
|
||||||
|
|
@ -445,7 +445,7 @@ class Module(llvm.Wrapper):
|
||||||
error."""
|
error."""
|
||||||
action = api.llvm.VerifierFailureAction.ReturnStatusAction
|
action = api.llvm.VerifierFailureAction.ReturnStatusAction
|
||||||
errio = StringIO()
|
errio = StringIO()
|
||||||
broken = api.llvm.verifyModule(self.ptr, action, errio)
|
broken = api.llvm.verifyModule(self._ptr, action, errio)
|
||||||
if broken:
|
if broken:
|
||||||
raise llvm.LLVMException(errio.getvalue())
|
raise llvm.LLVMException(errio.getvalue())
|
||||||
|
|
||||||
|
|
@ -463,15 +463,15 @@ class Module(llvm.Wrapper):
|
||||||
if fileobj is None:
|
if fileobj is None:
|
||||||
ret = True
|
ret = True
|
||||||
fileobj = StringIO
|
fileobj = StringIO
|
||||||
api.llvm.WriteBitcodeToFile(self.ptr, fileobj)
|
api.llvm.WriteBitcodeToFile(self._ptr, fileobj)
|
||||||
if ret:
|
if ret:
|
||||||
return fileobj.getvalue()
|
return fileobj.getvalue()
|
||||||
|
|
||||||
def _get_id(self):
|
def _get_id(self):
|
||||||
return self.ptr.getModuleIdentifier(self.ptr)
|
return self._ptr.getModuleIdentifier(self._ptr)
|
||||||
|
|
||||||
def _set_id(self, string):
|
def _set_id(self, string):
|
||||||
self.ptr.setModuleIdentifier(string)
|
self._ptr.setModuleIdentifier(string)
|
||||||
|
|
||||||
id = property(_get_id, _set_id)
|
id = property(_get_id, _set_id)
|
||||||
|
|
||||||
|
|
@ -508,13 +508,13 @@ class Module(llvm.Wrapper):
|
||||||
return self._to_native_something(fileobj, CGFT.CGFT_AssemblyFile)
|
return self._to_native_something(fileobj, CGFT.CGFT_AssemblyFile)
|
||||||
|
|
||||||
def get_or_insert_named_metadata(self, name):
|
def get_or_insert_named_metadata(self, name):
|
||||||
return NamedMetadata(self.ptr.getOrInsertNamedMetadata(name))
|
return NamedMetadata(self._ptr.getOrInsertNamedMetadata(name))
|
||||||
|
|
||||||
def get_named_metadata(self, name):
|
def get_named_metadata(self, name):
|
||||||
return NamedMetadata(self.ptr.get_named_metadata(name))
|
return NamedMetadata(self._ptr.get_named_metadata(name))
|
||||||
|
|
||||||
def clone(self):
|
def clone(self):
|
||||||
return NamedMetadata(api.llvm.CloneModule(self.ptr))
|
return NamedMetadata(api.llvm.CloneModule(self._ptr))
|
||||||
|
|
||||||
class Type(llvm.Wrapper):
|
class Type(llvm.Wrapper):
|
||||||
"""Represents a type, like a 32-bit integer or an 80-bit x86 float.
|
"""Represents a type, like a 32-bit integer or an 80-bit x86 float.
|
||||||
|
|
@ -860,7 +860,7 @@ class User(Value):
|
||||||
for i in range(self.operand_count)]
|
for i in range(self.operand_count)]
|
||||||
|
|
||||||
def _get_operand(self, i):
|
def _get_operand(self, i):
|
||||||
return _make_value(_core.LLVMUserGetOperand(self.ptr, i))
|
return _make_value(_core.LLVMUserGetOperand(self._ptr, i))
|
||||||
|
|
||||||
class Constant(User):
|
class Constant(User):
|
||||||
|
|
||||||
|
|
@ -1309,7 +1309,7 @@ class Function(GlobalValue):
|
||||||
return self._ptr.viewCFG()
|
return self._ptr.viewCFG()
|
||||||
|
|
||||||
def add_attribute(self, attr):
|
def add_attribute(self, attr):
|
||||||
_core.LLVMAddFunctionAttr(self.ptr, attr)
|
_core.LLVMAddFunctionAttr(self._ptr, attr)
|
||||||
|
|
||||||
def remove_attribute(self, attr):
|
def remove_attribute(self, attr):
|
||||||
attrbldr = api.llvm.AttrBuilder()
|
attrbldr = api.llvm.AttrBuilder()
|
||||||
|
|
@ -1589,7 +1589,7 @@ class Builder(llvm.Wrapper):
|
||||||
context = api.llvm.getGlobalContext()
|
context = api.llvm.getGlobalContext()
|
||||||
ptr = api.llvm.IRBuilder.new(context)
|
ptr = api.llvm.IRBuilder.new(context)
|
||||||
ptr.SetInsertPoint(basic_block._ptr)
|
ptr.SetInsertPoint(basic_block._ptr)
|
||||||
return BasicBlock(ptr)
|
return Builder(ptr)
|
||||||
|
|
||||||
def position_at_beginning(self, bblk):
|
def position_at_beginning(self, bblk):
|
||||||
"""Position the builder at the beginning of the given block.
|
"""Position the builder at the beginning of the given block.
|
||||||
|
|
@ -1970,20 +1970,20 @@ def load_library_permanently(filename):
|
||||||
path of the .so file) using LLVM. Symbols from these are available
|
path of the .so file) using LLVM. Symbols from these are available
|
||||||
from the execution engine thereafter."""
|
from the execution engine thereafter."""
|
||||||
with contextlib.closing(StringIO()) as errmsg:
|
with contextlib.closing(StringIO()) as errmsg:
|
||||||
failed = _api.llvm.sys.LoadLibraryPermanently(filename, errmsg)
|
failed = api.llvm.sys.LoadLibraryPermanently(filename, errmsg)
|
||||||
if failed:
|
if failed:
|
||||||
raise llvm.LLVMException(errmsg.getvalue())
|
raise llvm.LLVMException(errmsg.getvalue())
|
||||||
|
|
||||||
def inline_function(call):
|
def inline_function(call):
|
||||||
info = _api.llvm.InlineFunctionInfo()
|
info = api.llvm.InlineFunctionInfo()
|
||||||
return _api.llvm.InlineFunction(call._ptr, info)
|
return api.llvm.InlineFunction(call._ptr, info)
|
||||||
|
|
||||||
def parse_environment_options(progname, envname):
|
def parse_environment_options(progname, envname):
|
||||||
_api.llvm.cl.ParseEnvironmentOptions(progname, envname)
|
api.llvm.cl.ParseEnvironmentOptions(progname, envname)
|
||||||
|
|
||||||
if _api.llvm.InitializeNativeTarget():
|
if api.llvm.InitializeNativeTarget():
|
||||||
raise llvm.LLVMException("No native target!?")
|
raise llvm.LLVMException("No native target!?")
|
||||||
if _api.llvm.InitializeNativeTargetAsmPrinter():
|
if api.llvm.InitializeNativeTargetAsmPrinter():
|
||||||
# should this be an optional feature?
|
# should this be an optional feature?
|
||||||
# should user trigger the initialization?
|
# should user trigger the initialization?
|
||||||
raise llvm.LLVMException("No native asm printer!?")
|
raise llvm.LLVMException("No native asm printer!?")
|
||||||
|
|
@ -1996,17 +1996,17 @@ HAS_PTX = HAS_NVPTX = False
|
||||||
|
|
||||||
if True: # use PTX?
|
if True: # use PTX?
|
||||||
try:
|
try:
|
||||||
_api.LLVMInitializePTXTarget()
|
api.LLVMInitializePTXTarget()
|
||||||
_api.LLVMInitializePTXTargetInfo()
|
api.LLVMInitializePTXTargetInfo()
|
||||||
_api.LLVMInitializePTXTargetMC()
|
api.LLVMInitializePTXTargetMC()
|
||||||
_api.LLVMInitializePTXAsmPrinter()
|
api.LLVMInitializePTXAsmPrinter()
|
||||||
HAS_PTX = True
|
HAS_PTX = True
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
try:
|
try:
|
||||||
_api.LLVMInitializeNVPTXTarget()
|
api.LLVMInitializeNVPTXTarget()
|
||||||
_api.LLVMInitializeNVPTXTargetInfo()
|
api.LLVMInitializeNVPTXTargetInfo()
|
||||||
_api.LLVMInitializeNVPTXTargetMC()
|
api.LLVMInitializeNVPTXTargetMC()
|
||||||
_api.LLVMInitializeNVPTXAsmPrinter()
|
api.LLVMInitializeNVPTXAsmPrinter()
|
||||||
HAS_NVPTX = True
|
HAS_NVPTX = True
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue