Major refactoring

This commit is contained in:
Siu Kwan Lam 2013-01-25 12:29:31 -06:00
commit eba88b32ba
22 changed files with 999 additions and 924 deletions

View file

@ -1,6 +1,7 @@
from binding import *
from namespace import llvm
AssemblyAnnotationWriter = llvm.Class()
AssemblyAnnotationWriter.include.add("llvm/Assembly/AssemblyAnnotationWriter.h")
@llvm.Class()
class AssemblyAnnotationWriter:
_include_ = "llvm/Assembly/AssemblyAnnotationWriter.h"

View file

@ -2,4 +2,6 @@ from binding import *
from namespace import llvm
from User import User
Constant = User.Subclass()
@llvm.Class(User)
class Constant:
pass

View file

@ -4,17 +4,15 @@ from LLVMContext import LLVMContext
from Type import Type
from SmallVector import SmallVector_Type
FunctionType = Type.Subclass()
FunctionType.include.add('llvm/DerivedTypes.h')
FunctionType = llvm.Class(Type)
_get_signatures = [(FunctionType.Pointer,
Type.Pointer, Bool.From(bool)),
(FunctionType.Pointer,
Type.Pointer, SmallVector_Type.Ref, Bool.From(bool))]
@FunctionType
class FunctionType:
_include_ = 'llvm/DerivedTypes.h'
get = StaticMethod(ptr(FunctionType), ptr(Type), cast(bool, Bool))
get |= StaticMethod(ptr(FunctionType), ptr(Type), ref(SmallVector_Type), cast(bool, Bool))
isVarArg = Method(cast(Bool, bool))
getReturnType = Method(ptr(Type))
getParamType = Method(ptr(Type), cast(int, Unsigned))
getNumParams = Method(cast(Unsigned, int))
get = FunctionType.staticmultimethod(*_get_signatures)
isVarArg = FunctionType.method(Bool.To(bool))
getReturnType = FunctionType.method(Type.Pointer)
getParamType = FunctionType.method(Type.Pointer, Unsigned.From(int))
getNumParams = FunctionType.method(Unsigned.To(int))

View file

@ -1,8 +1,8 @@
from binding import *
from namespace import llvm
LLVMContext = llvm.Class()
LLVMContext.include.add("llvm/LLVMContext.h")
getGlobalContext = llvm.Function(LLVMContext.Ref)
@llvm.Class()
class LLVMContext:
_include_ = "llvm/LLVMContext.h"
llvm.Function('getGlobalContext', ref(LLVMContext))

View file

@ -7,39 +7,39 @@ from DerivedTypes import FunctionType
from raw_ostream import raw_ostream
from AssemblyAnnotationWriter import AssemblyAnnotationWriter
# class Module
Module = llvm.Class()
Module.include.add("llvm/Module.h")
@llvm.Class()
class Module:
_include_ = "llvm/Module.h"
# Enumerators
Endianness = Enum('AnyEndianness', 'LittleEndian', 'BigEndian')
PointerSize = Enum('AnyPointerSize', 'Pointer32', 'Pointer64')
# Enumerators
Endianness = Module.Enum('AnyEndianness', 'LittleEndian', 'BigEndian')
PointerSize = Module.Enum('AnyPointerSize', 'Pointer32', 'Pointer64')
# Constructors & Destructors
new = Constructor(cast(str, StringRef), ref(LLVMContext))
delete = Destructor()
# Constructors & Destructors
new = Module.new(StringRef.From(str), LLVMContext.Ref)
delete = Module.delete()
# Module Level Accessor
getModuleIdentifier = Method(cast(ConstStdString, str))
getDataLayout = Method(cast(ConstStdString, str))
getTargetTriple = Method(cast(ConstStdString, str))
getEndianness = Method(Endianness)
getPointerSize = Method(PointerSize)
getContext = Method(ref(LLVMContext))
getModuleInlineAsm = Method(cast(ConstStdString, str))
# Module Level Accessor
getModuleIdentifier = Module.method(ConstStdString.To(str))
getDataLayout = Module.method(ConstStdString.To(str))
getTargetTriple = Module.method(ConstStdString.To(str))
getEndianness = Module.method(Endianness)
getPointerSize = Module.method(PointerSize)
getContext = Module.method(LLVMContext.Ref)
getModuleInlineAsm = Module.method(ConstStdString.To(str))
# Module Level Mutators
setModuleIdentifier = Method(Void, cast(str, StringRef))
setDataLayout = Method(Void, cast(str, StringRef))
setTargetTriple = Method(Void, cast(str, StringRef))
setModuleInlineAsm = Method(Void, cast(str, StringRef))
appendModuleInlineAsm = Method(Void, cast(str, StringRef))
# Module Level Mutators
setModuleIdentifier = Module.method(Void, StringRef.From(str))
setDataLayout = Module.method(Void, StringRef.From(str))
setTargetTriple = Module.method(Void, StringRef.From(str))
setModuleInlineAsm = Module.method(Void, StringRef.From(str))
appendModuleInlineAsm = Module.method(Void, StringRef.From(str))
# Function Accessors
getOrInsertFunction = Method(ptr(Constant), cast(str, StringRef), ptr(FunctionType))
# Function Accessors
getOrInsertFunction = Module.method(Constant.Pointer, StringRef.From(str), FunctionType.Pointer)
# Utilities
dump = Method(Void)
print_ = Method(Void, ref(raw_ostream), ptr(AssemblyAnnotationWriter))
print_.realname = 'print'
# Utilities
dump = Module.method(Void)
print_ = Module.method(Void, raw_ostream.Ref, AssemblyAnnotationWriter.Pointer)
print_.realname = 'print'
dropAllReferences = Module.method(Void)
dropAllReferences = Method()

