binding compiles with llvm 3.3
This commit is contained in:
parent
2338eae5f6
commit
4c1b9016fb
22 changed files with 324 additions and 119 deletions
|
|
@ -247,7 +247,8 @@ class Class(SubModule, _Type):
|
|||
def __call__(self, defn):
|
||||
assert not self._is_defined
|
||||
# process the definition in "defn"
|
||||
self.name = defn.__name__
|
||||
self.name = getattr(defn, '_name_', defn.__name__)
|
||||
|
||||
for k, v in defn.__dict__.items():
|
||||
if isinstance(v, Method):
|
||||
self.methods.append(v)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,22 @@
|
|||
#include <Python.h>
|
||||
#include <llvm/ADT/SmallVector.h>
|
||||
#include <llvm/Value.h>
|
||||
#include <llvm/DerivedTypes.h>
|
||||
#include <llvm/Function.h>
|
||||
#if LLVM_VERSION_MAJOR >= 3 and LLVM_VERSION_MINOR >= 3
|
||||
#include <llvm/IR/Value.h>
|
||||
#include <llvm/IR/DerivedTypes.h>
|
||||
#include <llvm/IR/Function.h>
|
||||
#include <llvm/IR/Module.h>
|
||||
#include <llvm/IR/Constants.h>
|
||||
#include <llvm/IR/Intrinsics.h>
|
||||
#include <llvm/IR/IRBuilder.h>
|
||||
#else
|
||||
#include <llvm/Value.h>
|
||||
#include <llvm/DerivedTypes.h>
|
||||
#include <llvm/Function.h>
|
||||
#include <llvm/Module.h>
|
||||
#include <llvm/Constants.h>
|
||||
#include <llvm/Intrinsics.h>
|
||||
#include <llvm/IRBuilder.h>
|
||||
#endif
|
||||
#include <llvm/Support/raw_ostream.h>
|
||||
#include <llvm/Support/FormattedStream.h>
|
||||
#include <llvm/Support/MemoryBuffer.h>
|
||||
|
|
@ -12,11 +26,7 @@
|
|||
#include <llvm/ExecutionEngine/ExecutionEngine.h>
|
||||
#include <llvm/ExecutionEngine/GenericValue.h>
|
||||
#include <llvm/Linker.h>
|
||||
#include <llvm/Module.h>
|
||||
#include <llvm/Analysis/Verifier.h>
|
||||
#include <llvm/Constants.h>
|
||||
#include <llvm/Intrinsics.h>
|
||||
#include <llvm/IRBuilder.h>
|
||||
#include <llvm/PassRegistry.h>
|
||||
#include <llvm/Support/Host.h>
|
||||
|
||||
|
|
@ -56,6 +66,15 @@ namespace extra{
|
|||
|
||||
}
|
||||
|
||||
static
|
||||
PyObject* callwrite(PyObject* self, PyObject* arg)
|
||||
{
|
||||
char meth[] = "method";
|
||||
char fmt[] = "O";
|
||||
return PyObject_CallMethod(self, meth, fmt, arg);
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
PyObject* make_raw_ostream_for_printing(PyObject* self, PyObject* args)
|
||||
{
|
||||
|
|
@ -271,7 +290,7 @@ llvm::ExecutionEngine* ExecutionEngine_create(
|
|||
&ErrorStr, OptLevel,
|
||||
GVsWithCode);
|
||||
auto_pyobject buf = PyBytes_FromString(ErrorStr.c_str());
|
||||
if (errout && NULL == PyObject_CallMethod(errout, "write", "O", *buf)){
|
||||
if (errout && NULL == callwrite(errout, *buf)){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -298,7 +317,7 @@ llvm::ExecutionEngine* ExecutionEngine_createJIT(
|
|||
ExecutionEngine *ee = ExecutionEngine::createJIT(M, &ErrorStr, JMM, OL,
|
||||
GCsWithCode, RM, CMM);
|
||||
auto_pyobject buf = PyBytes_FromString(ErrorStr.c_str());
|
||||
if (errout && NULL == PyObject_CallMethod(errout, "write", "O", *buf)){
|
||||
if (errout && NULL == callwrite(errout, *buf)){
|
||||
return NULL;
|
||||
}
|
||||
// PyFile_WriteString(ErrorStr.c_str(), errout);
|
||||
|
|
@ -483,7 +502,7 @@ PyObject* llvm_ParseBitCodeFile(llvm::StringRef Buf, llvm::LLVMContext& Ctx,
|
|||
std::string ErrStr;
|
||||
M = ParseBitcodeFile(MB, Ctx, &ErrStr);
|
||||
auto_pyobject buf = PyBytes_FromString(ErrStr.c_str());
|
||||
if (NULL == PyObject_CallMethod(FObj, "write", "O", *buf)){
|
||||
if (NULL == callwrite(FObj, *buf)){
|
||||
return NULL;
|
||||
}
|
||||
// if (-1 == PyFile_WriteString(ErrStr.c_str(), FObj)) {
|
||||
|
|
@ -507,7 +526,7 @@ PyObject* llvm_WriteBitcodeToFile(const llvm::Module *M, PyObject* FObj)
|
|||
rso.flush();
|
||||
StringRef ref = rso.str();
|
||||
auto_pyobject buf = PyBytes_FromStringAndSize(ref.data(), ref.size());
|
||||
return PyObject_CallMethod(FObj, "write", "O", *buf);
|
||||
return callwrite(FObj, *buf);
|
||||
}
|
||||
|
||||
static
|
||||
|
|
@ -522,7 +541,7 @@ PyObject* llvm_getBitcodeTargetTriple(llvm::StringRef Buf,
|
|||
std::string ErrStr;
|
||||
Triple = getBitcodeTargetTriple(MB, Ctx, &ErrStr);
|
||||
auto_pyobject buf = PyBytes_FromString(ErrStr.c_str());
|
||||
if (NULL == PyObject_CallMethod(FObj, "write", "O", *buf)){
|
||||
if (NULL == callwrite(FObj, *buf)){
|
||||
return NULL;
|
||||
}
|
||||
// if (-1 == PyFile_WriteString(ErrStr.c_str(), FObj)) {
|
||||
|
|
@ -594,19 +613,19 @@ PyObject* Linker_LinkInModule(llvm::Linker* Linker,
|
|||
PyObject* ErrMsg)
|
||||
{
|
||||
std::string errmsg;
|
||||
#if LLVM_VERSION_MAJOR >= 3 && LLVM_VERSION_MINOR >= 3
|
||||
bool failed = Linker->linkInModule(Mod, &errmsg);
|
||||
#else
|
||||
bool failed = Linker->LinkInModule(Mod, &errmsg);
|
||||
#endif
|
||||
if (! failed) {
|
||||
Py_RETURN_FALSE;
|
||||
} else {
|
||||
|
||||
auto_pyobject buf = PyBytes_FromString(errmsg.c_str());
|
||||
if (NULL == PyObject_CallMethod(ErrMsg, "write", "O", *buf)){
|
||||
if (NULL == callwrite(ErrMsg, *buf)){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// if (-1 == PyFile_WriteString(errmsg.c_str(), ErrMsg)) {
|
||||
// return NULL;
|
||||
// }
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
}
|
||||
|
|
@ -623,7 +642,7 @@ PyObject* Linker_LinkModules(llvm::Module* Dest,
|
|||
Py_RETURN_FALSE;
|
||||
} else {
|
||||
auto_pyobject buf = PyBytes_FromString(errmsg.c_str());
|
||||
if (NULL == PyObject_CallMethod(ErrMsg, "write", "O", *buf)){
|
||||
if (NULL == callwrite(ErrMsg, *buf)){
|
||||
return NULL;
|
||||
}
|
||||
// if (-1 == PyFile_WriteString(errmsg.c_str(), ErrMsg)) {
|
||||
|
|
@ -689,7 +708,7 @@ PyObject* llvm_verifyModule(const llvm::Module& Fn,
|
|||
|
||||
if (failed) {
|
||||
auto_pyobject buf = PyBytes_FromString(errmsg.c_str());
|
||||
if (NULL == PyObject_CallMethod(ErrMsg, "write", "O", *buf)){
|
||||
if (NULL == callwrite(ErrMsg, *buf)){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -819,7 +838,7 @@ PyObject* DynamicLibrary_LoadLibraryPermanently(const char * Filename,
|
|||
failed = DynamicLibrary::LoadLibraryPermanently(Filename, &errmsg);
|
||||
if (failed) {
|
||||
auto_pyobject buf = PyBytes_FromString(errmsg.c_str());
|
||||
if (NULL == PyObject_CallMethod(ErrMsg, "write", "O", *buf)){
|
||||
if (NULL == callwrite(ErrMsg, *buf)){
|
||||
return NULL;
|
||||
}
|
||||
// if (-1 == PyFile_WriteString(errmsg.c_str(), ErrMsg)) {
|
||||
|
|
@ -869,7 +888,7 @@ PyObject* TargetRegistry_lookupTarget(const std::string &Triple,
|
|||
if (!target) {
|
||||
// PyFile_WriteString(error.c_str(), Error);
|
||||
auto_pyobject buf = PyBytes_FromString(error.c_str());
|
||||
if (NULL == PyObject_CallMethod(Error, "write", "O", *buf)){
|
||||
if (NULL == callwrite(Error, *buf)){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -891,7 +910,7 @@ PyObject* TargetRegistry_lookupTarget(const std::string &Arch,
|
|||
if (!target) {
|
||||
// PyFile_WriteString(error.c_str(), Error);
|
||||
auto_pyobject buf = PyBytes_FromString(error.c_str());
|
||||
if (NULL == PyObject_CallMethod(Error, "write", "O", *buf)){
|
||||
if (NULL == callwrite(Error, *buf)){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -910,7 +929,7 @@ PyObject* TargetRegistry_getClosestTargetForJIT(PyObject* Error)
|
|||
const Target* target = TargetRegistry::getClosestTargetForJIT(error);
|
||||
if (!target) {
|
||||
auto_pyobject buf = PyBytes_FromString(error.c_str());
|
||||
if (NULL == PyObject_CallMethod(Error, "write", "O", *buf)){
|
||||
if (NULL == callwrite(Error, *buf)){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -945,3 +964,21 @@ PyObject* llvm_sys_getHostCPUFeatures(PyObject* Features)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
PyObject* llvm_sys_isLittleEndianHost()
|
||||
{
|
||||
if (llvm::sys::IsLittleEndianHost)
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static
|
||||
PyObject* llvm_sys_isBigEndianHost()
|
||||
{
|
||||
if (llvm::sys::IsBigEndianHost)
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
|
@ -1,16 +1,27 @@
|
|||
from binding import *
|
||||
from .namespace import llvm
|
||||
from .Value import Argument, Value
|
||||
from .Attributes import Attributes
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
from .Attributes import AttributeSet, Attribute
|
||||
else:
|
||||
from .Attributes import Attributes
|
||||
|
||||
@Argument
|
||||
class Argument:
|
||||
_include_ = 'llvm/Argument.h'
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
_include_ = 'llvm/IR/Argument.h'
|
||||
else:
|
||||
_include_ = 'llvm/Argument.h'
|
||||
|
||||
_downcast_ = Value
|
||||
|
||||
addAttr = Method(Void, ref(Attributes))
|
||||
removeAttr = Method(Void, ref(Attributes))
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
addAttr = Method(Void, ref(AttributeSet))
|
||||
removeAttr = Method(Void, ref(AttributeSet))
|
||||
else:
|
||||
addAttr = Method(Void, ref(Attributes))
|
||||
removeAttr = Method(Void, ref(Attributes))
|
||||
|
||||
getParamAlignment = Method(cast(Unsigned, int))
|
||||
|
||||
getArgNo = Method(cast(Unsigned, int))
|
||||
|
|
|
|||
|
|
@ -2,38 +2,91 @@ from binding import *
|
|||
from .namespace import llvm
|
||||
from .LLVMContext import LLVMContext
|
||||
|
||||
llvm.includes.add('llvm/Attributes.h')
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
llvm.includes.add('llvm/IR/Attributes.h')
|
||||
else:
|
||||
llvm.includes.add('llvm/Attributes.h')
|
||||
|
||||
|
||||
Attributes = llvm.Class()
|
||||
AttrBuilder = llvm.Class()
|
||||
|
||||
|
||||
@Attributes
|
||||
class Attributes:
|
||||
AttrVal = Enum('''None, AddressSafety, Alignment, AlwaysInline,
|
||||
ByVal, InlineHint, InReg, MinSize,
|
||||
Naked, Nest, NoAlias, NoCapture,
|
||||
NoImplicitFloat, NoInline, NonLazyBind, NoRedZone,
|
||||
NoReturn, NoUnwind, OptimizeForSize, ReadNone,
|
||||
ReadOnly, ReturnsTwice, SExt, StackAlignment,
|
||||
StackProtect, StackProtectReq, StructRet, UWTable, ZExt''')
|
||||
|
||||
delete = Destructor()
|
||||
|
||||
get = StaticMethod(Attributes, ref(LLVMContext), ref(AttrBuilder))
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
Attribute = llvm.Class()
|
||||
AttributeSet = llvm.Class()
|
||||
else:
|
||||
Attributes = llvm.Class()
|
||||
|
||||
|
||||
@AttrBuilder
|
||||
class AttrBuilder:
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
@Attribute
|
||||
class Attribute:
|
||||
AttrKind = Enum('''None, Alignment, AlwaysInline,
|
||||
ByVal, InlineHint, InReg,
|
||||
MinSize, Naked, Nest, NoAlias,
|
||||
NoBuiltin, NoCapture, NoDuplicate, NoImplicitFloat,
|
||||
NoInline, NonLazyBind, NoRedZone, NoReturn,
|
||||
NoUnwind, OptimizeForSize, ReadNone, ReadOnly,
|
||||
Returned, ReturnsTwice, SExt, StackAlignment,
|
||||
StackProtect, StackProtectReq, StackProtectStrong, StructRet,
|
||||
SanitizeAddress, SanitizeThread, SanitizeMemory, UWTable,
|
||||
ZExt, EndAttrKinds''')
|
||||
|
||||
new = Constructor()
|
||||
delete = Destructor()
|
||||
delete = Destructor()
|
||||
|
||||
clear = Method()
|
||||
get = StaticMethod(Attribute,
|
||||
ref(LLVMContext),
|
||||
AttrKind,
|
||||
cast(int, Uint64)).require_only(2)
|
||||
|
||||
addAttribute = Method(ref(AttrBuilder), Attributes.AttrVal)
|
||||
removeAttribute = Method(ref(AttrBuilder), Attributes.AttrVal)
|
||||
@AttrBuilder
|
||||
class AttrBuilder:
|
||||
|
||||
addAlignmentAttr = Method(ref(AttrBuilder), cast(int, Unsigned))
|
||||
new = Constructor()
|
||||
delete = Destructor()
|
||||
|
||||
clear = Method()
|
||||
|
||||
addAttribute = Method(ref(AttrBuilder), Attribute.AttrKind)
|
||||
removeAttribute = Method(ref(AttrBuilder), Attribute.AttrKind)
|
||||
|
||||
addAlignmentAttr = Method(ref(AttrBuilder), cast(int, Unsigned))
|
||||
|
||||
@AttributeSet
|
||||
class AttributeSet:
|
||||
delete = Destructor()
|
||||
|
||||
get = StaticMethod(AttributeSet,
|
||||
ref(LLVMContext),
|
||||
cast(int, Unsigned),
|
||||
ref(AttrBuilder))
|
||||
|
||||
else:
|
||||
@Attributes
|
||||
class Attributes:
|
||||
AttrVal = Enum('''None, AddressSafety, Alignment, AlwaysInline,
|
||||
ByVal, InlineHint, InReg, MinSize,
|
||||
Naked, Nest, NoAlias, NoCapture,
|
||||
NoImplicitFloat, NoInline, NonLazyBind, NoRedZone,
|
||||
NoReturn, NoUnwind, OptimizeForSize, ReadNone,
|
||||
ReadOnly, ReturnsTwice, SExt, StackAlignment,
|
||||
StackProtect, StackProtectReq, StructRet, UWTable, ZExt''')
|
||||
|
||||
delete = Destructor()
|
||||
|
||||
get = StaticMethod(Attributes, ref(LLVMContext), ref(AttrBuilder))
|
||||
|
||||
|
||||
@AttrBuilder
|
||||
class AttrBuilder:
|
||||
|
||||
new = Constructor()
|
||||
delete = Destructor()
|
||||
|
||||
clear = Method()
|
||||
|
||||
addAttribute = Method(ref(AttrBuilder), Attributes.AttrVal)
|
||||
removeAttribute = Method(ref(AttrBuilder), Attributes.AttrVal)
|
||||
|
||||
addAlignmentAttr = Method(ref(AttrBuilder), cast(int, Unsigned))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -124,17 +124,31 @@ class DIBuilder:
|
|||
ptr(MDNode), # TemplateParms = 0
|
||||
).require_only(10)
|
||||
|
||||
createStructType = Method(DIType,
|
||||
ref(DIDescriptor), # Scope
|
||||
stringref_arg, # Name
|
||||
ref(DIFile), # File
|
||||
unsigned_arg, # LineNumber
|
||||
uint64_arg, # SizeInBits
|
||||
uint64_arg, # AlignInBits
|
||||
unsigned_arg, # Flags
|
||||
ref(DIArray), # Elements
|
||||
unsigned_arg, # RunTimeLang = 0
|
||||
).require_only(8)
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
createStructType = Method(DIType,
|
||||
ref(DIDescriptor), # Scope
|
||||
stringref_arg, # Name
|
||||
ref(DIFile), # File
|
||||
unsigned_arg, # LineNumber
|
||||
uint64_arg, # SizeInBits
|
||||
uint64_arg, # AlignInBits
|
||||
unsigned_arg, # Flags
|
||||
ref(DIType), # DerivedFrom
|
||||
ref(DIArray), # Elements
|
||||
unsigned_arg, # RunTimeLang = 0
|
||||
).require_only(9)
|
||||
else:
|
||||
createStructType = Method(DIType,
|
||||
ref(DIDescriptor), # Scope
|
||||
stringref_arg, # Name
|
||||
ref(DIFile), # File
|
||||
unsigned_arg, # LineNumber
|
||||
uint64_arg, # SizeInBits
|
||||
uint64_arg, # AlignInBits
|
||||
unsigned_arg, # Flags
|
||||
ref(DIArray), # Elements
|
||||
unsigned_arg, # RunTimeLang = 0
|
||||
).require_only(8)
|
||||
|
||||
createUnionType = Method(DIType,
|
||||
ref(DIDescriptor), # Scope
|
||||
|
|
@ -186,7 +200,7 @@ class DIBuilder:
|
|||
ref(DIType), # Ty
|
||||
)
|
||||
|
||||
createTemporaryType = Method(DIType, ref(DIFile)).require_only(0)
|
||||
#createTemporaryType = Method(DIType, ref(DIFile)).require_only(0)
|
||||
|
||||
createForwardDecl = Method(DIType,
|
||||
unsigned_arg, # Tag
|
||||
|
|
|
|||
|
|
@ -15,7 +15,10 @@ from .GlobalVariable import GlobalVariable
|
|||
|
||||
@DataLayout
|
||||
class DataLayout:
|
||||
_include_ = 'llvm/DataLayout.h'
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
_include_ = 'llvm/IR/DataLayout.h'
|
||||
else:
|
||||
_include_ = 'llvm/DataLayout.h'
|
||||
|
||||
_new_string = Constructor(cast(str, StringRef))
|
||||
_new_module = Constructor(ptr(Module))
|
||||
|
|
|
|||
|
|
@ -8,7 +8,10 @@ FunctionType = llvm.Class(Type)
|
|||
|
||||
@FunctionType
|
||||
class FunctionType:
|
||||
_include_ = 'llvm/DerivedTypes.h'
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
_include_ = 'llvm/IR/DerivedTypes.h'
|
||||
else:
|
||||
_include_ = 'llvm/DerivedTypes.h'
|
||||
_downcast_ = Type
|
||||
|
||||
_get = StaticMethod(ptr(FunctionType), ptr(Type), cast(bool, Bool))
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@ from .Value import GlobalValue, Constant, Function, Argument, Value
|
|||
from .Module import Module
|
||||
from .BasicBlock import BasicBlock
|
||||
from .ValueSymbolTable import ValueSymbolTable
|
||||
from .Attributes import Attributes
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
from .Attributes import Attribute, AttributeSet
|
||||
else:
|
||||
from .Attributes import Attributes
|
||||
from .Type import Type
|
||||
from .DerivedTypes import FunctionType
|
||||
from .LLVMContext import LLVMContext
|
||||
|
|
@ -12,7 +15,11 @@ from .CallingConv import CallingConv
|
|||
|
||||
@Function
|
||||
class Function:
|
||||
_include_ = 'llvm/Function.h'
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
_include_ = 'llvm/IR/Function.h'
|
||||
else:
|
||||
_include_ = 'llvm/Function.h'
|
||||
|
||||
_downcast_ = GlobalValue, Constant, Value
|
||||
|
||||
getReturnType = Method(ptr(Type))
|
||||
|
|
@ -48,10 +55,17 @@ class Function:
|
|||
|
||||
deleteBody = Method()
|
||||
viewCFG = Method()
|
||||
|
||||
viewCFGOnly = Method()
|
||||
|
||||
addFnAttr = Method(Void, Attributes.AttrVal)
|
||||
removeFnAttr = Method(Void, ref(Attributes))
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
addFnAttr = Method(Void, Attribute.AttrKind)
|
||||
addAttributes = Method(Void, cast(int, Unsigned), ref(AttributeSet))
|
||||
removeAttributes = Method(Void, cast(int, Unsigned), ref(AttributeSet))
|
||||
#removeFnAttr = Method(Void, Attribute.AttrKind) # 3.4?
|
||||
else:
|
||||
addFnAttr = Method(Void, Attributes.AttrVal)
|
||||
removeFnAttr = Method(Void, ref(Attributes))
|
||||
#hasFnAttribute = Method(cast(Bool, bool), Attributes.AttrVal)
|
||||
|
||||
Create = StaticMethod(ptr(Function),
|
||||
|
|
|
|||
|
|
@ -6,7 +6,10 @@ from .ADT.StringRef import StringRef
|
|||
|
||||
@GlobalValue
|
||||
class GlobalValue:
|
||||
_include_ = 'llvm/GlobalValue.h'
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
_include_ = 'llvm/IR/GlobalValue.h'
|
||||
else:
|
||||
_include_ = 'llvm/GlobalValue.h'
|
||||
|
||||
LinkageTypes = Enum('''
|
||||
ExternalLinkage, AvailableExternallyLinkage, LinkOnceAnyLinkage,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,11 @@ IRBuilder = llvm.Class()
|
|||
|
||||
@IRBuilder
|
||||
class IRBuilder:
|
||||
_include_ = 'llvm/IRBuilder.h'
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
_include_ = 'llvm/IR/IRBuilder.h'
|
||||
else:
|
||||
_include_ = 'llvm/IRBuilder.h'
|
||||
|
||||
_realname_ = 'IRBuilder<>'
|
||||
|
||||
new = Constructor(ref(LLVMContext))
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@ from .Value import Value
|
|||
from .DerivedTypes import FunctionType
|
||||
from .ADT.StringRef import StringRef
|
||||
|
||||
llvm.includes.add('llvm/InlineAsm.h')
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
llvm.includes.add('llvm/IR/InlineAsm.h')
|
||||
else:
|
||||
llvm.includes.add('llvm/InlineAsm.h')
|
||||
|
||||
InlineAsm = llvm.Class(Value)
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,10 @@ SynchronizationScope = llvm.Enum('SynchronizationScope',
|
|||
|
||||
from .ADT.StringRef import StringRef
|
||||
from .CallingConv import CallingConv
|
||||
from .Attributes import Attributes
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
from .Attributes import AttributeSet, Attribute
|
||||
else:
|
||||
from .Attributes import Attributes
|
||||
from .Type import Type
|
||||
|
||||
|
||||
|
|
@ -142,8 +145,12 @@ class CallInst:
|
|||
getCallingConv = Method(CallingConv.ID)
|
||||
setCallingConv = Method(Void, CallingConv.ID)
|
||||
getParamAlignment = Method(cast(Unsigned, int), cast(int, Unsigned))
|
||||
addAttribute = Method(Void, cast(int, Unsigned), ref(Attributes))
|
||||
removeAttribute = Method(Void, cast(int, Unsigned), ref(Attributes))
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
addAttribute = Method(Void, cast(int, Unsigned), Attribute.AttrKind)
|
||||
removeAttribute = Method(Void, cast(int, Unsigned), ref(Attribute))
|
||||
else:
|
||||
addAttribute = Method(Void, cast(int, Unsigned), ref(Attributes))
|
||||
removeAttribute = Method(Void, cast(int, Unsigned), ref(Attributes))
|
||||
getCalledFunction = Method(ptr(Function))
|
||||
getCalledValue = Method(ptr(Value))
|
||||
setCalledFunction = Method(Void, ptr(Function))
|
||||
|
|
@ -264,7 +271,10 @@ class UnaryInstruction:
|
|||
|
||||
@IntrinsicInst
|
||||
class IntrinsicInst:
|
||||
_include_ = 'llvm/IntrinsicInst.h'
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
_include_ = 'llvm/IR/IntrinsicInst.h'
|
||||
else:
|
||||
_include_ = 'llvm/IntrinsicInst.h'
|
||||
_downcast_ = Value, User, Instruction
|
||||
|
||||
#compare
|
||||
|
|
@ -292,8 +302,12 @@ class InvokeInst:
|
|||
getCallingConv = Method(CallingConv.ID)
|
||||
setCallingConv = Method(Void, CallingConv.ID)
|
||||
getParamAlignment = Method(cast(Unsigned, int), cast(int, Unsigned))
|
||||
addAttribute = Method(Void, cast(int, Unsigned), ref(Attributes))
|
||||
removeAttribute = Method(Void, cast(int, Unsigned), ref(Attributes))
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
addAttribute = Method(Void, cast(int, Unsigned), Attribute.AttrKind)
|
||||
removeAttribute = Method(Void, cast(int, Unsigned), ref(Attribute))
|
||||
else:
|
||||
addAttribute = Method(Void, cast(int, Unsigned), ref(Attributes))
|
||||
removeAttribute = Method(Void, cast(int, Unsigned), ref(Attributes))
|
||||
getCalledFunction = Method(ptr(Function))
|
||||
getCalledValue = Method(ptr(Value))
|
||||
setCalledFunction = Method(Void, ptr(Function))
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ from .namespace import llvm
|
|||
|
||||
@llvm.Class()
|
||||
class LLVMContext:
|
||||
_include_ = "llvm/LLVMContext.h"
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
_include_ = "llvm/IR/LLVMContext.h"
|
||||
else:
|
||||
_include_ = "llvm/LLVMContext.h"
|
||||
|
||||
llvm.Function('getGlobalContext', ref(LLVMContext))
|
||||
|
|
|
|||
|
|
@ -10,30 +10,33 @@ Linker = llvm.Class()
|
|||
|
||||
@Linker
|
||||
class Linker:
|
||||
ControlFlags = Enum('Verbose, QuietWarnings, QuietErrors')
|
||||
#ControlFlags = Enum('Verbose, QuietWarnings, QuietErrors')
|
||||
LinkerMode = Enum('DestroySource, PreserveSource')
|
||||
|
||||
_new_w_empty = Constructor(cast(str, StringRef),
|
||||
cast(str, StringRef),
|
||||
ref(LLVMContext),
|
||||
cast(int, Unsigned)).require_only(3)
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
new = Constructor(ptr(Module))
|
||||
else:
|
||||
_new_w_empty = Constructor(cast(str, StringRef),
|
||||
cast(str, StringRef),
|
||||
ref(LLVMContext),
|
||||
cast(int, Unsigned)).require_only(3)
|
||||
|
||||
_new_w_existing = Constructor(cast(str, StringRef),
|
||||
ptr(Module),
|
||||
cast(int, Unsigned)).require_only(2)
|
||||
_new_w_existing = Constructor(cast(str, StringRef),
|
||||
ptr(Module),
|
||||
cast(int, Unsigned)).require_only(2)
|
||||
|
||||
@CustomPythonStaticMethod
|
||||
def new(progname, module_or_name, *args):
|
||||
if isinstance(module_or_name, Module):
|
||||
return _new_w_existing(progname, module_or_name, *args)
|
||||
else:
|
||||
return _new_w_empty(progname, module_or_name, *args)
|
||||
@CustomPythonStaticMethod
|
||||
def new(progname, module_or_name, *args):
|
||||
if isinstance(module_or_name, Module):
|
||||
return _new_w_existing(progname, module_or_name, *args)
|
||||
else:
|
||||
return _new_w_empty(progname, module_or_name, *args)
|
||||
|
||||
delete = Destructor()
|
||||
|
||||
getModule = Method(ptr(Module))
|
||||
releaseModule = Method(ptr(Module))
|
||||
getLastError = Method(cast(ConstStdString, str))
|
||||
#releaseModule = Method(ptr(Module))
|
||||
#getLastError = Method(cast(ConstStdString, str))
|
||||
|
||||
LinkInModule = CustomMethod('Linker_LinkInModule',
|
||||
PyObjectPtr, # boolean
|
||||
|
|
|
|||
|
|
@ -16,7 +16,10 @@ from .Metadata import NamedMDNode
|
|||
|
||||
@Module
|
||||
class Module:
|
||||
_include_ = "llvm/Module.h"
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
_include_ = "llvm/IR/Module.h"
|
||||
else:
|
||||
_include_ = "llvm/Module.h"
|
||||
# Enumerators
|
||||
Endianness = Enum('AnyEndianness', 'LittleEndian', 'BigEndian')
|
||||
PointerSize = Enum('AnyPointerSize', 'Pointer32', 'Pointer64')
|
||||
|
|
|
|||
|
|
@ -1,18 +1,29 @@
|
|||
from binding import *
|
||||
from src.namespace import sys
|
||||
|
||||
isLittleEndianHost = sys.Function('isLittleEndianHost',
|
||||
cast(Bool, bool))
|
||||
|
||||
isBigEndianHost = sys.Function('isBigEndianHost',
|
||||
cast(Bool, bool))
|
||||
|
||||
getDefaultTargetTriple = sys.Function('getDefaultTargetTriple',
|
||||
cast(ConstStdString, str))
|
||||
|
||||
# llvm 3.3
|
||||
#getProcessTriple = sys.Function('getProcessTriple',
|
||||
# cast(ConstStdString, str))
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
getProcessTriple = sys.Function('getProcessTriple',
|
||||
cast(ConstStdString, str))
|
||||
|
||||
isLittleEndianHost = sys.CustomFunction('isLittleEndianHost',
|
||||
'llvm_sys_isLittleEndianHost',
|
||||
cast(Bool, bool))
|
||||
|
||||
isBigEndianHost = sys.CustomFunction('isBigEndianHost',
|
||||
'llvm_sys_isBigEndianHost',
|
||||
cast(Bool, bool))
|
||||
|
||||
else:
|
||||
|
||||
isLittleEndianHost = sys.Function('isLittleEndianHost',
|
||||
cast(Bool, bool))
|
||||
|
||||
isBigEndianHost = sys.Function('isBigEndianHost',
|
||||
cast(Bool, bool))
|
||||
|
||||
|
||||
getHostCPUName = sys.Function('getHostCPUName',
|
||||
cast(ConstStdString, str))
|
||||
|
|
|
|||
|
|
@ -8,8 +8,10 @@ from src.ADT.StringRef import StringRef
|
|||
from src.Support.CodeGen import CodeModel, TLSModel, CodeGenOpt, Reloc
|
||||
from src.GlobalValue import GlobalValue
|
||||
from src.DataLayout import DataLayout
|
||||
from src.TargetTransformInfo import (ScalarTargetTransformInfo,
|
||||
VectorTargetTransformInfo)
|
||||
|
||||
if LLVM_VERSION < (3, 3):
|
||||
from src.TargetTransformInfo import (ScalarTargetTransformInfo,
|
||||
VectorTargetTransformInfo)
|
||||
from src.PassManager import PassManagerBase
|
||||
from src.Support.FormattedStream import formatted_raw_ostream
|
||||
|
||||
|
|
@ -39,9 +41,11 @@ class TargetMachine:
|
|||
setMCUseDwarfDirectory = Method(Void, cast(bool, Bool))
|
||||
|
||||
getDataLayout = Method(const(ownedptr(DataLayout)))
|
||||
getScalarTargetTransformInfo = Method(const(
|
||||
|
||||
if LLVM_VERSION < (3, 3):
|
||||
getScalarTargetTransformInfo = Method(const(
|
||||
ownedptr(ScalarTargetTransformInfo)))
|
||||
getVectorTargetTransformInfo = Method(const(
|
||||
getVectorTargetTransformInfo = Method(const(
|
||||
ownedptr(VectorTargetTransformInfo)))
|
||||
|
||||
addPassesToEmitFile = Method(cast(bool, Bool),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ from binding import *
|
|||
from src.namespace import llvm
|
||||
from src.Pass import ImmutablePass
|
||||
|
||||
llvm.includes.add('llvm/TargetTransformInfo.h')
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
llvm.includes.add('llvm/Analysis/TargetTransformInfo.h')
|
||||
else:
|
||||
llvm.includes.add('llvm/TargetTransformInfo.h')
|
||||
|
||||
TargetTransformInfo = llvm.Class(ImmutablePass)
|
||||
ScalarTargetTransformInfo = llvm.Class()
|
||||
|
|
@ -11,14 +14,17 @@ VectorTargetTransformInfo = llvm.Class()
|
|||
|
||||
@ScalarTargetTransformInfo
|
||||
class ScalarTargetTransformInfo:
|
||||
delete = Destructor()
|
||||
if LLVM_VERSION < (3, 3):
|
||||
delete = Destructor()
|
||||
|
||||
@VectorTargetTransformInfo
|
||||
class VectorTargetTransformInfo:
|
||||
delete = Destructor()
|
||||
if LLVM_VERSION < (3, 3):
|
||||
delete = Destructor()
|
||||
|
||||
@TargetTransformInfo
|
||||
class TargetTransformInfo:
|
||||
new = Constructor(ptr(ScalarTargetTransformInfo),
|
||||
ptr(VectorTargetTransformInfo))
|
||||
if LLVM_VERSION < (3, 3):
|
||||
new = Constructor(ptr(ScalarTargetTransformInfo),
|
||||
ptr(VectorTargetTransformInfo))
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,11 @@ class PassManagerBuilder:
|
|||
DisableSimplifyLibCalls = _attr_bool()
|
||||
DisableUnitAtATime = _attr_bool()
|
||||
DisableUnrollLoops = _attr_bool()
|
||||
Vectorize = _attr_bool()
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
BBVectorize = _attr_bool()
|
||||
SLPVectorize = _attr_bool()
|
||||
else:
|
||||
Vectorize = _attr_bool()
|
||||
LoopVectorize = _attr_bool()
|
||||
|
||||
LibraryInfo = Attr(getter=ownedptr(TargetLibraryInfo),
|
||||
|
|
|
|||
|
|
@ -15,7 +15,10 @@ VectorType = llvm.Class(SequentialType)
|
|||
|
||||
@Type
|
||||
class Type:
|
||||
_include_ = 'llvm/Type.h'
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
_include_ = 'llvm/IR/Type.h'
|
||||
else:
|
||||
_include_ = 'llvm/Type.h'
|
||||
|
||||
TypeID = Enum('''
|
||||
VoidTyID, HalfTyID, FloatTyID, DoubleTyID,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@ from .ADT.StringRef import StringRef
|
|||
|
||||
@ValueSymbolTable
|
||||
class ValueSymbolTable:
|
||||
_include_ = 'llvm/ValueSymbolTable.h'
|
||||
if LLVM_VERSION >= (3, 3):
|
||||
_include_ = 'llvm/IR/ValueSymbolTable.h'
|
||||
else:
|
||||
_include_ = 'llvm/ValueSymbolTable.h'
|
||||
new = Constructor()
|
||||
delete = Destructor()
|
||||
lookup = Method(ptr(Value), cast(str, StringRef))
|
||||
|
|
|
|||
7
setup.py
7
setup.py
|
|
@ -61,7 +61,12 @@ def auto_intrinsic_gen(incdir):
|
|||
# let's do auto intrinsic generation
|
||||
print("Generate intrinsic IDs")
|
||||
from tools import intrgen
|
||||
path = "%s/llvm/Intrinsics.gen" % incdir
|
||||
|
||||
if llvm_version >= (3, 3):
|
||||
path = "%s/llvm/IR/Intrinsics.gen" % incdir
|
||||
else:
|
||||
path = "%s/llvm/Intrinsics.gen" % incdir
|
||||
|
||||
with open('llvm/_intrinsic_ids.py', 'w') as fout:
|
||||
intrgen.gen(path, fout)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue