Add more functions to GlobalValue GlobalVariable, StructType and Module

This commit is contained in:
Siu Kwan Lam 2013-02-05 18:48:46 -06:00
commit 9c81fa1f63
6 changed files with 201 additions and 10 deletions

View file

@ -6,3 +6,21 @@ from Value import GlobalValue
class GlobalValue:
_include_ = 'llvm/GlobalValue.h'
LinkageTypes = Enum('''
ExternalLinkage, AvailableExternallyLinkage, LinkOnceAnyLinkage,
LinkOnceODRLinkage, LinkOnceODRAutoHideLinkage, WeakAnyLinkage,
WeakODRLinkage, AppendingLinkage, InternalLinkage, PrivateLinkage,
LinkerPrivateLinkage, LinkerPrivateWeakLinkage, DLLImportLinkage,
DLLExportLinkage, ExternalWeakLinkage, CommonLinkage
''')
VisibilityTypes = Enum('''DefaultVisibility,
HiddenVisibility,
ProtectedVisibility''')
setLinkage = Method(Void, LinkageTypes)
getLinkage = Method(LinkageTypes)
setVisibility = Method(Void, VisibilityTypes)
getVisibility = Method(VisibilityTypes)

View file

@ -1,8 +1,48 @@
from binding import *
from namespace import llvm
from GlobalValue import GlobalValue
GlobalVariable = llvm.Class(GlobalValue)
@llvm.Class(GlobalValue)
from Constant import Constant
from Module import Module
from Type import Type
from ADT.StringRef import StringRef
@GlobalVariable
class GlobalVariable:
pass
ThreadLocalMode = Enum('''NotThreadLocal, GeneralDynamicTLSModel,
LocalDynamicTLSModel, InitialExecTLSModel,
LocalExecTLSModel
''')
new = Constructor(ref(Module),
ptr(Type),
cast(bool, Bool), # is constant
GlobalValue.LinkageTypes,
ptr(Constant), # initializer -- can be None
cast(str, StringRef), # name
ptr(GlobalVariable), # insert before
ThreadLocalMode,
cast(int, Unsigned), # address-space
# cast(bool, Bool), # externally initialized
).require_only(5)
setThreadLocal = Method(Void, cast(bool, Bool))
setThreadLocalMode = Method(Void, ThreadLocalMode)
isThreadLocal = Method(cast(Bool, bool))
isConstant = Method(cast(Bool, bool))
setConstant = Method(Void, ptr(Constant))
setInitializer = Method(Void, ptr(Constant))
getInitializer = Method(ptr(Constant))
hasInitializer = Method(cast(Bool, bool))
hasUniqueInitializer = Method(cast(Bool, bool))
hasDefinitiveInitializer = Method(cast(Bool, bool))
# isExternallyInitialized = Method(cast(Bool, bool))
# setExternallyinitialized = Method(Void, cast(bool, Bool))

View file

@ -1,14 +1,19 @@
from binding import *
from namespace import llvm
Module = llvm.Class()
from LLVMContext import LLVMContext
from ADT.StringRef import StringRef
from Constant import Constant
from GlobalVariable import GlobalVariable
from Function import Function
from DerivedTypes import FunctionType
from Support.raw_ostream import raw_ostream
from Assembly.AssemblyAnnotationWriter import AssemblyAnnotationWriter
from Type import Type, StructType
@llvm.Class()
@Module
class Module:
_include_ = "llvm/Module.h"
# Enumerators
@ -38,6 +43,21 @@ class Module:
# Function Accessors
getOrInsertFunction = Method(ptr(Constant), cast(str, StringRef),
ptr(FunctionType))
getFunction = Method(ptr(Function), cast(str, StringRef))
# Function Iteration
list_functions = CustomMethod('Module_list_functions', PyObjectPtr)
# GlobalVariabe Accessors
getGlobalVariable = Method(ptr(GlobalVariable),
cast(str, StringRef),
cast(bool, Bool),
).require_only(1)
getNamedGlobal = Method(ptr(GlobalVariable), cast(str, StringRef))
getOrInsertGlobal = Method(ptr(Constant), cast(str, StringRef), ptr(Type))
# GlobalVariable Iteration
list_globals = CustomMethod('Module_list_globals', PyObjectPtr)
# Utilities
dump = Method(Void)
@ -52,3 +72,7 @@ class Module:
return os.str()
dropAllReferences = Method()
getTypeByName = Method(ptr(StructType), cast(str, StringRef))

View file

@ -110,6 +110,12 @@ class Type:
getIntNPtrTy = StaticMethod(ptr(PointerType),
ref(LLVMContext), cast(int, Unsigned))
@CustomPythonMethod
def __str__(self):
import extra
os = extra.make_raw_ostream_for_printing()
self.print_(os)
return os.str()
@IntegerType
class IntegerType:
@ -130,4 +136,23 @@ class PointerType:
@StructType
class StructType:
pass
isPacked = Method(cast(Bool, bool))
isLiteral = Method(cast(Bool, bool))
isOpaque = Method(cast(Bool, bool))
hasName = Method(cast(Bool, bool))
getName = Method(cast(StringRef, str))
setName = Method(Void, cast(str, StringRef))
setBody = CustomMethod('StructType_setBody',
PyObjectPtr, # None
PyObjectPtr, # ArrayRef<Type*>
cast(bool, Bool),
).require_only(1)
getNumElements = Method(cast(Unsigned, int))
getElementType = Method(ptr(Type), cast(int, Unsigned))
create = StaticMethod(ptr(StructType),
ref(LLVMContext),
cast(str, StringRef),
).require_only(1)
isValidElementType = StaticMethod(cast(Bool, bool), ptr(Type))

View file

@ -1,13 +1,8 @@
from binding import *
from namespace import llvm
from Support.raw_ostream import raw_ostream
from Assembly.AssemblyAnnotationWriter import AssemblyAnnotationWriter
from Type import Type
from LLVMContext import LLVMContext
from ADT.StringRef import StringRef
Value = llvm.Class()
# forward declarations
Value = llvm.Class()
Argument = llvm.Class(Value)
MDNode = llvm.Class(Value)
User = llvm.Class(Value)
@ -16,6 +11,13 @@ Constant = llvm.Class(User)
GlobalValue = llvm.Class(Constant)
Function = llvm.Class(GlobalValue)
from Support.raw_ostream import raw_ostream
from Assembly.AssemblyAnnotationWriter import AssemblyAnnotationWriter
from Type import Type
from LLVMContext import LLVMContext
from ADT.StringRef import StringRef
@Value
class Value: