From bba30621f1e4535fe5030a3f841d347e733607a7 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 10 Oct 2012 10:47:56 -0500 Subject: [PATCH] Allow to_native_object & to_native_assembly to receive an optional fileobj to write to. --- llvm/core.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/llvm/core.py b/llvm/core.py index da260a3..6ef2fad 100644 --- a/llvm/core.py +++ b/llvm/core.py @@ -544,15 +544,29 @@ class Module(llvm.Ownable, llvm.Cacheable): id = property(_get_id, _set_id) - def to_native_object(self): - '''returns byte string of the module as native object code - ''' - return _core.LLVMGetNativeCodeFromModule(self.ptr, 0) + def to_native_object(self, fileobj=None): + '''Outputs the byte string of the module as native object code - def to_native_assembly(self): - '''returns byte string of the module as native assembly code + If a fileobj is given, the output is written to it; + Otherwise, the output is returned ''' - return _core.LLVMGetNativeCodeFromModule(self.ptr, 1) + data = _core.LLVMGetNativeCodeFromModule(self.ptr, 0) + if fileobj is not None: + fileobj.write(data) + else: + return data + + def to_native_assembly(self, fileobj=None): + '''Outputs the byte string of the module as native assembly code + + If a fileobj is given, the output is written to it; + Otherwise, the output is returned + ''' + data = _core.LLVMGetNativeCodeFromModule(self.ptr, 1) + if fileobj is not None: + fileobj.write(data) + else: + return data #===----------------------------------------------------------------------=== # Types