Add custom binding to SmallVector<Type*>
This commit is contained in:
parent
ce103975b8
commit
6b88ffbaed
5 changed files with 51 additions and 8 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
PYTHON = python
|
PYTHON = python
|
||||||
PYMODS = raw_ostream Type DerivedTypes LLVMContext StringRef AssemblyAnnotationWriter Module
|
|
||||||
|
PYMODS = raw_ostream SmallVector Type DerivedTypes StringRef
|
||||||
|
PYMODS += LLVMContext AssemblyAnnotationWriter Module
|
||||||
|
|
||||||
all: _api.so _capsule.so
|
all: _api.so _capsule.so
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,16 @@ Bool = BuiltinType('bool')
|
||||||
Unsigned = BuiltinType('unsigned')
|
Unsigned = BuiltinType('unsigned')
|
||||||
ConstStdString = BuiltinType('const std::string')
|
ConstStdString = BuiltinType('const std::string')
|
||||||
|
|
||||||
|
class PyObjectImpl(object):
|
||||||
|
name = 'PyObject*'
|
||||||
|
fullname = name
|
||||||
|
format = 'O'
|
||||||
|
|
||||||
|
def unwrap(self, println, var):
|
||||||
|
return var
|
||||||
|
|
||||||
|
PyObject = PyObjectImpl()
|
||||||
|
|
||||||
class Unwrapper(object):
|
class Unwrapper(object):
|
||||||
def __init__(self, cls, pytype):
|
def __init__(self, cls, pytype):
|
||||||
self.cls = cls
|
self.cls = cls
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
namespace llvm{
|
namespace llvm{
|
||||||
|
|
||||||
|
class Type; //forward declaration
|
||||||
|
|
||||||
class raw_svector_ostream_helper: public raw_svector_ostream {
|
class raw_svector_ostream_helper: public raw_svector_ostream {
|
||||||
SmallVectorImpl<char> *SV;
|
SmallVectorImpl<char> *SV;
|
||||||
public:
|
public:
|
||||||
|
|
@ -30,5 +32,25 @@ private:
|
||||||
void operator = (const raw_svector_ostream_helper&);
|
void operator = (const raw_svector_ostream_helper&);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
class SmallVector_Type : public SmallVector<Type*, 8> {
|
||||||
|
public:
|
||||||
|
static
|
||||||
|
SmallVector_Type* fromPySequence(PyObject* obj) {
|
||||||
|
SmallVector_Type* SV = new SmallVector_Type;
|
||||||
|
Py_ssize_t sz = PySequence_Size(obj);
|
||||||
|
for (Py_ssize_t i = 0; i < sz; ++i) {
|
||||||
|
PyObject* item = PySequence_GetItem(obj, i);
|
||||||
|
PyObject* cap = PyObject_GetAttrString(item, "_ptr");
|
||||||
|
Type* type = (Type*)PyCapsule_GetPointer(cap, "llvm::Type");
|
||||||
|
SV->push_back(type);
|
||||||
|
Py_XDECREF(cap);
|
||||||
|
Py_XDECREF(item);
|
||||||
|
}
|
||||||
|
return SV;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // end namespace llvm
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,17 @@ from binding import *
|
||||||
from namespace import llvm
|
from namespace import llvm
|
||||||
from LLVMContext import LLVMContext
|
from LLVMContext import LLVMContext
|
||||||
from Type import Type
|
from Type import Type
|
||||||
|
from SmallVector import SmallVector_Type
|
||||||
|
|
||||||
FunctionType = Type.Subclass()
|
FunctionType = Type.Subclass()
|
||||||
FunctionType.include.add('llvm/DerivedTypes.h')
|
FunctionType.include.add('llvm/DerivedTypes.h')
|
||||||
|
|
||||||
get = FunctionType.staticmultimethod([FunctionType.Pointer,
|
_get_signatures = [(FunctionType.Pointer,
|
||||||
Type.Pointer, Bool.From(bool)],)
|
Type.Pointer, Bool.From(bool)),
|
||||||
# (FunctionType.Pointer,
|
(FunctionType.Pointer,
|
||||||
# Type.Pointer, )])
|
Type.Pointer, SmallVector_Type.Ref, Bool.From(bool))]
|
||||||
|
|
||||||
|
get = FunctionType.staticmultimethod(*_get_signatures)
|
||||||
|
|
||||||
isVarArg = FunctionType.method(Bool.To(bool))
|
isVarArg = FunctionType.method(Bool.To(bool))
|
||||||
getReturnType = FunctionType.method(Type.Pointer)
|
getReturnType = FunctionType.method(Type.Pointer)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import api
|
import api
|
||||||
#api.capsule.set_debug(True)
|
api.capsule.set_debug(True)
|
||||||
context = api.getGlobalContext()
|
context = api.getGlobalContext()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -14,7 +14,6 @@ assert m.getPointerSize() == api.Module.PointerSize.AnyPointerSize
|
||||||
m.dump()
|
m.dump()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
os = api.raw_svector_ostream_helper.create()
|
os = api.raw_svector_ostream_helper.create()
|
||||||
m.print_(os, None)
|
m.print_(os, None)
|
||||||
print os.str()
|
print os.str()
|
||||||
|
|
@ -26,6 +25,13 @@ int1ty.dump()
|
||||||
print int1ty.isIntegerTy(1)
|
print int1ty.isIntegerTy(1)
|
||||||
|
|
||||||
fnty = api.FunctionType.get(int1ty, False)
|
fnty = api.FunctionType.get(int1ty, False)
|
||||||
|
fnty.dump()
|
||||||
|
print
|
||||||
|
|
||||||
|
types = [int1ty, api.Type.getIntNTy(context, 21)]
|
||||||
|
sv = api.SmallVector_Type.fromPySequence(types)
|
||||||
|
|
||||||
|
fnty = api.FunctionType.get(int1ty, sv, False)
|
||||||
|
|
||||||
os2 = api.raw_svector_ostream_helper.create()
|
os2 = api.raw_svector_ostream_helper.create()
|
||||||
fnty.print_(os2)
|
fnty.print_(os2)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue