[pypy-svn] r15981 - in pypy/dist/pypy/translator/llvm2: . test

rxe at codespeak.net rxe at codespeak.net
Thu Aug 11 23:42:56 CEST 2005


Author: rxe
Date: Thu Aug 11 23:42:54 2005
New Revision: 15981

Modified:
   pypy/dist/pypy/translator/llvm2/genllvm.py
   pypy/dist/pypy/translator/llvm2/test/test_lltype.py
Log:
remove embedexterns and work a little on readability.



Modified: pypy/dist/pypy/translator/llvm2/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm2/genllvm.py	Thu Aug 11 23:42:54 2005
@@ -24,14 +24,12 @@
 
 class GenLLVM(object):
 
-    def __init__(self, translator, debug=False, embedexterns=True):
-        embedexterns = True # XXX just for now because exception handling globals must be available
+    def __init__(self, translator, debug=False):
     
         # reset counters
         LLVMNode.nodename_count = {}    
         self.db = Database(translator)
         self.translator = translator
-        self.embedexterns = embedexterns
         translator.checkgraphs()
         ExternalFuncNode.used_external_functions = {}
 
@@ -100,9 +98,8 @@
             
         if self.debug:  print 'gen_llvm_source extdeclarations) ' + time.ctime()
         nl(); comment("Function Prototypes") ; nl()
-        if self.embedexterns:
-            for extdecl in extdeclarations.split('\n'):
-                codewriter.append(extdecl)
+        for extdecl in extdeclarations.split('\n'):
+            codewriter.append(extdecl)
 
         if self.debug:  print 'gen_llvm_source self._debug_prototype) ' + time.ctime()
         if self.debug:
@@ -178,26 +175,39 @@
         if self.debug:  print 'gen_llvm_source return) ' + time.ctime()
         return filename
 
-    def create_module(self, filename, really_compile=True, standalone=False, optimize=True, exe_name=None):
-        if not llvm_is_on_path(): 
-            py.test.skip("llvm not found")  # XXX not good to call py.test.skip here
+    def create_module(self,
+                      filename,
+                      really_compile=True,
+                      standalone=False,
+                      optimize=True,
+                      exe_name=None):
+
+        if not llvm_is_on_path():
+            # XXX not good to call py.test.skip here
+            py.test.skip("llvm not found")
 
         if standalone:
-            return build_llvm_module.make_module_from_llvm(filename, optimize=optimize, exe_name=exe_name)
+            return build_llvm_module.make_module_from_llvm(filename,
+                                                           optimize=optimize,
+                                                           exe_name=exe_name)
         else:
             postfix = ''
-            pyxfile = filename.new(basename=filename.purebasename+'_wrapper'+postfix+'.pyx')
+            basename = filename.purebasename+'_wrapper'+postfix+'.pyx'
+            pyxfile = filename.new(basename = basename)
             write_pyx_wrapper(self.entrynode, pyxfile)    
-            return build_llvm_module.make_module_from_llvm(filename, pyxfile=pyxfile, optimize=optimize)
+            return build_llvm_module.make_module_from_llvm(filename,
+                                                           pyxfile=pyxfile,
+                                                           optimize=optimize)
 
     def _debug_prototype(self, codewriter):
         codewriter.append("declare int %printf(sbyte*, ...)")
 
-def genllvm(translator, really_compile=True, standalone=False, optimize=True, embedexterns=True, exe_name=None):
-    gen = GenLLVM(translator, embedexterns=embedexterns)
+def genllvm(translator, log_source=False, **kwds):
+    gen = GenLLVM(translator)
     filename = gen.gen_llvm_source()
-    #log.genllvm(open(filename).read())
-    return gen.create_module(filename, really_compile=really_compile, standalone=standalone, optimize=optimize, exe_name=exe_name)
+    if log_source:
+        log.genllvm(open(filename).read())
+    return gen.create_module(filename, **kwds)
 
 def llvm_is_on_path():
     try:
@@ -206,19 +216,19 @@
         return False 
     return True
 
-def compile_module(function, annotation, view=False, really_compile=True, standalone=False, optimize=True, embedexterns=True, exe_name=None):
+def compile_module(function, annotation, view=False, **kwds):
     t = Translator(function)
     a = t.annotate(annotation)
     t.specialize()
     if view:
         t.view()
-    return genllvm(t, really_compile=really_compile, standalone=standalone, optimize=optimize, embedexterns=embedexterns, exe_name=exe_name)
+    return genllvm(t, **kwds)
 
-def compile_function(function, annotation, view=False, really_compile=True, standalone=False, optimize=True, embedexterns=True, exe_name=None):
-    mod = compile_module(function, annotation, view=view, really_compile=really_compile, standalone=standalone, optimize=optimize, embedexterns=embedexterns, exe_name=exe_name)
+def compile_function(function, annotation, **kwds):
+    mod = compile_module(function, annotation)
     return getattr(mod, function.func_name + "_wrapper")
 
-def compile_module_function(function, annotation, view=False, really_compile=True, standalone=False, optimize=True, embedexterns=True, exe_name=None):
-    mod = compile_module(function, annotation, view=view, really_compile=really_compile, standalone=standalone, optimize=optimize, embedexterns=embedexterns, exe_name=exe_name)
+def compile_module_function(function, annotation, **kwds):
+    mod = compile_module(function, annotation, **kwds)
     f = getattr(mod, function.func_name + "_wrapper")
     return mod, f

Modified: pypy/dist/pypy/translator/llvm2/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_lltype.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_lltype.py	Thu Aug 11 23:42:54 2005
@@ -28,7 +28,7 @@
     def struct_constant():
         x1 = s.signed + s.unsigned
         return x1
-    f = compile_function(struct_constant, [], embedexterns=False)
+    f = compile_function(struct_constant, [])
     assert f() == struct_constant()
 
 def test_struct_constant2():
@@ -41,7 +41,7 @@
     s.s2.b = 3
     def struct_constant():
         return s.a + s.s2.b + s.s1.a + s.s1.b
-    f = compile_function(struct_constant, [], embedexterns=False)
+    f = compile_function(struct_constant, [])
     assert f() == struct_constant()
 
 def test_struct_constant3():
@@ -62,7 +62,7 @@
         return (top.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.a -
                 top.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.b)
     
-    f = compile_function(struct_constant, [], embedexterns=False)
+    f = compile_function(struct_constant, [])
     assert f() == struct_constant()
 
 def test_struct_constant4():
@@ -73,7 +73,7 @@
     s.sptr.a = 21
     def struct_constant():
         return s.sptr.a * 2
-    f = compile_function(struct_constant, [], embedexterns=False)
+    f = compile_function(struct_constant, [])
     assert f() == struct_constant()
 
 def test_struct_constant5():
@@ -86,7 +86,7 @@
     s.sptr.b.b = 10
     def struct_constant():
         return s.sptr.a + s.sptr.b.a + s.sptr.b.b
-    f = compile_function(struct_constant, [], embedexterns=False)
+    f = compile_function(struct_constant, [])
     assert f() == struct_constant()
 
 def test_struct_constant6():
@@ -101,7 +101,7 @@
     s.p = s.u
     def struct_constant():
         return s.x.y + s.p.z
-    f = compile_function(struct_constant, [], embedexterns=False)
+    f = compile_function(struct_constant, [])
     assert f() == struct_constant()
 
 def test_aliasing():
@@ -112,7 +112,7 @@
     def aliasing(i):
         global_b.x = 17
         return global_a[i].x
-    f = compile_function(aliasing, [int], embedexterns=False)
+    f = compile_function(aliasing, [int])
     assert f(2) == 0
     assert f(3) == 17
 
@@ -126,7 +126,7 @@
     def aliasing(i):
         global_c.bptr.x = 17
         return global_a[i].x
-    f = compile_function(aliasing, [int], embedexterns=False)
+    f = compile_function(aliasing, [int])
     assert f(2) == 0
     assert f(3) == 17    
 
@@ -138,7 +138,7 @@
     a[2] = 102
     def array_constant():
         return a[0] + a[1] + a[2]    
-    f = compile_function(array_constant, [], embedexterns=False)
+    f = compile_function(array_constant, [])
     assert f() == array_constant()
 
 def test_array_constant2():
@@ -150,7 +150,7 @@
     def array_constant():
         a[0] = 0
         return a[0] + a[1] + a[2]    
-    f = compile_function(array_constant, [], embedexterns=False)
+    f = compile_function(array_constant, [])
     assert f() == array_constant()
 
 def test_array_constant3():
@@ -161,7 +161,7 @@
     a[2].x = 102
     def array_constant():
         return a[0].x + a[1].x + a[2].x    
-    f = compile_function(array_constant, [], embedexterns=False)
+    f = compile_function(array_constant, [])
     assert f() == array_constant()
 
 def test_struct_array1():
@@ -173,7 +173,7 @@
     a[1] = 101
     def array_constant():
         return s.aptr[1] - a[0]
-    f = compile_function(array_constant, [], embedexterns=False)
+    f = compile_function(array_constant, [])
     assert f() == array_constant()
 
 def test_struct_array2():
@@ -185,7 +185,7 @@
     s.b[1] = 101
     def array_constant():
         return s.b[1] - s.b[0] + s.a
-    f = compile_function(array_constant, [], embedexterns=False)
+    f = compile_function(array_constant, [])
     assert f() == array_constant()
 
 def test_struct_array3():
@@ -201,7 +201,7 @@
     def array_constant():
         s = b.p
         return s.b[1] - s.b[0] + s.a
-    f = compile_function(array_constant, [], embedexterns=False)
+    f = compile_function(array_constant, [])
     assert f() == array_constant()
 
 def test_struct_opaque():
@@ -211,5 +211,5 @@
     s.a = 42
     def array_constant():
         return s.a
-    f = compile_function(array_constant, [], embedexterns=False)
+    f = compile_function(array_constant, [])
     assert f() == array_constant()



More information about the Pypy-commit mailing list