45 lines
1.3 KiB
C
45 lines
1.3 KiB
C
#include <Python.h>
|
|
#include <llvm/ADT/SmallVector.h>
|
|
#include <llvm/Support/raw_ostream.h>
|
|
|
|
static
|
|
PyObject* make_raw_ostream_for_printing(PyObject* self, PyObject* args) {
|
|
using llvm::raw_svector_ostream_helper;
|
|
using llvm::raw_svector_ostream;
|
|
|
|
if (!PyArg_ParseTuple(args, "")) {
|
|
return NULL;
|
|
}
|
|
raw_svector_ostream* RSOH = raw_svector_ostream_helper::create();
|
|
return pycapsule_new(RSOH, "llvm::raw_ostream",
|
|
"llvm::raw_svector_ostream");
|
|
}
|
|
|
|
static
|
|
PyObject* make_small_vector_from_types(PyObject* self, PyObject* args) {
|
|
using llvm::Type;
|
|
using llvm::SmallVector_Type;
|
|
|
|
SmallVector_Type* SV = new SmallVector_Type;
|
|
Py_ssize_t size = PyTuple_Size(args);
|
|
for (Py_ssize_t i = 0; i < size; ++i) {
|
|
PyObject* cap = PyTuple_GetItem(args, i);
|
|
if (!cap) {
|
|
return NULL;
|
|
}
|
|
Type* type = (Type*)PyCapsule_GetPointer(cap, "llvm::Type");
|
|
if (!type) {
|
|
return NULL;
|
|
}
|
|
SV->push_back(type);
|
|
}
|
|
return pycapsule_new(SV, "llvm::SmallVector_Type");
|
|
}
|
|
|
|
static PyMethodDef extra_methodtable[] = {
|
|
#define method(func) { #func, (PyCFunction)func, METH_VARARGS, NULL }
|
|
method( make_raw_ostream_for_printing ),
|
|
method( make_small_vector_from_types ),
|
|
{ NULL }
|
|
#undef method
|
|
};
|