View file

@ -1,5 +1,6 @@
from binding import *
from namespace import llvm
SmallVector_Type = llvm.Class()
delete = SmallVector_Type.delete()
@llvm.Class()
class SmallVector_Type:
delete = Destructor()

View file

@ -1,6 +1,7 @@
from binding import *
from namespace import llvm
StringRef = llvm.Class()
StringRef.include.add("llvm/ADT/StringRef.h")
@llvm.Class()
class StringRef:
_include_ = "llvm/ADT/StringRef.h"

View file

@ -4,93 +4,112 @@ from LLVMContext import LLVMContext
from raw_ostream import raw_ostream
Type = llvm.Class()
Type.include.add('llvm/Type.h')
IntegerType = llvm.Class(Type)
CompositeType = llvm.Class(Type)
SequentialType = llvm.Class(CompositeType)
PointerType = llvm.Class(SequentialType)
IntegerType = Type.Subclass()
CompositeType = Type.Subclass()
SequentialType = CompositeType.Subclass()
PointerType = SequentialType.Subclass()
@Type
class Type:
_include_ = 'llvm/Type.h'
getContext = Type.method(LLVMContext.Ref)
dump = Type.method(Void)
print_ = Type.method(Void, raw_ostream.Ref)
print_.realname = 'print'
getContext = Method(ref(LLVMContext))
dump = Method()
print_ = Method(Void, ref(raw_ostream))
print_.realname = 'print'
def type_checker():
return Type.method(Bool.To(bool))
def type_checker():
return Method(cast(Bool, bool))
isVoidTy = type_checker()
isHalfTy = type_checker()
isFloatTy = type_checker()
isDoubleTy = type_checker()
isX86_FP80Ty = type_checker()
isFP128Ty = type_checker()
isPPC_FP128Ty = type_checker()
isFloatingPointTy = type_checker()
isX86_MMXTy = type_checker()
isFPOrFPVectorTy = type_checker()
isLabelTy = type_checker()
isMetadataTy = type_checker()
isIntOrIntVectorTy = type_checker()
isFunctionTy = type_checker()
isStructTy = type_checker()
isArrayTy = type_checker()
isPointerTy = type_checker()
isPtrOrPtrVectorTy = type_checker()
isVectorTy = type_checker()
isEmptyTy = type_checker()
isPrimitiveType = type_checker()
isDerivedType = type_checker()
isFirstClassType = type_checker()
isSingleValueType = type_checker()
isAggregateType = type_checker()
isSized = type_checker()
isVoidTy = type_checker()
isHalfTy = type_checker()
isFloatTy = type_checker()
isDoubleTy = type_checker()
isX86_FP80Ty = type_checker()
isFP128Ty = type_checker()
isPPC_FP128Ty = type_checker()
isFloatingPointTy = type_checker()
isX86_MMXTy = type_checker()
isFPOrFPVectorTy = type_checker()
isLabelTy = type_checker()
isMetadataTy = type_checker()
isIntOrIntVectorTy = type_checker()
isFunctionTy = type_checker()
isStructTy = type_checker()
isArrayTy = type_checker()
isPointerTy = type_checker()
isPtrOrPtrVectorTy = type_checker()
isVectorTy = type_checker()
isEmptyTy = type_checker()
isPrimitiveType = type_checker()
isDerivedType = type_checker()
isFirstClassType = type_checker()
isSingleValueType = type_checker()
isAggregateType = type_checker()
isSized = type_checker()
isIntegerTy = Type.multimethod([Bool.To(bool)],
[Bool.To(bool), Unsigned.From(int)])
isIntegerTy = Method(cast(Bool, bool))
isIntegerTy |= Method(cast(Bool, bool), cast(int, Unsigned))
def type_factory():
return Type.staticmethod(Type.Pointer, LLVMContext.Ref)
def type_factory():
return StaticMethod(ptr(Type), ref(LLVMContext))
getVoidTy = type_factory()
getLabelTy = type_factory()
getHalfTy = type_factory()
getFloatTy = type_factory()
getDoubleTy = type_factory()
getMetadataTy = type_factory()
getX86_FP80Ty = type_factory()
getFP128Ty = type_factory()
getPPC_FP128Ty = type_factory()
getX86_MMXTy = type_factory()
getVoidTy = type_factory()
getLabelTy = type_factory()
getHalfTy = type_factory()
getFloatTy = type_factory()
getDoubleTy = type_factory()
getMetadataTy = type_factory()
getX86_FP80Ty = type_factory()
getFP128Ty = type_factory()
getPPC_FP128Ty = type_factory()
getX86_MMXTy = type_factory()
getIntNTy = Type.staticmethod(IntegerType.Pointer, LLVMContext.Ref, Unsigned.From(int))
getIntNTy = StaticMethod(ptr(IntegerType), ref(LLVMContext), cast(Unsigned, int))
def integer_factory():
return Type.staticmethod(IntegerType.Pointer, LLVMContext.Ref)
def integer_factory():
return StaticMethod(ptr(IntegerType), ref(LLVMContext))
getInt1Ty = integer_factory()
getInt8Ty = integer_factory()
getInt16Ty = integer_factory()
getInt32Ty = integer_factory()
getInt64Ty = integer_factory()
getInt1Ty = integer_factory()
getInt8Ty = integer_factory()
getInt16Ty = integer_factory()
getInt32Ty = integer_factory()
getInt64Ty = integer_factory()
def pointer_factory():
return Type.staticmethod(PointerType.Pointer, LLVMContext.Ref)
def pointer_factory():
return StaticMethod(ptr(PointerType), ref(LLVMContext))
getHalfPtrTy = pointer_factory()
getFloatPtrTy = pointer_factory()
getDoublePtrTy = pointer_factory()
getX86_FP80PtrTy = pointer_factory()
getFP128PtrTy = pointer_factory()
getPPC_FP128PtrTy = pointer_factory()
getX86_MMXPtrTy = pointer_factory()
getInt1PtrTy = pointer_factory()
getInt8PtrTy = pointer_factory()
getInt16PtrTy = pointer_factory()
getInt32PtrTy = pointer_factory()
getInt64PtrTy = pointer_factory()
getIntNPtrTy = Type.staticmethod(PointerType.Pointer,
LLVMContext.Ref, Unsigned.From(int))
getHalfPtrTy = pointer_factory()
getFloatPtrTy = pointer_factory()
getDoublePtrTy = pointer_factory()
getX86_FP80PtrTy = pointer_factory()
getFP128PtrTy = pointer_factory()
getPPC_FP128PtrTy = pointer_factory()
getX86_MMXPtrTy = pointer_factory()
getInt1PtrTy = pointer_factory()
getInt8PtrTy = pointer_factory()
getInt16PtrTy = pointer_factory()
getInt32PtrTy = pointer_factory()
getInt64PtrTy = pointer_factory()
getIntNPtrTy = StaticMethod(ptr(PointerType),
ref(LLVMContext), cast(int, Unsigned))
@IntegerType
class IntegerType:
pass
@CompositeType
class CompositeType:
pass
@SequentialType
class SequentialType:
pass
@PointerType
class PointerType:
pass

View file

@ -2,4 +2,7 @@ from binding import *
from namespace import llvm
from Value import Value
User = Value.Subclass()
@llvm.Class(Value)
class User:
pass

View file

@ -5,20 +5,23 @@ from AssemblyAnnotationWriter import AssemblyAnnotationWriter
from Type import Type
from LLVMContext import LLVMContext
from StringRef import StringRef
#
Value = llvm.Class()
dump = Value.method(Void)
@Value
class Value:
print_ = Value.method(Void, raw_ostream.Ref, AssemblyAnnotationWriter.Pointer)
print_.realname = 'print'
dump = Method()
getType = Value.method(Type.Pointer)
getContext = Value.method(LLVMContext.Ref)
print_ = Method(Void, ref(raw_ostream), ptr(AssemblyAnnotationWriter))
print_.realname = 'print'
hasName = Value.method(Bool.To(bool))
# skip getValueName, setValueName
getName = Value.method(StringRef.To(str))
setName = Value.method(Void, StringRef.From(str))
getType = Method(ptr(Type))
getContext = Method(ref(LLVMContext))
replaceAllUsesWith = Value.method(Void, Value.Pointer)
hasName = Method(cast(Bool, bool))
# skip getValueName, setValueName
getName = Method(cast(StringRef, str))
setName = Method(Void, cast(str, StringRef))
replaceAllUsesWith = Method(Void, ptr(Value))

View file

@ -0,0 +1,2 @@
from . import Module

View file

@ -1,4 +1,3 @@
from binding import *
extra = Namespace('llvm_extra')
llvm = Namespace('llvm')

View file

@ -3,10 +3,15 @@ from namespace import llvm
from LLVMContext import LLVMContext
from StringRef import StringRef
raw_ostream = llvm.Class()
raw_ostream.include.add("llvm/Support/raw_ostream.h")
delete = raw_ostream.delete()
@llvm.Class()
class raw_ostream:
_include_ = "llvm/Support/raw_ostream.h"
delete = Destructor()
@llvm.Class(raw_ostream)
class raw_svector_ostream:
_include_ = "llvm/Support/raw_os_ostream.h"
_base_ = raw_ostream
str = Method(cast(str, StringRef))
raw_svector_ostream = raw_ostream.Subclass()
raw_svector_ostream.include.add("llvm/Support/raw_os_ostream.h")
str = raw_svector_ostream.method(StringRef.To(str))