[pypy-svn] r22418 - in pypy/dist/pypy/translator/llvm: . module test

ericvrp at codespeak.net ericvrp at codespeak.net
Thu Jan 19 11:26:01 CET 2006


Author: ericvrp
Date: Thu Jan 19 11:25:53 2006
New Revision: 22418

Modified:
   pypy/dist/pypy/translator/llvm/extfuncnode.py
   pypy/dist/pypy/translator/llvm/module/support.py
   pypy/dist/pypy/translator/llvm/test/test_extfunc.py
Log:
Create wrapper functions (on 64 bit architectures) where a int is expected
but a long gives.

The remaining problem for external functions has to do with data structures
used by the ext.funcs.


Modified: pypy/dist/pypy/translator/llvm/extfuncnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/extfuncnode.py	(original)
+++ pypy/dist/pypy/translator/llvm/extfuncnode.py	Thu Jan 19 11:25:53 2006
@@ -18,20 +18,6 @@
     "%LL_thread_start" : ExtFuncSig(None, ["sbyte*", "sbyte*"]),
     }
 
-#on 64 bit systems we need a wrapper for everything the takes or returns an int
-from sys import maxint
-if maxint != 2**31-1:
-    extra_ext_func_sigs = {
-        "%LL_os_dup" : ExtFuncSig("int", ["int"]),
-        "%LL_os_open" : ExtFuncSig("int", [None, "int", "int"]),
-        "%LL_os_write" : ExtFuncSig(None, ["int", None]),
-        "%LL_read_into" : ExtFuncSig(None, ["int", None]),
-        "%LL_os_close" : ExtFuncSig(None, ["int"]),
-        "%pypy_ll_stat_result__Signed_Signed_Signed_Signed_Signed_Signed_Signed_Signed_Signed_Signed" : ExtFuncSig(None, ["int"]*10)
-        }
-    ext_func_sigs.update(extra_ext_func_sigs)
-
-
 class ExternalFuncNode(ConstantLLVMNode):
 
     def __init__(self, db, value):
@@ -42,15 +28,45 @@
 
         mapped_name = EXTERNALS[value._callable]
         self.ref = self.make_ref("%", mapped_name)
-        self.wrapper = ext_func_sigs.get(self.ref, None)
-        if self.wrapper is None and maxint != 2**31-1:
-            #XXX if returntype or param in ('int', 'uint'):
-            #         add wrapper to return from long->int
-            pass
+
+    def setup(self):
+        self.db.prepare_type(self.value._TYPE.RESULT)
+        self.db.prepare_type_multi(self.value._TYPE._trueargs()) 
 
     def __str__(self):
         return "<ExternalFuncNode %r>" % self.ref
 
+    def _get_wrapper(self):
+        wrapper = ext_func_sigs.get(self.ref, None)
+
+        from sys import maxint
+        if wrapper is None and maxint != 2**31-1:
+            #log("ref=%s" % self.ref)
+            rettype, args = self.getdecl_parts()
+            conversions = False
+            if   rettype == "long":
+                rettype = "int"
+                conversions = True
+            elif rettype == "ulong":
+                rettype = "uint"
+                conversions = True
+            else:
+                rettype = None
+            for i, a in enumerate(args):
+                if   a == "long":
+                    args[i] = "int"
+                    conversions = True
+                elif a == "ulong":
+                    args[i] = "uint"
+                    conversions = True
+                else:
+                    args[i] = None
+            if conversions:
+                wrapper = ExtFuncSig(rettype, args)
+                #log("    rettype=%s" % str(rettype))
+                #log("    args   =%s" % str(args))
+        return wrapper
+
     def getdecl_parts(self):
         T = self.value._TYPE
         rettype = self.db.repr_type(T.RESULT)
@@ -65,8 +81,8 @@
         codewriter.declare(self.getdecl())
 
     def writeimpl(self, codewriter):
-                                   
-        if self.wrapper is None:
+        wrapper = self._get_wrapper()
+        if wrapper is None:
             return
         
         rettype, argtypes = self.getdecl_parts()
@@ -85,10 +101,10 @@
         expected_argtypes = []
 
         # find out what the args/types should be
-        if self.wrapper.args is not None:
-            assert len(self.wrapper.args) == len(argtypes)
+        if wrapper.args is not None:
+            assert len(wrapper.args) == len(argtypes)
             
-            for expected_typ, typ, ref in zip(self.wrapper.args,
+            for expected_typ, typ, ref in zip(wrapper.args,
                                               argtypes,
                                               argrefs):
                 if expected_typ is not None:
@@ -108,17 +124,17 @@
             expected_argtypes = argtypes
 
         # find out what the return type should be 
-        expected_rettype = self.wrapper.rettype or rettype
+        expected_rettype = wrapper.rettype or rettype
 
         # call
         codewriter.call(returnval, expected_rettype, self.ref,
                         expected_argtypes, expected_argrefs)
 
-        if self.wrapper.rettype:
+        if wrapper.rettype:
             # cast to desired return type
             tmpval = returnval
             returnval = self.db.repr_tmpvar()
-            codewriter.cast(returnval, self.wrapper.rettype,
+            codewriter.cast(returnval, wrapper.rettype,
                             tmpval, rettype)
             
         codewriter.ret(rettype, returnval)

Modified: pypy/dist/pypy/translator/llvm/module/support.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/module/support.py	(original)
+++ pypy/dist/pypy/translator/llvm/module/support.py	Thu Jan 19 11:25:53 2006
@@ -81,7 +81,7 @@
 
 from sys import maxint
 if maxint != 2**31-1:
-    extfunctions = """
+    extfunctions += """
 internal fastcc void %pypy_ll_raise_OSError__Signed(int %errno_0) {
     %tmp = cast int %errno_0 to long
     call void %pypy_ll_raise_OSError__Signed(long %tmp)

Modified: pypy/dist/pypy/translator/llvm/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_extfunc.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/test_extfunc.py	Thu Jan 19 11:25:53 2006
@@ -9,9 +9,6 @@
 from pypy.rpython.rarithmetic import r_uint
 from pypy.rpython import ros
 
-if sys.maxint != 2**31-1:
-    py.test.skip("WIP") 
-
 def test_external_function_ll_os_dup():
     def fn():
         return os.dup(0)
@@ -60,6 +57,8 @@
     assert os.path.exists(path)
 
 def test_os_file_ops_open_write_close(): 
+    if sys.maxint != 2**31-1:
+        py.test.skip("WIP on 64 bit architectures") 
     def openwriteclose(): 
         fd = os.open(path, os.O_CREAT|os.O_RDWR, 0777) 
         byteswritten = os.write(fd, path)
@@ -74,6 +73,8 @@
     assert open(path).read() == path
 
 def test_os_file_ops_open_write_read_close(): 
+    if sys.maxint != 2**31-1:
+        py.test.skip("WIP on 64 bit architectures") 
     def openwriteclose_openreadclose():
         fd = os.open(path, os.O_CREAT|os.O_RDWR, 0777) 
         byteswritten = os.write(fd, path+path+path)
@@ -97,6 +98,8 @@
 # following from translator/c/test/test_extfunc.py Revision: 15320 (jul 29th 2005)
 
 def test_os_stat():
+    if sys.maxint != 2**31-1:
+        py.test.skip("WIP on 64 bit architectures") 
     filename = str(py.magic.autopath())
     def call_stat0():
         st = os.stat(filename)
@@ -116,6 +119,8 @@
     assert f2() == st[2]
 
 def test_os_fstat():
+    if sys.maxint != 2**31-1:
+        py.test.skip("WIP on 64 bit architectures") 
     filename = str(py.magic.autopath())
     def call_fstat0():
         fd = os.open(filename, os.O_RDONLY, 0777)
@@ -148,6 +153,8 @@
     assert f1()
 
 def test_math_frexp():
+    if sys.maxint != 2**31-1:
+        py.test.skip("WIP on 64 bit architectures") 
     from math import frexp
     def fn(x):
         res = frexp(x)
@@ -186,6 +193,8 @@
         yield math_function_test, funcname
 
 def test_os_path_exists():
+    if sys.maxint != 2**31-1:
+        py.test.skip("WIP on 64 bit architectures") 
     tmpfile = str(udir.join('test_os_path_exists.TMP'))
     def fn():
         return os.path.exists(tmpfile)
@@ -196,6 +205,8 @@
     assert f() == False
 
 def test_dynamic_string_null_termination():
+    if sys.maxint != 2**31-1:
+        py.test.skip("WIP on 64 bit architectures") 
     # forces malloc / versus pbc for NUL testing of C string
     tmpfile = str(udir.join('test_os_path_exists.TMP'))
     def fn(l):
@@ -208,6 +219,8 @@
     assert f(lfile-2) == False
 
 def test_os_path_isdir():
+    if sys.maxint != 2**31-1:
+        py.test.skip("WIP on 64 bit architectures") 
     directory = "./."
     def fn():
         return os.path.isdir(directory)
@@ -228,6 +241,8 @@
     assert f(2) == os.isatty(2)
     
 def test_rarith_parts_to_float():
+    if sys.maxint != 2**31-1:
+        py.test.skip("WIP on 64 bit architectures") 
     from pypy.rpython.rarithmetic import parts_to_float
     parts = [
      ["" ,"1","" ,""],
@@ -246,6 +261,8 @@
         assert f(i) == v
 
 def test_rarith_formatd():
+    if sys.maxint != 2**31-1:
+        py.test.skip("WIP on 64 bit architectures") 
     from pypy.rpython.rarithmetic import formatd
     as_float  = [ 0.0  ,  1.5  ,  2.0  ]
     as_string = ["0.00", "1.50", "2.00"]
@@ -421,6 +438,8 @@
     assert res == 42
 
 def test_start_new_thread():
+    if sys.maxint != 2**31-1:
+        py.test.skip("WIP on 64 bit architectures") 
     import thread
     import pypy.module.thread.rpython.exttable   # for declare()/declaretype()
     class Arg:



More information about the Pypy-commit mailing list