Add Function and some Function methods

This commit is contained in:
Siu Kwan Lam 2013-01-25 15:41:38 -06:00
commit c76096bbcb
5 changed files with 40 additions and 2 deletions

View file

@ -0,0 +1,19 @@
from binding import *
from namespace import llvm
from GlobalValue import GlobalValue
from Constant import Constant
from Type import Type
from DerivedTypes import FunctionType
from LLVMContext import LLVMContext
@llvm.Class(GlobalValue)
class Function:
_include_ = 'llvm/Function.h'
_downcast_ = GlobalValue, Constant
getReturnType = Method(ptr(Type))
getFunctionType = Method(ptr(FunctionType))
getContext = Method(ref(LLVMContext))
isVarArg = Method(cast(Bool, bool))
getIntrinsicID = Method(cast(Unsigned, int))
isIntrinsic = Method(cast(Bool, bool))

View file

@ -0,0 +1,8 @@
from binding import *
from namespace import llvm
from Constant import Constant
@llvm.Class(Constant)
class GlobalValue:
_include_ = 'llvm/GlobalValue.h'

View file

@ -3,6 +3,7 @@ from namespace import llvm
from LLVMContext import LLVMContext from LLVMContext import LLVMContext
from StringRef import StringRef from StringRef import StringRef
from Constant import Constant from Constant import Constant
from Function import Function
from DerivedTypes import FunctionType from DerivedTypes import FunctionType
from raw_ostream import raw_ostream from raw_ostream import raw_ostream
from AssemblyAnnotationWriter import AssemblyAnnotationWriter from AssemblyAnnotationWriter import AssemblyAnnotationWriter

View file

@ -24,4 +24,4 @@ class Value:
getName = Method(cast(StringRef, str)) getName = Method(cast(StringRef, str))
setName = Method(Void, cast(str, StringRef)) setName = Method(Void, cast(str, StringRef))
replaceAllUsesWith = Method(Void, ptr(Value)) replaceAllUsesWith = Method(Void, ptr(Value))

View file

@ -37,7 +37,8 @@ os = extra.make_raw_ostream_for_printing()
fnty.print_(os) fnty.print_(os)
print os.str() print os.str()
fn = m.getOrInsertFunction("foo", fnty) const = m.getOrInsertFunction("foo", fnty)
fn = extra.downcast(const, api.Function)
os = extra.make_raw_ostream_for_printing() os = extra.make_raw_ostream_for_printing()
fn.print_(os, None) fn.print_(os, None)
print os.str() print os.str()
@ -45,3 +46,12 @@ assert fn.hasName()
assert 'foo' == fn.getName() assert 'foo' == fn.getName()
fn.setName('bar') fn.setName('bar')
assert 'bar' == fn.getName() assert 'bar' == fn.getName()
os = extra.make_raw_ostream_for_printing()
assert fn.getReturnType() is int1ty
assert fnty is fn.getFunctionType()
assert fn.isVarArg() == False
assert fn.getIntrinsicID() == 0
assert not fn.isIntrinsic()