Added pointer_size and get_or_insert_function to Module

git-svn-id: http://llvm-py.googlecode.com/svn/trunk@43 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
mdevan.foobar 2008-09-16 17:03:21 +00:00
commit 2780d9fc10
5 changed files with 53 additions and 1 deletions

View file

@ -38,6 +38,9 @@ _wrap_objstr2none(LLVMDeleteTypeName, LLVMModuleRef)
_wrap_obj2none(LLVMDumpModule, LLVMModuleRef)
_wrap_obj2none(LLVMDisposeModule, LLVMModuleRef)
_wrap_dumper(LLVMDumpModuleToString, LLVMModuleRef)
_wrap_obj2obj(LLVMModuleGetPointerSize, LLVMModuleRef, int)
_wrap_objstrobj2obj(LLVMModuleGetOrInsertFunction, LLVMModuleRef,
LLVMTypeRef, LLVMValueRef)
static PyObject *
_wLLVMVerifyModule(PyObject *self, PyObject *args)
@ -942,6 +945,8 @@ static PyMethodDef core_methods[] = {
_method( LLVMGetModuleFromAssembly )
_method( LLVMGetModuleFromBitcode )
_method( LLVMGetBitcodeFromModule )
_method( LLVMModuleGetPointerSize )
_method( LLVMModuleGetOrInsertFunction )
/* Types */

View file

@ -822,6 +822,14 @@ class Module(llvm.Ownable):
"""
)
@property
def pointer_size(self):
"""Pointer size of target platform.
Can be 0, 32 or 64. Zero represents
llvm::Module::AnyPointerSize."""
return _core.LLVMModuleGetPointerSize(self.ptr)
def add_type_name(self, name, ty):
"""Map a string to a type.
@ -868,6 +876,9 @@ class Module(llvm.Ownable):
"""Return a Function object representing function with given name."""
return Function.get(self, name)
def get_or_insert_function(self, ty, name):
return Function.get_or_insert(self, ty, name)
@property
def functions(self):
"""All functions in this module.
@ -1603,7 +1614,15 @@ class Function(GlobalValue):
def new(module, func_ty, name):
check_is_module(module)
check_is_type(func_ty)
return Function(_core.LLVMAddFunction(module.ptr, name, func_ty.ptr), module)
return Function(_core.LLVMAddFunction(module.ptr, name, \
func_ty.ptr), module)
@staticmethod
def get_or_insert(module, func_ty, name):
check_is_module(module)
check_is_type(func_ty)
return Function(_core.LLVMModuleGetOrInsertFunction(module.ptr, \
name, func_ty.ptr), module)
@staticmethod
def get(module, name):

View file

@ -84,6 +84,24 @@ LLVMValueRef LLVMBuildVFCmp(LLVMBuilderRef B, LLVMRealPredicate Op,
}
#endif
unsigned LLVMModuleGetPointerSize(LLVMModuleRef M)
{
Module::PointerSize p = unwrap(M)->getPointerSize();
if (p == Module::Pointer32)
return 32;
else if (p == Module::Pointer64)
return 64;
return 0;
}
LLVMValueRef LLVMModuleGetOrInsertFunction(LLVMModuleRef M,
const char *Name, LLVMTypeRef FunctionTy)
{
FunctionType *ft = unwrap<FunctionType>(FunctionTy);
Constant *f = unwrap(M)->getOrInsertFunction(Name, ft);
return wrap(f);
}
#define inst_checkfn(ourfn, llvmfn) \
unsigned ourfn (LLVMValueRef I) { \
return unwrap<Instruction>(I)-> llvmfn () ? 1 : 0; \

View file

@ -51,6 +51,12 @@ LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef, LLVMValueRef V,
LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef B, int ID,
LLVMTypeRef *Types, unsigned Count);
/* module */
unsigned LLVMModuleGetPointerSize(LLVMModuleRef M);
LLVMValueRef LLVMModuleGetOrInsertFunction(LLVMModuleRef M,
const char *Name, LLVMTypeRef FunctionTy);
/* instruction */
unsigned LLVMInstIsTerminator(LLVMValueRef I);

View file

@ -52,6 +52,9 @@ def do_module():
ft = Type.function(ti, [ti])
m.add_function(ft, "func")
m.get_function_named("func")
m.get_or_insert_function(ft, "func")
m.get_or_insert_function(Type.function(ti, []), "func")
m.get_or_insert_function(ft, "func2")
fns = list(m.functions)
try:
m.verify()
@ -78,6 +81,7 @@ def do_module():
ss2.write(str(m))
m4 = Module.from_assembly(ss2)
t = m4 == m
t = m4.pointer_size
def do_type():