can now clone modules
This commit is contained in:
parent
e0d1b94053
commit
d781e83bd1
5 changed files with 64 additions and 0 deletions
|
|
@ -297,6 +297,7 @@ _wLLVMLinkModules(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
_wrap_objstr2obj(LLVMModuleGetOrInsertNamedMetaData, LLVMModuleRef, LLVMNamedMDRef)
|
_wrap_objstr2obj(LLVMModuleGetOrInsertNamedMetaData, LLVMModuleRef, LLVMNamedMDRef)
|
||||||
_wrap_objstr2obj(LLVMModuleGetNamedMetaData, LLVMModuleRef, LLVMNamedMDRef)
|
_wrap_objstr2obj(LLVMModuleGetNamedMetaData, LLVMModuleRef, LLVMNamedMDRef)
|
||||||
|
_wrap_obj2obj(LLVMCloneModule, LLVMModuleRef, LLVMModuleRef)
|
||||||
|
|
||||||
/*===----------------------------------------------------------------------===*/
|
/*===----------------------------------------------------------------------===*/
|
||||||
/* Types */
|
/* Types */
|
||||||
|
|
@ -1577,6 +1578,7 @@ static PyMethodDef core_methods[] = {
|
||||||
_method( LLVMLinkModules )
|
_method( LLVMLinkModules )
|
||||||
_method( LLVMModuleGetOrInsertNamedMetaData )
|
_method( LLVMModuleGetOrInsertNamedMetaData )
|
||||||
_method( LLVMModuleGetNamedMetaData )
|
_method( LLVMModuleGetNamedMetaData )
|
||||||
|
_method( LLVMCloneModule )
|
||||||
|
|
||||||
/* Types */
|
/* Types */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -582,6 +582,9 @@ class Module(llvm.Ownable, llvm.Cacheable):
|
||||||
ptr = _core.LLVMModuleGetNamedMetaData(self.ptr, name)
|
ptr = _core.LLVMModuleGetNamedMetaData(self.ptr, name)
|
||||||
return NamedMetaData(ptr)
|
return NamedMetaData(ptr)
|
||||||
|
|
||||||
|
def clone(self):
|
||||||
|
return Module(_core.LLVMCloneModule(self.ptr))
|
||||||
|
|
||||||
#===----------------------------------------------------------------------===
|
#===----------------------------------------------------------------------===
|
||||||
# Types
|
# Types
|
||||||
#===----------------------------------------------------------------------===
|
#===----------------------------------------------------------------------===
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,12 @@ const CodeGenOpt::Level OptLevelMap[] = {
|
||||||
};
|
};
|
||||||
} // end anony namespace
|
} // end anony namespace
|
||||||
|
|
||||||
|
LLVMModuleRef LLVMCloneModule(LLVMModuleRef mod)
|
||||||
|
{
|
||||||
|
using namespace llvm;
|
||||||
|
return wrap(CloneModule(unwrap(mod)));
|
||||||
|
}
|
||||||
|
|
||||||
const char * LLVMDumpNamedMDToString(LLVMNamedMDRef nmd)
|
const char * LLVMDumpNamedMDToString(LLVMNamedMDRef nmd)
|
||||||
{
|
{
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,13 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wraps llvm::CloneModule
|
||||||
|
*/
|
||||||
|
LLVMModuleRef LLVMCloneModule(LLVMModuleRef mod);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wraps NamedMDNode::print()
|
* Wraps NamedMDNode::print()
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
46
test/clonemodule.py
Normal file
46
test/clonemodule.py
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# Import the llvm-py modules.
|
||||||
|
from llvm import *
|
||||||
|
from llvm.core import *
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
class TestCloneModule(unittest.TestCase):
|
||||||
|
def test_example(self):
|
||||||
|
my_module = Module.new('my_module')
|
||||||
|
|
||||||
|
ty_int = Type.int() # by default 32 bits
|
||||||
|
|
||||||
|
ty_func = Type.function(ty_int, [ty_int, ty_int])
|
||||||
|
|
||||||
|
f_sum = my_module.add_function(ty_func, "sum")
|
||||||
|
|
||||||
|
self.assertEqual(str(f_sum).strip(), 'declare i32 @sum(i32, i32)')
|
||||||
|
|
||||||
|
f_sum.args[0].name = "a"
|
||||||
|
f_sum.args[1].name = "b"
|
||||||
|
|
||||||
|
bb = f_sum.append_basic_block("entry")
|
||||||
|
|
||||||
|
builder = Builder.new(bb)
|
||||||
|
|
||||||
|
tmp = builder.add(f_sum.args[0], f_sum.args[1], "tmp")
|
||||||
|
|
||||||
|
self.assertEqual(str(tmp).strip(), '%tmp = add i32 %a, %b')
|
||||||
|
|
||||||
|
builder.ret(tmp)
|
||||||
|
|
||||||
|
cloned = my_module.clone()
|
||||||
|
|
||||||
|
self.assertTrue(id(cloned) != id(my_module))
|
||||||
|
self.assertTrue(str(cloned) == str(my_module))
|
||||||
|
self.assertTrue(cloned == my_module)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue