Refactor raw_svector_stream_helper
This commit is contained in:
parent
6a861d82e6
commit
e9be14ca0e
5 changed files with 42 additions and 22 deletions
|
|
@ -1,15 +1,36 @@
|
|||
#include <Python.h>
|
||||
#include <llvm/ADT/SmallVector.h>
|
||||
#include <llvm/Support/raw_ostream.h>
|
||||
|
||||
static
|
||||
PyObject* small_vector_from_types(PyObject* self, PyObject* args) {
|
||||
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");
|
||||
|
|
@ -17,7 +38,8 @@ PyObject* small_vector_from_types(PyObject* self, PyObject* args) {
|
|||
|
||||
static PyMethodDef extra_methodtable[] = {
|
||||
#define method(func) { #func, (PyCFunction)func, METH_VARARGS, NULL }
|
||||
method( small_vector_from_types ),
|
||||
method( make_raw_ostream_for_printing ),
|
||||
method( make_small_vector_from_types ),
|
||||
{ NULL }
|
||||
#undef method
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue