Added convert module from/to bitcode.

git-svn-id: http://llvm-py.googlecode.com/svn/trunk@28 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
mdevan.foobar 2008-08-03 16:01:02 +00:00
commit 392f2e7e79
5 changed files with 118 additions and 11 deletions

View file

@ -721,6 +721,20 @@ class Module(llvm.Ownable):
"""
return Module(_core.LLVMModuleCreateWithName(id))
@staticmethod
def from_bitcode(fileobj):
"""Create a Module instance from the contents of a bitcode
file."""
data = fileobj.read()
ret = _core.LLVMGetModuleFromBitcode(data)
if not ret:
raise llvm.LLVMException, "Unable to create module from bitcode"
elif isinstance(ret, str):
raise llvm.LLVMException, ret
else:
return Module(ret)
def __init__(self, ptr):
"""DO NOT CALL DIRECTLY.
@ -837,6 +851,15 @@ class Module(llvm.Ownable):
if ret != "":
raise llvm.LLVMException, ret
def to_bitcode(self, fileobj):
"""Write bitcode representation of module to given file-like
object."""
data = _core.LLVMGetBitcodeFromModule(self.ptr)
if not data:
raise llvm.LLVMException, "Unable to create bitcode"
fileobj.write(data)
#===----------------------------------------------------------------------===
# Types