Making progress towards a 3.0 version of llvm-py.
This commit is contained in:
parent
cb9fcd70cb
commit
c09903e54f
7 changed files with 16 additions and 65 deletions
24
llvm/_core.c
24
llvm/_core.c
|
|
@ -87,8 +87,6 @@ _wrap_obj2str(LLVMGetDataLayout, LLVMModuleRef)
|
||||||
_wrap_objstr2none(LLVMSetDataLayout, LLVMModuleRef)
|
_wrap_objstr2none(LLVMSetDataLayout, LLVMModuleRef)
|
||||||
_wrap_obj2str(LLVMGetTarget, LLVMModuleRef)
|
_wrap_obj2str(LLVMGetTarget, LLVMModuleRef)
|
||||||
_wrap_objstr2none(LLVMSetTarget, LLVMModuleRef)
|
_wrap_objstr2none(LLVMSetTarget, LLVMModuleRef)
|
||||||
_wrap_objstrobj2obj(LLVMAddTypeName, LLVMModuleRef, LLVMTypeRef, int)
|
|
||||||
_wrap_objstr2none(LLVMDeleteTypeName, LLVMModuleRef)
|
|
||||||
_wrap_objstr2obj(LLVMGetTypeByName, LLVMModuleRef, LLVMTypeRef)
|
_wrap_objstr2obj(LLVMGetTypeByName, LLVMModuleRef, LLVMTypeRef)
|
||||||
_wrap_obj2none(LLVMDumpModule, LLVMModuleRef)
|
_wrap_obj2none(LLVMDumpModule, LLVMModuleRef)
|
||||||
_wrap_obj2none(LLVMDisposeModule, LLVMModuleRef)
|
_wrap_obj2none(LLVMDisposeModule, LLVMModuleRef)
|
||||||
|
|
@ -189,8 +187,9 @@ _wLLVMLinkModules(PyObject *self, PyObject *args)
|
||||||
PyObject *dest_obj, *src_obj, *ret;
|
PyObject *dest_obj, *src_obj, *ret;
|
||||||
LLVMModuleRef dest, src;
|
LLVMModuleRef dest, src;
|
||||||
char *errmsg;
|
char *errmsg;
|
||||||
|
unsigned int mode = 0;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "OO", &dest_obj, &src_obj))
|
if (!PyArg_ParseTuple(args, "OO|I", &dest_obj, &src_obj, &mode))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
#ifdef LLVM_PY_USE_PYCAPSULE
|
#ifdef LLVM_PY_USE_PYCAPSULE
|
||||||
|
|
@ -201,7 +200,7 @@ _wLLVMLinkModules(PyObject *self, PyObject *args)
|
||||||
src = (LLVMModuleRef) PyCObject_AsVoidPtr(src_obj);
|
src = (LLVMModuleRef) PyCObject_AsVoidPtr(src_obj);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!LLVMLinkModules(dest, src, &errmsg)) {
|
if (!LLVMLinkModules(dest, src, mode, &errmsg)) {
|
||||||
if (errmsg) {
|
if (errmsg) {
|
||||||
ret = PyBytes_FromString(errmsg);
|
ret = PyBytes_FromString(errmsg);
|
||||||
LLVMDisposeMessage(errmsg);
|
LLVMDisposeMessage(errmsg);
|
||||||
|
|
@ -326,14 +325,14 @@ _wrap_obj2obj(LLVMGetVectorSize, LLVMTypeRef, int)
|
||||||
|
|
||||||
_wrap_none2obj(LLVMVoidType, LLVMTypeRef)
|
_wrap_none2obj(LLVMVoidType, LLVMTypeRef)
|
||||||
_wrap_none2obj(LLVMLabelType, LLVMTypeRef)
|
_wrap_none2obj(LLVMLabelType, LLVMTypeRef)
|
||||||
_wrap_none2obj(LLVMOpaqueType, LLVMTypeRef)
|
|
||||||
|
|
||||||
/*===-- Type handles -----------------------------------------------------===*/
|
/*===-- Type handles -----------------------------------------------------===*/
|
||||||
|
|
||||||
|
/*
|
||||||
_wrap_obj2obj(LLVMCreateTypeHandle, LLVMTypeRef, LLVMTypeHandleRef)
|
_wrap_obj2obj(LLVMCreateTypeHandle, LLVMTypeRef, LLVMTypeHandleRef)
|
||||||
_wrap_objobj2none(LLVMRefineType, LLVMTypeRef, LLVMTypeRef)
|
|
||||||
_wrap_obj2obj(LLVMResolveTypeHandle, LLVMTypeHandleRef, LLVMTypeRef)
|
_wrap_obj2obj(LLVMResolveTypeHandle, LLVMTypeHandleRef, LLVMTypeRef)
|
||||||
_wrap_obj2none(LLVMDisposeTypeHandle, LLVMTypeHandleRef)
|
_wrap_obj2none(LLVMDisposeTypeHandle, LLVMTypeHandleRef)
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*===----------------------------------------------------------------------===*/
|
/*===----------------------------------------------------------------------===*/
|
||||||
|
|
@ -706,7 +705,6 @@ _wLLVMBuildInvoke(PyObject *self, PyObject *args)
|
||||||
return ctor_LLVMValueRef(inst);
|
return ctor_LLVMValueRef(inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
_wrap_obj2obj(LLVMBuildUnwind, LLVMBuilderRef, LLVMValueRef)
|
|
||||||
_wrap_obj2obj(LLVMBuildUnreachable, LLVMBuilderRef, LLVMValueRef)
|
_wrap_obj2obj(LLVMBuildUnreachable, LLVMBuilderRef, LLVMValueRef)
|
||||||
|
|
||||||
/* Add a case to the switch instruction */
|
/* Add a case to the switch instruction */
|
||||||
|
|
@ -870,7 +868,6 @@ _wrap_pass( DeadArgElimination )
|
||||||
_wrap_pass( DeadCodeElimination )
|
_wrap_pass( DeadCodeElimination )
|
||||||
_wrap_pass( DeadInstElimination )
|
_wrap_pass( DeadInstElimination )
|
||||||
_wrap_pass( DeadStoreElimination )
|
_wrap_pass( DeadStoreElimination )
|
||||||
_wrap_pass( DeadTypeElimination )
|
|
||||||
_wrap_pass( DemoteRegisterToMemory )
|
_wrap_pass( DemoteRegisterToMemory )
|
||||||
_wrap_pass( DomOnlyPrinter )
|
_wrap_pass( DomOnlyPrinter )
|
||||||
_wrap_pass( DomOnlyViewer )
|
_wrap_pass( DomOnlyViewer )
|
||||||
|
|
@ -905,7 +902,6 @@ _wrap_pass( LoopStrengthReduce )
|
||||||
_wrap_pass( LoopUnroll )
|
_wrap_pass( LoopUnroll )
|
||||||
_wrap_pass( LoopUnswitch )
|
_wrap_pass( LoopUnswitch )
|
||||||
_wrap_pass( LowerInvoke )
|
_wrap_pass( LowerInvoke )
|
||||||
_wrap_pass( LowerSetJmp )
|
|
||||||
_wrap_pass( LowerSwitch )
|
_wrap_pass( LowerSwitch )
|
||||||
_wrap_pass( MemCpyOpt )
|
_wrap_pass( MemCpyOpt )
|
||||||
_wrap_pass( MergeFunctions )
|
_wrap_pass( MergeFunctions )
|
||||||
|
|
@ -1323,8 +1319,6 @@ static PyMethodDef core_methods[] = {
|
||||||
_method( LLVMSetDataLayout )
|
_method( LLVMSetDataLayout )
|
||||||
_method( LLVMGetTarget )
|
_method( LLVMGetTarget )
|
||||||
_method( LLVMSetTarget )
|
_method( LLVMSetTarget )
|
||||||
_method( LLVMAddTypeName )
|
|
||||||
_method( LLVMDeleteTypeName )
|
|
||||||
_method( LLVMGetTypeByName )
|
_method( LLVMGetTypeByName )
|
||||||
_method( LLVMDumpModule )
|
_method( LLVMDumpModule )
|
||||||
_method( LLVMDisposeModule )
|
_method( LLVMDisposeModule )
|
||||||
|
|
@ -1388,13 +1382,12 @@ static PyMethodDef core_methods[] = {
|
||||||
/* Other types */
|
/* Other types */
|
||||||
_method( LLVMVoidType )
|
_method( LLVMVoidType )
|
||||||
_method( LLVMLabelType )
|
_method( LLVMLabelType )
|
||||||
_method( LLVMOpaqueType )
|
|
||||||
|
|
||||||
/* Type handles */
|
/* Type handles */
|
||||||
_method( LLVMCreateTypeHandle )
|
/*
|
||||||
_method( LLVMRefineType )
|
|
||||||
_method( LLVMResolveTypeHandle )
|
_method( LLVMResolveTypeHandle )
|
||||||
_method( LLVMDisposeTypeHandle )
|
_method( LLVMDisposeTypeHandle )
|
||||||
|
*/
|
||||||
|
|
||||||
/* Values */
|
/* Values */
|
||||||
|
|
||||||
|
|
@ -1592,7 +1585,6 @@ static PyMethodDef core_methods[] = {
|
||||||
_method( LLVMBuildCondBr )
|
_method( LLVMBuildCondBr )
|
||||||
_method( LLVMBuildSwitch )
|
_method( LLVMBuildSwitch )
|
||||||
_method( LLVMBuildInvoke )
|
_method( LLVMBuildInvoke )
|
||||||
_method( LLVMBuildUnwind )
|
|
||||||
_method( LLVMBuildUnreachable )
|
_method( LLVMBuildUnreachable )
|
||||||
|
|
||||||
/* Add a case to the switch instruction */
|
/* Add a case to the switch instruction */
|
||||||
|
|
@ -1690,7 +1682,6 @@ static PyMethodDef core_methods[] = {
|
||||||
_pass( DeadCodeElimination )
|
_pass( DeadCodeElimination )
|
||||||
_pass( DeadInstElimination )
|
_pass( DeadInstElimination )
|
||||||
_pass( DeadStoreElimination )
|
_pass( DeadStoreElimination )
|
||||||
_pass( DeadTypeElimination )
|
|
||||||
_pass( DemoteRegisterToMemory )
|
_pass( DemoteRegisterToMemory )
|
||||||
_pass( DomOnlyPrinter )
|
_pass( DomOnlyPrinter )
|
||||||
_pass( DomOnlyViewer )
|
_pass( DomOnlyViewer )
|
||||||
|
|
@ -1725,7 +1716,6 @@ static PyMethodDef core_methods[] = {
|
||||||
_pass( LoopUnroll )
|
_pass( LoopUnroll )
|
||||||
_pass( LoopUnswitch )
|
_pass( LoopUnswitch )
|
||||||
_pass( LowerInvoke )
|
_pass( LowerInvoke )
|
||||||
_pass( LowerSetJmp )
|
|
||||||
_pass( LowerSwitch )
|
_pass( LowerSwitch )
|
||||||
_pass( MemCpyOpt )
|
_pass( MemCpyOpt )
|
||||||
_pass( MergeFunctions )
|
_pass( MergeFunctions )
|
||||||
|
|
|
||||||
38
llvm/core.py
38
llvm/core.py
|
|
@ -440,23 +440,6 @@ class Module(llvm.Ownable, llvm.Cacheable):
|
||||||
# Do not try to destroy the other module's llvm::Module*.
|
# Do not try to destroy the other module's llvm::Module*.
|
||||||
other._own(llvm.DummyOwner())
|
other._own(llvm.DummyOwner())
|
||||||
|
|
||||||
def add_type_name(self, name, ty):
|
|
||||||
"""Map a string to a type.
|
|
||||||
|
|
||||||
Similar to C's struct/typedef declarations. Returns True
|
|
||||||
if entry already existed (in which case nothing is changed),
|
|
||||||
False otherwise.
|
|
||||||
"""
|
|
||||||
check_is_type(ty)
|
|
||||||
return _core.LLVMAddTypeName(self.ptr, name, ty.ptr) != 0
|
|
||||||
|
|
||||||
def delete_type_name(self, name):
|
|
||||||
"""Removes a named type.
|
|
||||||
|
|
||||||
Undoes what add_type_name() does.
|
|
||||||
"""
|
|
||||||
_core.LLVMDeleteTypeName(self.ptr, name)
|
|
||||||
|
|
||||||
def get_type_named(self, name):
|
def get_type_named(self, name):
|
||||||
"""Return a Type object with the given name."""
|
"""Return a Type object with the given name."""
|
||||||
ptr = _core.LLVMGetTypeByName(self.ptr, name)
|
ptr = _core.LLVMGetTypeByName(self.ptr, name)
|
||||||
|
|
@ -650,13 +633,6 @@ class Type(object):
|
||||||
"""Create a label type."""
|
"""Create a label type."""
|
||||||
return _make_type(_core.LLVMLabelType(), TYPE_LABEL)
|
return _make_type(_core.LLVMLabelType(), TYPE_LABEL)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def opaque():
|
|
||||||
"""Create an opaque type.
|
|
||||||
|
|
||||||
Opaque types are used to create self-referencing types."""
|
|
||||||
return _make_type(_core.LLVMOpaqueType(), TYPE_OPAQUE)
|
|
||||||
|
|
||||||
def __init__(self, ptr, kind):
|
def __init__(self, ptr, kind):
|
||||||
"""DO NOT CALL DIRECTLY.
|
"""DO NOT CALL DIRECTLY.
|
||||||
|
|
||||||
|
|
@ -683,17 +659,6 @@ class Type(object):
|
||||||
def __ne__(self, rhs):
|
def __ne__(self, rhs):
|
||||||
return not self == rhs
|
return not self == rhs
|
||||||
|
|
||||||
def refine(self, dest):
|
|
||||||
"""Refine the abstract type represented by self into a concrete class.
|
|
||||||
|
|
||||||
This object is no longer valid after refining, so do not hold
|
|
||||||
references to it after calling. See the user guide for examples on how
|
|
||||||
to use this."""
|
|
||||||
|
|
||||||
check_is_type(dest)
|
|
||||||
_core.LLVMRefineType(self.ptr, dest.ptr)
|
|
||||||
self.ptr = None
|
|
||||||
|
|
||||||
|
|
||||||
class IntegerType(Type):
|
class IntegerType(Type):
|
||||||
"""Represents an integer type."""
|
"""Represents an integer type."""
|
||||||
|
|
@ -1656,9 +1621,6 @@ class Builder(object):
|
||||||
_core.LLVMBuildInvoke(self.ptr, func.ptr, args2,
|
_core.LLVMBuildInvoke(self.ptr, func.ptr, args2,
|
||||||
then_blk.ptr, catch_blk.ptr, name))
|
then_blk.ptr, catch_blk.ptr, name))
|
||||||
|
|
||||||
def unwind(self):
|
|
||||||
return _make_value(_core.LLVMBuildUnwind(self.ptr))
|
|
||||||
|
|
||||||
def unreachable(self):
|
def unreachable(self):
|
||||||
return _make_value(_core.LLVMBuildUnreachable(self.ptr))
|
return _make_value(_core.LLVMBuildUnreachable(self.ptr))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/GlobalVariable.h"
|
#include "llvm/GlobalVariable.h"
|
||||||
#include "llvm/TypeSymbolTable.h"
|
//#include "llvm/TypeSymbolTable.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Support/CallSite.h"
|
#include "llvm/Support/CallSite.h"
|
||||||
#include "llvm/IntrinsicInst.h"
|
#include "llvm/IntrinsicInst.h"
|
||||||
|
|
@ -330,7 +330,7 @@ LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef module, int id,
|
||||||
{
|
{
|
||||||
assert(types);
|
assert(types);
|
||||||
|
|
||||||
std::vector<const llvm::Type*> types_vec;
|
std::vector< llvm::ArrayRef<llvm::Type*> > types_vec;
|
||||||
unwrap_cvec(types, n_types, types_vec);
|
unwrap_cvec(types, n_types, types_vec);
|
||||||
|
|
||||||
llvm::Module *modulep = llvm::unwrap(module);
|
llvm::Module *modulep = llvm::unwrap(module);
|
||||||
|
|
@ -384,7 +384,8 @@ LLVMModuleRef LLVMGetModuleFromBitcode(const char *bitcode, unsigned bclen,
|
||||||
return wrap(modulep);
|
return wrap(modulep);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src, char **out)
|
unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src, unsigned int mode,
|
||||||
|
char **out)
|
||||||
{
|
{
|
||||||
llvm::Module *sourcep = llvm::unwrap(src);
|
llvm::Module *sourcep = llvm::unwrap(src);
|
||||||
assert(sourcep);
|
assert(sourcep);
|
||||||
|
|
@ -392,7 +393,7 @@ unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src, char **out)
|
||||||
assert(destinationp);
|
assert(destinationp);
|
||||||
|
|
||||||
std::string msg;
|
std::string msg;
|
||||||
if (llvm::Linker::LinkModules(destinationp, sourcep, &msg)) {
|
if (llvm::Linker::LinkModules(destinationp, sourcep, mode, &msg)) {
|
||||||
*out = strdup(msg.c_str());
|
*out = strdup(msg.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -544,8 +545,8 @@ define_pass( ScalarEvolutionAliasAnalysis )
|
||||||
//define_pass( SimplifyHalfPowrLibCalls )
|
//define_pass( SimplifyHalfPowrLibCalls )
|
||||||
define_pass( SingleLoopExtractor )
|
define_pass( SingleLoopExtractor )
|
||||||
define_pass( StripNonDebugSymbols )
|
define_pass( StripNonDebugSymbols )
|
||||||
define_pass( StructRetPromotion )
|
//define_pass( StructRetPromotion )
|
||||||
define_pass( TailDuplication )
|
//define_pass( TailDuplication )
|
||||||
define_pass( UnifyFunctionExitNodes )
|
define_pass( UnifyFunctionExitNodes )
|
||||||
|
|
||||||
/* we support only internalize(true) */
|
/* we support only internalize(true) */
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,8 @@ LLVMModuleRef LLVMGetModuleFromBitcode(const char *bc, unsigned bclen,
|
||||||
/* Wraps llvm::Linker::LinkModules(). Returns 0 on failure (with errmsg
|
/* Wraps llvm::Linker::LinkModules(). Returns 0 on failure (with errmsg
|
||||||
* filled in) and 1 on success. Dispose error message after use with
|
* filled in) and 1 on success. Dispose error message after use with
|
||||||
* LLVMDisposeMessage(). */
|
* LLVMDisposeMessage(). */
|
||||||
unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src, char **errmsg);
|
unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src,
|
||||||
|
unsigned int, char **errmsg);
|
||||||
|
|
||||||
/* Returns pointer to a heap-allocated block of `*len' bytes containing bit code
|
/* Returns pointer to a heap-allocated block of `*len' bytes containing bit code
|
||||||
* for the given module. NULL on error. */
|
* for the given module. NULL on error. */
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,6 @@ _pass_creator = {
|
||||||
PASS_LOOP_UNROLL : _core.LLVMAddLoopUnrollPass,
|
PASS_LOOP_UNROLL : _core.LLVMAddLoopUnrollPass,
|
||||||
PASS_LOOP_UNSWITCH : _core.LLVMAddLoopUnswitchPass,
|
PASS_LOOP_UNSWITCH : _core.LLVMAddLoopUnswitchPass,
|
||||||
PASS_LOWER_INVOKE : _core.LLVMAddLowerInvokePass,
|
PASS_LOWER_INVOKE : _core.LLVMAddLowerInvokePass,
|
||||||
PASS_LOWER_SET_JMP : _core.LLVMAddLowerSetJmpPass,
|
|
||||||
PASS_LOWER_SWITCH : _core.LLVMAddLowerSwitchPass,
|
PASS_LOWER_SWITCH : _core.LLVMAddLowerSwitchPass,
|
||||||
PASS_MEM_CPY_OPT : _core.LLVMAddMemCpyOptPass,
|
PASS_MEM_CPY_OPT : _core.LLVMAddMemCpyOptPass,
|
||||||
PASS_MERGE_FUNCTIONS : _core.LLVMAddMergeFunctionsPass,
|
PASS_MERGE_FUNCTIONS : _core.LLVMAddMergeFunctionsPass,
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,6 @@ PyObject * ctor_ ## typ ( typ p) \
|
||||||
_define_std_ctor(LLVMModuleRef)
|
_define_std_ctor(LLVMModuleRef)
|
||||||
_define_std_ctor(LLVMTypeRef)
|
_define_std_ctor(LLVMTypeRef)
|
||||||
_define_std_ctor(LLVMValueRef)
|
_define_std_ctor(LLVMValueRef)
|
||||||
_define_std_ctor(LLVMTypeHandleRef)
|
|
||||||
_define_std_ctor(LLVMBasicBlockRef)
|
_define_std_ctor(LLVMBasicBlockRef)
|
||||||
_define_std_ctor(LLVMBuilderRef)
|
_define_std_ctor(LLVMBuilderRef)
|
||||||
_define_std_ctor(LLVMMemoryBufferRef)
|
_define_std_ctor(LLVMMemoryBufferRef)
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,6 @@ PyObject * ctor_ ## typ ( typ p);
|
||||||
_declare_std_ctor(LLVMModuleRef)
|
_declare_std_ctor(LLVMModuleRef)
|
||||||
_declare_std_ctor(LLVMTypeRef)
|
_declare_std_ctor(LLVMTypeRef)
|
||||||
_declare_std_ctor(LLVMValueRef)
|
_declare_std_ctor(LLVMValueRef)
|
||||||
_declare_std_ctor(LLVMTypeHandleRef)
|
|
||||||
_declare_std_ctor(LLVMBasicBlockRef)
|
_declare_std_ctor(LLVMBasicBlockRef)
|
||||||
_declare_std_ctor(LLVMBuilderRef)
|
_declare_std_ctor(LLVMBuilderRef)
|
||||||
_declare_std_ctor(LLVMMemoryBufferRef)
|
_declare_std_ctor(LLVMMemoryBufferRef)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue