Commits

Amaury Forgeot d'Arc committed 623f0ae

Merge the new CSharedModuleBuilder into the already existing CLibraryBuilder.

Comments (0)

Files changed (3)

pypy/translator/c/dlltool.py

 
 from pypy.translator.driver import TranslationDriver
-from pypy.translator.c.genc import CBuilder, CCompilerDriver
+from pypy.translator.c.genc import CLibraryBuilder, CCompilerDriver
 from pypy.rpython.typesystem import getfunctionptr
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 
-class CLibraryBuilder(CBuilder):
-    standalone = False
-    split = True
-
-    def __init__(self, *args, **kwds):
-        self.functions = kwds.pop('functions')
-        self.name = kwds.pop('name')
-        CBuilder.__init__(self, *args, **kwds)
-
-    def getentrypointptr(self):
-        bk = self.translator.annotator.bookkeeper
-        graphs = [bk.getdesc(f).cachedgraph(None) for f, _ in self.functions]
-        return [getfunctionptr(graph) for graph in graphs]
-
-    def gen_makefile(self, targetdir):
-        pass # XXX finish
-
-    def compile(self):
-        export_symbols = ([self.db.get(ep) for ep in self.getentrypointptr()] +
-                          ['RPython_StartupCode'])
-        extsymeci = ExternalCompilationInfo(export_symbols=export_symbols)
-        self.eci = self.eci.merge(extsymeci)
-        files = [self.c_source_filename] + self.extrafiles
-        oname = self.name
-        self.so_name = self.translator.platform.compile(files, self.eci,
-                                                        standalone=False,
-                                                        outputfilename=oname)
-
-    def get_entry_point(self, isolated=False):
-        return self.so_name
-
 class DLLDef(object):
     def __init__(self, name, functions=[], policy=None, config=None):
         self.name = name
 
     def compile(self):
         self.driver.proceed(['compile_c'])
-        return self.driver.c_entryp
+        return self.driver.cbuilder.so_name
 
     def getcbuilder(self, translator, config):
-        return CLibraryBuilder(translator, None, config,
-                               functions=self.functions, name=self.name)
+        bk = translator.annotator.bookkeeper
+        entrypoints = {}
+        for f, _ in self.functions:
+            graph = bk.getdesc(f).cachedgraph(None)
+            entrypoints[f.func_name] = getfunctionptr(graph)
+
+        return CLibraryBuilder(translator, entrypoints, config)

pypy/translator/c/genc.py

         except KeyError:
             pass
 
-class CSharedModuleBuilder(CBuilder):
+class CLibraryBuilder(CBuilder):
     "Builds a simple .so or .dll file"
     standalone = False
+    split = True
 
     def getentrypointptr(self):
         return self.entrypoint.values()
 
+    def get_entry_point(self, isolated=False):
+        return None
+
     def getexportsymbols(self):
         self.export_node_names = dict(
             (funcname, self.db.get(funcptr))
             for funcname, funcptr in self.entrypoint.items())
-        return self.export_node_names.values()
+        return self.export_node_names.values() + ['RPython_StartupCode']
 
     def compile(self):
         assert self.c_source_filename
     def gen_makefile(self, targetdir):
         pass
 
-class CExtModuleBuilder(CSharedModuleBuilder):
+class CExtModuleBuilder(CLibraryBuilder):
     "Build a CPython extension module"
     _module = None
     _wrapper = None

pypy/translator/c/test/test_separate.py

 from pypy.translator.c.separate import export
 from pypy.translator.translator import TranslationContext
-from pypy.translator.c.genc import CExtModuleBuilder, CSharedModuleBuilder, gen_forwarddecl
+from pypy.translator.c.genc import CExtModuleBuilder, CLibraryBuilder, gen_forwarddecl
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from pypy.rpython.typesystem import getfunctionptr
 from pypy.rpython.lltypesystem import rffi, lltype
 
             exported_funcptr[funcname] = funcptr
 
-        builder = CSharedModuleBuilder(t, exported_funcptr, config=t.config)
+        builder = CLibraryBuilder(t, exported_funcptr, config=t.config)
         builder.generate_source()
         builder.compile()