From 48ef080faeee112510766b048d110d346d677468 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sat, 9 Jul 2011 08:57:32 -0400 Subject: [PATCH] Auto-generate headers on setup.py, first test, plus fixes. --- gen_wrap.py | 78 ++++++++++++++++++++++++---------------- islpy/__init__.py | 4 +-- setup.py | 10 +++++- src/wrapper/wrap_isl.cpp | 77 +++++++++++++++++++++++---------------- 4 files changed, 106 insertions(+), 63 deletions(-) diff --git a/gen_wrap.py b/gen_wrap.py index 97ae0dd..65ef0c8 100644 --- a/gen_wrap.py +++ b/gen_wrap.py @@ -115,11 +115,25 @@ def parse_arg(arg): class FunctionData: - def __init__(self): + def __init__(self, include_dirs): self.classes_to_methods = {} + self.include_dirs = include_dirs def read_header(self, fname): - inf = open(fname, "rt") + from os.path import join + success = False + for inc_dir in self.include_dirs: + try: + inf = open(join(inc_dir, fname), "rt") + except IOError: + pass + else: + success = True + break + + if not success: + raise RuntimeError("header '%s' not found" % fname) + try: lines = inf.readlines() finally: @@ -215,18 +229,22 @@ class FunctionData: def write_exposer(outf, meth): - extra_stuff = "" - if meth.return_type.endswith("*") and not meth.return_type.endswith("char *"): - extra_stuff = ", py::return_value_policy()" - + func_name = "isl::%s_%s" % (meth.cls, meth.name) py_name = meth.name + if meth.name == "size": py_name = "__len__" - elif meth.name == "alloc": + elif "alloc" in meth.name: py_name = "__init__" + func_name = "py::make_constructor(%s)" % func_name + + extra_stuff = "" + if (py_name != "__init__" and + meth.return_type.endswith("*") and not meth.return_type.endswith("char *")): + extra_stuff = ", py::return_value_policy()" - outf.write("wrap_%s.def(\"%s\", isl::%s_%s%s);\n" % ( - meth.cls, py_name, meth.cls, meth.name, extra_stuff)) + outf.write("wrap_%s.def(\"%s\", %s%s);\n" % ( + meth.cls, py_name, func_name, extra_stuff)) @@ -364,27 +382,27 @@ def write_wrappers(expf, wrapf, methods): except OddSignature: print "SKIP (odd sig):", meth else: - print "WRAPPED:", meth - - - - -def gen_wrapper(): - fdata = FunctionData() - from os.path import expanduser - fdata.read_header(expanduser("~/pool/include/isl/dim.h")) - fdata.read_header(expanduser("~/pool/include/isl/set.h")) - fdata.read_header(expanduser("~/pool/include/isl/map.h")) - fdata.read_header(expanduser("~/pool/include/isl/vec.h")) - fdata.read_header(expanduser("~/pool/include/isl/mat.h")) - fdata.read_header(expanduser("~/pool/include/isl/local_space.h")) - fdata.read_header(expanduser("~/pool/include/isl/aff.h")) - #fdata.read_header(expanduser("~/pool/include/isl/polynomial.h")) - fdata.read_header(expanduser("~/pool/include/isl/union_map.h")) - fdata.read_header(expanduser("~/pool/include/isl/union_set.h")) - fdata.read_header(expanduser("~/pool/include/isl/printer.h")) - fdata.read_header(expanduser("~/pool/include/isl/vertices.h")) - #fdata.read_header(expanduser("~/pool/include/isl/constraint.h")) + #print "WRAPPED:", meth + pass + + + + +def gen_wrapper(include_dirs): + fdata = FunctionData(include_dirs) + fdata.read_header("isl/dim.h") + fdata.read_header("isl/set.h") + fdata.read_header("isl/map.h") + fdata.read_header("isl/vec.h") + fdata.read_header("isl/mat.h") + fdata.read_header("isl/local_space.h") + fdata.read_header("isl/aff.h") + #fdata.read_header("isl/polynomial.h") + fdata.read_header("isl/union_map.h") + fdata.read_header("isl/union_set.h") + fdata.read_header("isl/printer.h") + fdata.read_header("isl/vertices.h") + #fdata.read_header("isl/constraint.h") expf = open("src/wrapper/gen-expose.inc", "wt") wrapf = open("src/wrapper/gen-wrap.inc", "wt") diff --git a/islpy/__init__.py b/islpy/__init__.py index d9dee6c..9c21145 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -1,2 +1,2 @@ -version = (2011, 1) -version_text = ".".join(str(i) for i in version) +from islpy._isl import * +from islpy.version import * diff --git a/setup.py b/setup.py index 30ae97e..9e790f8 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ def main(): LIBRARY_DIRS = conf["BOOST_LIB_DIR"] LIBRARIES = conf["BOOST_PYTHON_LIBNAME"] - init_filename = "islpy/__init__.py" + init_filename = "islpy/version.py" exec(compile(open(init_filename, "r").read(), init_filename, "exec"), conf) try: @@ -41,6 +41,9 @@ def main(): # 2.x from distutils.command.build_py import build_py + from gen_wrap import gen_wrapper + gen_wrapper(conf["ISL_INC_DIR"]) + setup(name="islpy", version=conf["version_text"], description="Wrapper around isl, an integer set library", @@ -68,6 +71,11 @@ def main(): ], packages = [ "islpy" ], + + install_requires=[ + "pytest>=2", + # "Mako>=0.3.6", + ], ext_modules = [ Extension( "islpy._isl", diff --git a/src/wrapper/wrap_isl.cpp b/src/wrapper/wrap_isl.cpp index f01b498..4607999 100644 --- a/src/wrapper/wrap_isl.cpp +++ b/src/wrapper/wrap_isl.cpp @@ -34,8 +34,25 @@ namespace isl { if (m_valid) isl_##name##_free(m_data); } \ }; - - WRAP_CLASS(ctx); + struct ctx \ + { + public: + isl_ctx *m_data; + bool m_valid; + + ctx(isl_ctx *data) + : m_data(data), m_valid(true) + { } + + ~ctx() + { + if (m_valid) + { + isl_ctx_deref(m_data); + isl_ctx_free(m_data); + } + } + }; WRAP_CLASS(printer); WRAP_CLASS(mat); @@ -153,34 +170,34 @@ BOOST_PYTHON_MODULE(_isl) #define MAKE_WRAP(name, py_name) \ py::class_ wrap_##name(#py_name, py::no_init); - MAKE_WRAP(printer, "Printer"); - MAKE_WRAP(mat, "Mat"); - MAKE_WRAP(vec, "Vec"); - - MAKE_WRAP(aff, "Aff"); - MAKE_WRAP(pw_aff, "PwAff"); - - MAKE_WRAP(div, "Div"); - MAKE_WRAP(dim, "Dim"); - MAKE_WRAP(local_space, "LocalSpace"); - - MAKE_WRAP(basic_set, "BasicSet"); - MAKE_WRAP(basic_map, "BasicMap"); - MAKE_WRAP(set, "Set"); - MAKE_WRAP(map, "Map"); - MAKE_WRAP(union_set, "UnionSet"); - MAKE_WRAP(union_map, "UnionMap"); - - MAKE_WRAP(point, "Point"); - MAKE_WRAP(vertex, "Vertex"); - MAKE_WRAP(cell, "Cell"); - MAKE_WRAP(vertices, "Vertices"); - MAKE_WRAP(qpolynomial, "QPolynomial"); - - MAKE_WRAP(basic_set_list, "BasicSetList"); - MAKE_WRAP(set_list, "SetList"); - MAKE_WRAP(aff_list, "AffList"); - MAKE_WRAP(band_list, "BandList"); + MAKE_WRAP(printer, Printer); + MAKE_WRAP(mat, Mat); + MAKE_WRAP(vec, Vec); + + MAKE_WRAP(aff, Aff); + MAKE_WRAP(pw_aff, PwAff); + + MAKE_WRAP(div, Div); + MAKE_WRAP(dim, Dim); + MAKE_WRAP(local_space, LocalSpace); + + MAKE_WRAP(basic_set, BasicSet); + MAKE_WRAP(basic_map, BasicMap); + MAKE_WRAP(set, Set); + MAKE_WRAP(map, Map); + MAKE_WRAP(union_set, UnionSet); + MAKE_WRAP(union_map, UnionMap); + + MAKE_WRAP(point, Point); + MAKE_WRAP(vertex, Vertex); + MAKE_WRAP(cell, Cell); + MAKE_WRAP(vertices, Vertices); + MAKE_WRAP(qpolynomial, QPolynomial); + + MAKE_WRAP(basic_set_list, BasicSetList); + MAKE_WRAP(set_list, SetList); + MAKE_WRAP(aff_list, AffList); + MAKE_WRAP(band_list, BandList); #include "gen-expose.inc" } -- GitLab