[pypy-svn] r48845 - in pypy/branch/new-genc-tests-wrapper/pypy/translator: c llsupport llvm
rxe at codespeak.net
rxe at codespeak.net
Tue Nov 20 16:41:05 CET 2007
Author: rxe
Date: Tue Nov 20 16:41:05 2007
New Revision: 48845
Modified:
pypy/branch/new-genc-tests-wrapper/pypy/translator/c/genc.py
pypy/branch/new-genc-tests-wrapper/pypy/translator/llsupport/modwrapper.py
pypy/branch/new-genc-tests-wrapper/pypy/translator/llvm/buildllvm.py
pypy/branch/new-genc-tests-wrapper/pypy/translator/llvm/funcnode.py
Log:
(cfbolz, rxe) progress in the direction of using modwrapper in both ll backends
Modified: pypy/branch/new-genc-tests-wrapper/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/new-genc-tests-wrapper/pypy/translator/c/genc.py (original)
+++ pypy/branch/new-genc-tests-wrapper/pypy/translator/c/genc.py Tue Nov 20 16:41:05 2007
@@ -35,7 +35,6 @@
if libraries is None:
libraries = []
self.libraries = libraries
- self.exports = {}
def build_database(self, pyobj_options=None):
translator = self.translator
@@ -74,7 +73,7 @@
# build entrypoint and eventually other things to expose
pf = self.getentrypointptr()
pfname = db.get(pf)
- self.exports[self.entrypoint.func_name] = pf
+ self.entrypoint_name = pfname
db.complete()
# add library dependencies
@@ -129,7 +128,6 @@
cfile, extra, include_dirs, library_dirs = \
gen_source(db, modulename, targetdir,
defines = defines,
- exports = self.exports,
libraries = self.libraries)
else:
if self.config.translation.instrument:
@@ -169,7 +167,8 @@
def getentrypointptr(self):
bk = self.translator.annotator.bookkeeper
- return getfunctionptr(bk.getdesc(self.entrypoint).getuniquegraph())
+ self.graph_entrypoint = bk.getdesc(self.entrypoint).getuniquegraph()
+ return getfunctionptr(self.graph_entrypoint)
def compile(self):
assert self.c_source_filename
@@ -180,8 +179,15 @@
include_dirs = [autopath.this_dir] + extra_includes,
library_dirs = self.library_dirs,
libraries=self.libraries)
- self._compiled = True
+ from pypy.translator.llsupport.modwrapper import CtypesModule
+ dll_filename = self.c_source_filename.new(ext='so')
+ modname = CtypesModule(self.entrypoint_name,
+ self.graph_entrypoint,
+ dll_filename).create()
+
+ self._compiled = True
+
def import_module(self):
assert self._compiled
assert not self.c_ext_module
@@ -682,8 +688,7 @@
return filename, sg.getextrafiles(), include_dirs, library_dirs
-def gen_source(database, modulename, targetdir, defines={}, exports={},
- libraries=[]):
+def gen_source(database, modulename, targetdir, defines={}, libraries=[]):
assert not database.standalone
if isinstance(targetdir, str):
targetdir = py.path.local(targetdir)
@@ -730,69 +735,6 @@
sg.write_extra_sources(sources)
#
- # PyObject support (strange) code
- #
- pyobjmaker = database.pyobjmaker
- print >> f
- print >> f, '/***********************************************************/'
- print >> f, '/*** Table of global PyObjects ***/'
- print >> f
- print >> f, 'static globalobjectdef_t globalobjectdefs[] = {'
- for node in database.containerlist:
- if isinstance(node, (PyObjectNode, PyObjHeadNode)):
- for target in node.where_to_copy_me:
- print >> f, '\t{%s, "%s"},' % (target, node.exported_name)
- print >> f, '\t{ NULL, NULL }\t/* Sentinel */'
- print >> f, '};'
- print >> f
- print >> f, 'static cpyobjheaddef_t cpyobjheaddefs[] = {'
- for node in database.containerlist:
- if isinstance(node, PyObjHeadNode):
- print >> f, '\t{"%s", %s, %s},' % (node.exported_name,
- node.ptrname,
- node.get_setupfn_name())
- print >> f, '\t{ NULL, NULL, NULL }\t/* Sentinel */'
- print >> f, '};'
- print >> f
- print >> f, '/***********************************************************/'
- print >> f, '/*** Table of functions ***/'
- print >> f
- print >> f, 'static globalfunctiondef_t globalfunctiondefs[] = {'
- wrappers = pyobjmaker.wrappers.items()
- wrappers.sort()
- for globalobject_name, (base_name, wrapper_name, func_doc) in wrappers:
- print >> f, ('\t{&%s, "%s", {"%s", (PyCFunction)%s, '
- 'METH_VARARGS|METH_KEYWORDS, %s}},' % (
- globalobject_name,
- globalobject_name,
- base_name,
- wrapper_name,
- func_doc and c_string_constant(func_doc) or 'NULL'))
- print >> f, '\t{ NULL }\t/* Sentinel */'
- print >> f, '};'
- print >> f, 'static globalfunctiondef_t *globalfunctiondefsptr = &globalfunctiondefs[0];'
- print >> f
- print >> f, '/***********************************************************/'
- print >> f, '/*** Frozen Python bytecode: the initialization code ***/'
- print >> f
- print >> f, 'static char *frozen_initcode[] = {"\\'
- bytecode, originalsource = database.pyobjmaker.getfrozenbytecode()
- g = targetdir.join('frozen.py').open('w')
- g.write(originalsource)
- g.close()
- def char_repr(c):
- if c in '\\"': return '\\' + c
- if ' ' <= c < '\x7F': return c
- return '\\%03o' % ord(c)
- for i in range(0, len(bytecode), 32):
- print >> f, ''.join([char_repr(c) for c in bytecode[i:i+32]])+'\\'
- if (i+32) % 1024 == 0:
- print >> f, '", "\\'
- print >> f, '"};'
- print >> f, "#define FROZEN_INITCODE_SIZE %d" % len(bytecode)
- print >> f
-
- #
# Module initialization function
#
print >> f, '/***********************************************************/'
@@ -800,16 +742,14 @@
print >> f
gen_startupcode(f, database)
print >> f
- print >> f, 'MODULE_INITFUNC(%s)' % modulename
- print >> f, '{'
- print >> f, '\tSETUP_MODULE(%s);' % modulename
- for publicname, pyobjptr in exports.items():
- # some fishing needed to find the name of the obj
- pyobjnode = database.containernodes[pyobjptr._obj]
- print >> f, '\tPyModule_AddObject(m, "%s", %s);' % (publicname,
- pyobjnode.name)
- print >> f, '\tcall_postsetup(m);'
+
+ print >> f, 'int ctypes_RPython_StartupCode() {'
+ print >> f, ' char *res = RPython_StartupCode();'
+ print >> f, ' if (res == NULL) return 1;'
+ print >> f, ' return 0;'
print >> f, '}'
+ print >> f
+
f.close()
#
Modified: pypy/branch/new-genc-tests-wrapper/pypy/translator/llsupport/modwrapper.py
==============================================================================
--- pypy/branch/new-genc-tests-wrapper/pypy/translator/llsupport/modwrapper.py (original)
+++ pypy/branch/new-genc-tests-wrapper/pypy/translator/llsupport/modwrapper.py Tue Nov 20 16:41:05 2007
@@ -14,11 +14,11 @@
_c = ctypes.CDLL(join(dirname(realpath(__file__)), "%s"))
-rpyexc_occured = _c.pypy__rpyexc_occured
+rpyexc_occured = _c.pypy_g__RPyExceptionOccurred
rpyexc_occured.argtypes = []
rpyexc_occured.restype = ctypes.c_int
-rpyexc_fetch_type = _c.pypy_rpyexc_fetch_type
+rpyexc_fetch_type = _c.pypy_g_RPyFetchExceptionType
rpyexc_fetch_type.argtypes = []
rpyexc_fetch_type.restype = ctypes.c_void_p
@@ -133,7 +133,7 @@
"""
epilog = """
-__entrypoint__ = _c.pypy_%(name)s
+__entrypoint__ = _c.%(name)s
# %(RT)r
to_llargs = %(to_llargs)s
@@ -156,11 +156,11 @@
lltype.UniChar: "ctypes.c_uint",
}
- def __init__(self, entryname, filename, graph, dllname, gcoffset=0):
+ def __init__(self, entryname, graph, dllname, gcoffset=0):
self.entryname = entryname
self.dllname = dllname
basename = self.entryname + '_wrapper.py'
- self.modfilename = filename.new(basename=basename)
+ self.modfilename = dllname.new(basename=basename)
self.count = 0
self.graph = graph
Modified: pypy/branch/new-genc-tests-wrapper/pypy/translator/llvm/buildllvm.py
==============================================================================
--- pypy/branch/new-genc-tests-wrapper/pypy/translator/llvm/buildllvm.py (original)
+++ pypy/branch/new-genc-tests-wrapper/pypy/translator/llvm/buildllvm.py Tue Nov 20 16:41:05 2007
@@ -135,9 +135,8 @@
self.execute_cmds()
gen = self.genllvm
modname = CtypesModule(gen.entry_name,
- gen.filename,
gen.entrynode.graph,
- "%s.so" % base).create()
+ py.path.local("%s.so" % base)).create()
finally:
self.lastdir.chdir()
Modified: pypy/branch/new-genc-tests-wrapper/pypy/translator/llvm/funcnode.py
==============================================================================
--- pypy/branch/new-genc-tests-wrapper/pypy/translator/llvm/funcnode.py (original)
+++ pypy/branch/new-genc-tests-wrapper/pypy/translator/llvm/funcnode.py Tue Nov 20 16:41:05 2007
@@ -11,7 +11,7 @@
pass
class FuncImplNode(FuncNode):
- prefix = '@pypy_'
+ prefix = '@pypy_g_'
__slots__ = "db value graph block_to_name bad_switch_block".split()
def __init__(self, db, value):
@@ -20,7 +20,9 @@
self.graph = value.graph
self.bad_switch_block = False
- self.make_name(value.graph.name)
+ name = value._name
+ #name = value.graph.name
+ self.make_name(name)
def setup(self):
assert self.graph, "cannot traverse"
More information about the Pypy-commit
mailing list