Add custom binding to SmallVector<Type*>

This commit is contained in:
Siu Kwan Lam 2013-01-22 21:23:20 -06:00
commit 6b88ffbaed
5 changed files with 51 additions and 8 deletions

View file

@ -4,6 +4,8 @@
namespace llvm{
class Type; //forward declaration
class raw_svector_ostream_helper: public raw_svector_ostream {
SmallVectorImpl<char> *SV;
public:
@ -30,5 +32,25 @@ private:
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