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
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ from binding import *
|
|||
from namespace import llvm
|
||||
from LLVMContext import LLVMContext
|
||||
from StringRef import StringRef
|
||||
from raw_ostream import raw_svector_ostream_helper
|
||||
from Constant import Constant
|
||||
from DerivedTypes import FunctionType
|
||||
from raw_ostream import raw_ostream
|
||||
from AssemblyAnnotationWriter import AssemblyAnnotationWriter
|
||||
|
||||
# class Module
|
||||
|
|
@ -34,13 +36,10 @@ setModuleInlineAsm = Module.method(Void, StringRef.From(str))
|
|||
appendModuleInlineAsm = Module.method(Void, StringRef.From(str))
|
||||
|
||||
# Function Accessors
|
||||
#getOrInsertFunction = Module.method(Constant, StringRef.From(str), FunctionType.Pointer)
|
||||
|
||||
|
||||
getOrInsertFunction = Module.method(Constant.Pointer, StringRef.From(str), FunctionType.Pointer)
|
||||
|
||||
# Utilities
|
||||
dump = Module.method(Void)
|
||||
print_ = Module.method(Void, raw_svector_ostream_helper.Ref,
|
||||
AssemblyAnnotationWriter.Pointer)
|
||||
print_ = Module.method(Void, raw_ostream.Ref, AssemblyAnnotationWriter.Pointer)
|
||||
print_.realname = 'print'
|
||||
dropAllReferences = Module.method(Void)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from binding import *
|
||||
from namespace import llvm
|
||||
from LLVMContext import LLVMContext
|
||||
from raw_ostream import raw_svector_ostream_helper
|
||||
from raw_ostream import raw_ostream
|
||||
|
||||
Type = llvm.Class()
|
||||
Type.include.add('llvm/Type.h')
|
||||
|
|
@ -13,7 +13,7 @@ PointerType = SequentialType.Subclass()
|
|||
|
||||
getContext = Type.method(LLVMContext.Ref)
|
||||
dump = Type.method(Void)
|
||||
print_ = Type.method(Void, raw_svector_ostream_helper.Ref)
|
||||
print_ = Type.method(Void, raw_ostream.Ref)
|
||||
print_.realname = 'print'
|
||||
|
||||
def type_checker():
|
||||
|
|
|
|||
|
|
@ -5,13 +5,8 @@ from StringRef import StringRef
|
|||
|
||||
raw_ostream = llvm.Class()
|
||||
raw_ostream.include.add("llvm/Support/raw_ostream.h")
|
||||
delete = raw_ostream.delete()
|
||||
|
||||
raw_svector_ostream = raw_ostream.Subclass()
|
||||
raw_svector_ostream.include.add("llvm/Support/raw_os_ostream.h")
|
||||
|
||||
# extra class to help binding
|
||||
raw_svector_ostream_helper = raw_svector_ostream.Subclass()
|
||||
create = raw_svector_ostream_helper.staticmethod(
|
||||
raw_svector_ostream_helper.Pointer)
|
||||
delete = raw_svector_ostream_helper.delete()
|
||||
str = raw_svector_ostream_helper.method(StringRef.To(str))
|
||||
str = raw_svector_ostream.method(StringRef.To(str))
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ assert m.getPointerSize() == api.Module.PointerSize.AnyPointerSize
|
|||
m.dump()
|
||||
|
||||
|
||||
os = api.raw_svector_ostream_helper.create()
|
||||
os = api.make_raw_ostream_for_printing()
|
||||
m.print_(os, None)
|
||||
print os.str()
|
||||
|
||||
|
|
@ -29,10 +29,14 @@ fnty = api.FunctionType.get(int1ty, False)
|
|||
fnty.dump()
|
||||
|
||||
types = [int1ty, api.Type.getIntNTy(context, 21)]
|
||||
svt = api.small_vector_from_types(*types)
|
||||
svt = api.make_small_vector_from_types(*types)
|
||||
fnty = api.FunctionType.get(int1ty, svt, False)
|
||||
|
||||
os2 = api.raw_svector_ostream_helper.create()
|
||||
fnty.print_(os2)
|
||||
print os2.str()
|
||||
os = api.make_raw_ostream_for_printing()
|
||||
fnty.print_(os)
|
||||
print os.str()
|
||||
|
||||
fn = m.getOrInsertFunction("foo", fnty)
|
||||
os = api.make_raw_ostream_for_printing()
|
||||
fn.print_(os, None)
|
||||
print os.str()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue