[pypy-svn] r45903 - in pypy/branch/pypy-more-rtti-inprogress: rpython/lltypesystem/test translator/c

fijal at codespeak.net fijal at codespeak.net
Wed Aug 22 12:06:04 CEST 2007


Author: fijal
Date: Wed Aug 22 12:06:03 2007
New Revision: 45903

Modified:
   pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_rffi.py
   pypy/branch/pypy-more-rtti-inprogress/translator/c/genc.py
Log:
* Move sources=[] attribute from having files into having direct source
* Include all the includes of current node into the same source


Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_rffi.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_rffi.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_rffi.py	Wed Aug 22 12:06:03 2007
@@ -8,15 +8,13 @@
 from pypy.rpython.test.test_llinterp import interpret
 
 def test_basic():
-    c_source = """
+    c_source = py.code.Source("""
     int z(int x)
     {
         return (x + 3);
     }
-    """
-    c_file = udir.join("stuff.c")
-    c_file.write(c_source)
-    z = llexternal('z', [Signed], Signed, sources=[str(c_file)])
+    """)
+    z = llexternal('z', [Signed], Signed, sources=[c_source])
 
     def f():
         return z(8)
@@ -64,9 +62,7 @@
         return ret;
     }
     """)
-    c_file = udir.join("stringrev.c")
-    c_file.write(c_source)
-    z = llexternal('f', [CCHARP], CCHARP, sources=[str(c_file)])    
+    z = llexternal('f', [CCHARP], CCHARP, sources=[c_source])    
 
     def f():
         s = str2charp("xxx")
@@ -93,9 +89,7 @@
         return (l);
     }
     """
-    c_file = udir.join("stringstar.c")
-    c_file.write(c_source)
-    z = llexternal('f', [CCHARPP], Signed, sources=[str(c_file)])
+    z = llexternal('f', [CCHARPP], Signed, sources=[c_source])
 
     def f():
         l = ["xxx", "x", "xxxx"]
@@ -119,7 +113,6 @@
     h_file.write(h_source)
     
     c_source = """
-    #include "structxx.h"
     int f(struct xx* z)
     {
       return (z->one + z->three);
@@ -127,10 +120,8 @@
     """
     TP = CStructPtr('xx', ('one', Signed), ('two', Char), ('three', Signed))
 
-    c_file = udir.join("structxx.c")
-    c_file.write(c_source)
-    z = llexternal('f', [TP], Signed, sources=[str(c_file)],
-                   includes=[str(h_file)])
+    z = llexternal('f', [TP], Signed, sources=[c_source],
+                   includes=[str(h_file)], include_dirs=[udir])
 
     def f():
         struct = lltype.malloc(TP.TO, flavor='raw')
@@ -178,16 +169,14 @@
 def test_extra_include_dirs():
     udir.ensure("incl", dir=True)
     udir.join("incl", "incl.h").write("#define C 3")
-    c_file = udir.join("test_extra_include_dirs.c")
-    c_source = """
+    c_source = py.code.Source("""
     #include <incl.h>
     int fun ()
     {
         return (C);
     }
-    """
-    c_file.write(c_source)
-    z = llexternal('fun', [], Signed, sources=[str(c_file)], include_dirs=
+    """)
+    z = llexternal('fun', [], Signed, sources=[c_source], include_dirs=
                    [str(udir.join("incl"))])
 
     def f():

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/genc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/genc.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/genc.py	Wed Aug 22 12:06:03 2007
@@ -373,6 +373,15 @@
 #        graph.optimize()
 #        self.funcnodes = graph.ordered_funcnodes()
 
+    def write_extra_sources(self, sources):
+        basename = 'additional_node.c'
+        retval = []
+        for source in sorted(sources.keys()):
+            f = self.makefile(self.uniquecname(basename))
+            for include in sources[source]:
+                print >>f, "#include <%s>" % (include,)
+            print >>f, str(source)
+
     def uniquecname(self, name):
         assert name.endswith('.c')
         return self.namespace.uniquename(name[:-2]) + '.c'
@@ -620,14 +629,12 @@
                 includes[include] = True
         if hasattr(node, 'sources'):
             for source in node.sources:
-                sources[source] = True
+                sources[source] = getattr(node, 'includes', [])
         if hasattr(node, 'include_dirs'):
             for include_dir in node.include_dirs:
                 include_dirs[include_dir] = True
     includes = includes.keys()
     includes.sort()
-    sources = sources.keys()
-    sources.sort()
     return includes, sources, include_dirs
 
 def gen_source_standalone(database, modulename, targetdir, 
@@ -674,6 +681,7 @@
     sg = SourceGenerator(database, preimplementationlines)
     sg.set_strategy(targetdir)
     sg.gen_readable_parts_of_source(f)
+    sg.write_extra_sources(sources)
 
     # 3) start-up code
     print >> f
@@ -687,7 +695,7 @@
         print >>fi, "#define INSTRUMENT_NCOUNTER %d" % n
         fi.close()
 
-    return filename, sg.getextrafiles() + sources, include_dirs
+    return filename, sg.getextrafiles(), include_dirs
 
 
 def gen_source(database, modulename, targetdir, defines={}, exports={},
@@ -735,6 +743,7 @@
     sg = SourceGenerator(database, preimplementationlines)
     sg.set_strategy(targetdir)
     sg.gen_readable_parts_of_source(f)
+    sg.write_extra_sources(sources)
 
     #
     # Debugging info
@@ -848,7 +857,7 @@
     f.write(SETUP_PY % locals())
     f.close()
 
-    return filename, sg.getextrafiles() + sources, include_dirs
+    return filename, sg.getextrafiles(), include_dirs
 
 
 SETUP_PY = '''



More information about the Pypy-commit mailing list