Added Module.id property (getter+setter).

Updated test/asm.py to use unittest.
This commit is contained in:
Siu Kwan Lam 2012-07-20 20:15:21 -07:00
commit 9bbeee519b
6 changed files with 57 additions and 12 deletions

View file

@ -85,6 +85,8 @@ _wLLVMModuleCreateWithName(PyObject *self, PyObject *args)
_wrap_obj2str(LLVMGetDataLayout, LLVMModuleRef)
_wrap_objstr2none(LLVMSetDataLayout, LLVMModuleRef)
_wrap_obj2str(LLVMGetModuleIdentifier, LLVMModuleRef)
_wrap_objstr2none(LLVMSetModuleIdentifier, LLVMModuleRef)
_wrap_obj2str(LLVMGetTarget, LLVMModuleRef)
_wrap_objstr2none(LLVMSetTarget, LLVMModuleRef)
_wrap_objstr2none(LLVMModuleAddLibrary, LLVMModuleRef)
@ -94,7 +96,7 @@ _wrap_obj2none(LLVMDisposeModule, LLVMModuleRef)
_wrap_dumper(LLVMDumpModuleToString, LLVMModuleRef)
_wrap_obj2obj(LLVMModuleGetPointerSize, LLVMModuleRef, int)
_wrap_objstrobj2obj(LLVMModuleGetOrInsertFunction, LLVMModuleRef,
LLVMTypeRef, LLVMValueRef)
LLVMTypeRef, LLVMValueRef)
static PyObject *
_wLLVMVerifyModule(PyObject *self, PyObject *args)
@ -1319,7 +1321,9 @@ static PyMethodDef core_methods[] = {
/* Modules */
_method( LLVMModuleCreateWithName )
_method( LLVMGetDataLayout )
_method( LLVMSetDataLayout )
_method( LLVMSetDataLayout )
_method( LLVMGetModuleIdentifier )
_method( LLVMSetModuleIdentifier )
_method( LLVMGetTarget )
_method( LLVMSetTarget )
_method( LLVMModuleAddLibrary )

View file

@ -507,7 +507,14 @@ class Module(llvm.Ownable, llvm.Cacheable):
def add_library(self, name):
return _core.LLVMModuleAddLibrary(self.ptr, name)
def _get_id(self):
return _core.LLVMGetModuleIdentifier(self.ptr)
def _set_id(self, string):
_core.LLVMSetModuleIdentifier(self.ptr, string)
id = property(_get_id, _set_id)
#===----------------------------------------------------------------------===
# Types

View file

@ -90,6 +90,16 @@ char *do_print(W obj)
return strdup(buf.str().c_str());
}
char *LLVMGetModuleIdentifier(LLVMModuleRef module)
{
return strdup(llvm::unwrap(module)->getModuleIdentifier().c_str());
}
void LLVMSetModuleIdentifier(LLVMModuleRef module, const char * name)
{
llvm::unwrap(module)->setModuleIdentifier(name);
}
char *LLVMDumpModuleToString(LLVMModuleRef module)
{
std::string s;

View file

@ -41,6 +41,17 @@
extern "C" {
#endif
/*
* Wraps llvm::Module::getModuleIdentifier()
*/
char *LLVMGetModuleIdentifier(LLVMModuleRef module);
/*
* Wraps llvm::Module::setModuleIdentifier()
*/
void LLVMSetModuleIdentifier(LLVMModuleRef module, const char * name);
/* Notes:
* - Some returned strings must be disposed of by LLVMDisposeMessage. These are
* indicated in the comments. Where it is not indicated, DO NOT call dispose.