Remove IterToList, llvm_extra.h.
Add CustomMethod.
This commit is contained in:
parent
d939728938
commit
af7962a2ca
7 changed files with 61 additions and 64 deletions
|
|
@ -272,28 +272,17 @@ class Method(object):
|
|||
writer.println()
|
||||
|
||||
|
||||
class IterToList(Method):
|
||||
def __init__(self, elemty, argtys, iterty, begin, end):
|
||||
super(IterToList, self).__init__(PyObjectPtr, *argtys)
|
||||
self.elemty = elemty
|
||||
self.iterty = iterty
|
||||
self.begin = begin
|
||||
self.end = end
|
||||
class CustomMethod(Method):
|
||||
def __init__(self, methodname, retty, *argtys):
|
||||
super(CustomMethod, self).__init__(retty, *argtys)
|
||||
self.methodname = methodname
|
||||
|
||||
def compile_cpp_body(self, writer, retty, argtys):
|
||||
args = writer.parse_arguments('args', ptr(self.parent), *argtys)
|
||||
it = writer.method_call(self.begin, self.iterty, *args)
|
||||
end = writer.method_call(self.end, self.iterty, *args)
|
||||
con = writer.call('PyList_New', 'PyObject*', '0')
|
||||
writer.die_if_false(con)
|
||||
with writer.block('for (; %(it)s != %(end)s; ++%(it)s)' % locals()):
|
||||
elem = writer.declare(self.elemty.fullname, '*%(it)s;' % locals())
|
||||
wrapped = self.elemty.wrap(writer, elem)
|
||||
ok = writer.call('PyList_Append', 'int', con, wrapped)
|
||||
with writer.block('if (%(ok)s == -1)' % locals()):
|
||||
writer.return_value(None)
|
||||
writer.return_value(con)
|
||||
ret = writer.call(self.methodname, retty.fullname, *args)
|
||||
writer.return_value(retty.wrap(writer, ret))
|
||||
|
||||
|
||||
|
||||
class StaticMethod(Method):
|
||||
|
||||
|
|
|
|||
|
|
@ -42,14 +42,14 @@ def parse_arguments(println, var, *args):
|
|||
|
||||
return unwrapped
|
||||
|
||||
_re_mangle_pattern = re.compile(r'[ _<>\*&]')
|
||||
_re_mangle_pattern = re.compile(r'[ _<>\*&,]')
|
||||
|
||||
def mangle(name):
|
||||
def repl(m):
|
||||
s = m.group(0)
|
||||
if s in '<>*&':
|
||||
return ''
|
||||
elif s in ' ':
|
||||
elif s in ' ,':
|
||||
return '_'
|
||||
elif s in '_':
|
||||
return '__'
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ def populate_headers(println):
|
|||
includes = [
|
||||
'llvm_binding/conversion.h',
|
||||
'llvm_binding/binding.h',
|
||||
'llvm_binding/llvm_extra.h',
|
||||
'llvm_binding/capsule_context.h',
|
||||
'llvm_binding/extra.h', # extra submodule to add
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,10 +1,43 @@
|
|||
#include <Python.h>
|
||||
#include <llvm/ADT/SmallVector.h>
|
||||
#include <llvm/Value.h>
|
||||
#include <llvm/Support/raw_ostream.h>
|
||||
|
||||
|
||||
namespace extra{
|
||||
using namespace llvm;
|
||||
|
||||
class raw_svector_ostream_helper: public raw_svector_ostream {
|
||||
SmallVectorImpl<char> *SV;
|
||||
public:
|
||||
static
|
||||
raw_svector_ostream_helper* create(){
|
||||
SmallVectorImpl<char>* sv = new SmallVector<char, 16>();
|
||||
return new raw_svector_ostream_helper(sv);
|
||||
}
|
||||
|
||||
~raw_svector_ostream_helper(){
|
||||
delete SV;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
explicit
|
||||
raw_svector_ostream_helper(SmallVectorImpl<char>* sv)
|
||||
: raw_svector_ostream(*sv), SV(sv) {}
|
||||
|
||||
private:
|
||||
// no copy
|
||||
raw_svector_ostream_helper(const raw_svector_ostream_helper&);
|
||||
// no assign
|
||||
void operator = (const raw_svector_ostream_helper&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
static
|
||||
PyObject* make_raw_ostream_for_printing(PyObject* self, PyObject* args) {
|
||||
using llvm::raw_svector_ostream_helper;
|
||||
using extra::raw_svector_ostream_helper;
|
||||
using llvm::raw_svector_ostream;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
|
|
@ -18,7 +51,7 @@ PyObject* make_raw_ostream_for_printing(PyObject* self, PyObject* args) {
|
|||
static
|
||||
PyObject* make_small_vector_from_types(PyObject* self, PyObject* args) {
|
||||
using llvm::Type;
|
||||
using llvm::SmallVector_Type;
|
||||
typedef llvm::SmallVector<llvm::Type*, 8> SmallVector_Type;
|
||||
|
||||
SmallVector_Type* SV = new SmallVector_Type;
|
||||
Py_ssize_t size = PyTuple_Size(args);
|
||||
|
|
@ -33,7 +66,7 @@ PyObject* make_small_vector_from_types(PyObject* self, PyObject* args) {
|
|||
}
|
||||
SV->push_back(type);
|
||||
}
|
||||
return pycapsule_new(SV, "llvm::SmallVector_Type");
|
||||
return pycapsule_new(SV, "llvm::SmallVector<llvm::Type*,8>");
|
||||
}
|
||||
|
||||
static PyMethodDef extra_methodtable[] = {
|
||||
|
|
@ -43,3 +76,17 @@ static PyMethodDef extra_methodtable[] = {
|
|||
#undef method
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
|
||||
////////////
|
||||
|
||||
PyObject* Value_use_iterator_to_list(llvm::Value* val){
|
||||
typedef llvm::Value::use_iterator iterator;
|
||||
PyObject* list = PyList_New(0);
|
||||
for (iterator it = val->use_begin(), end = val->use_end(); it != end; ++it) {
|
||||
PyObject* cap = pycapsule_new(*it, "llvm::Value", "llvm::User");
|
||||
PyList_Append(list, cap);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
#include <Python.h>
|
||||
#include <llvm/ADT/SmallVector.h>
|
||||
#include <llvm/Support/raw_ostream.h>
|
||||
|
||||
namespace llvm{
|
||||
|
||||
class Type; //forward declaration
|
||||
|
||||
class raw_svector_ostream_helper: public raw_svector_ostream {
|
||||
SmallVectorImpl<char> *SV;
|
||||
public:
|
||||
static
|
||||
raw_svector_ostream_helper* create(){
|
||||
SmallVectorImpl<char>* sv = new SmallVector<char, 16>();
|
||||
return new raw_svector_ostream_helper(sv);
|
||||
}
|
||||
|
||||
~raw_svector_ostream_helper(){
|
||||
delete SV;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
explicit
|
||||
raw_svector_ostream_helper(SmallVectorImpl<char>* sv)
|
||||
: raw_svector_ostream(*sv), SV(sv) {}
|
||||
|
||||
private:
|
||||
// no copy
|
||||
raw_svector_ostream_helper(const raw_svector_ostream_helper&);
|
||||
// no assign
|
||||
void operator = (const raw_svector_ostream_helper&);
|
||||
};
|
||||
|
||||
typedef SmallVector<Type*, 8> SmallVector_Type;
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
|
|
@ -3,4 +3,5 @@ from namespace import llvm
|
|||
|
||||
@llvm.Class()
|
||||
class SmallVector_Type:
|
||||
_realname_ = 'SmallVector<llvm::Type*,8>'
|
||||
delete = Destructor()
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@ class Value:
|
|||
|
||||
replaceAllUsesWith = Method(Void, ptr(Value))
|
||||
|
||||
list_use = IterToList(ptr(User), (), 'llvm::Value::use_iterator',
|
||||
'use_begin', 'use_end')
|
||||
list_use = CustomMethod('Value_use_iterator_to_list', PyObjectPtr)
|
||||
|
||||
hasOneUse = Method(cast(Bool, bool))
|
||||
hasNUses = Method(cast(Bool, bool), cast(int, Unsigned))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue