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

ericvrp at codespeak.net ericvrp at codespeak.net
Mon Aug 15 21:29:28 CEST 2005


Author: ericvrp
Date: Mon Aug 15 21:29:26 2005
New Revision: 16082

Modified:
   pypy/dist/pypy/translator/llvm2/genllvm.py
   pypy/dist/pypy/translator/llvm2/module/ll_math.py
   pypy/dist/pypy/translator/llvm2/module/ll_os.py
   pypy/dist/pypy/translator/llvm2/module/support.py
   pypy/dist/pypy/translator/llvm2/test/test_extfunc.py
Log:
- added debug info
- added os.stat and os.fstat
- enabled some (now passing) tests in test_extfunc.py

note: test/test_extfunc.py is not passing tests right now.
      I think this was not caused by this checkin.



Modified: pypy/dist/pypy/translator/llvm2/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm2/genllvm.py	Mon Aug 15 21:29:26 2005
@@ -15,6 +15,10 @@
      extfunctions, gc_boehm, gc_disabled, dependencies
 from pypy.translator.llvm2.node import LLVMNode
 
+#XXX commented out because extfuncs temp. not working
+#from pypy.rpython.module import ll_os, ll_time, ll_math, ll_strtod
+#from pypy.rpython.annlowlevel import annotate_lowlevel_helper
+
 from pypy.translator.translator import Translator
 
 import time
@@ -41,9 +45,20 @@
             func = self.translator.entrypoint
         self.entrypoint = func
 
+        #XXX commented out because extfuncs temp. not working
+        # # make sure helper functions are available
+        # rtyper = self.translator.rtyper
+        # for ptr in (
+        #             #rtyper.annotate_helper(ll_math.ll_frexp_result, [lltype.Float, lltype.Signed]),
+        #             #rtyper.annotate_helper(ll_math.ll_modf_result , [lltype.Float, lltype.Float ]),
+        #             rtyper.annotate_helper(ll_os.ll_stat_result   , [lltype.Signed] * 10),
+        #            ):
+        #     c = inputconst(lltype.typeOf(ptr), ptr)
+        #     self.db.prepare_arg_value(c)
+
         # make sure exception matching and exception type are available
         e = self.translator.rtyper.getexceptiondata()
-        for ll_helper in (e.ll_exception_match,):
+        for ll_helper in (e.ll_exception_match, e.ll_raise_OSError):
             ptr = getfunctionptr(self.translator, ll_helper)
             c = inputconst(lltype.typeOf(ptr), ptr)
             self.db.prepare_arg_value(c)
@@ -166,6 +181,15 @@
         codewriter.append("    ret int %result")
         codewriter.append("}")
         codewriter.newline()
+        # XXX we need to create our own main() that calls the actual entry_point function
+        entryfunc_name = t[1].split('(')[0]
+        if entryfunc_name != 'main' and entryfunc_name == 'entry_point': #XXX just to get on with translate_pypy
+            codewriter.append("int %main() {")
+            codewriter.append("    %argv = call fastcc %structtype.list* %ll_newlist__listPtrConst_Signed.2(int 0)")
+            codewriter.append("    %ret  = call fastcc int %entry_point(%structtype.list* %argv)")
+            codewriter.append("    ret int %ret")
+            codewriter.append("}")
+            codewriter.newline()
 
         comment("End of file") ; nl()
         if self.debug:  print 'gen_llvm_source return) ' + time.ctime()

Modified: pypy/dist/pypy/translator/llvm2/module/ll_math.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/ll_math.py	(original)
+++ pypy/dist/pypy/translator/llvm2/module/ll_math.py	Mon Aug 15 21:29:26 2005
@@ -18,6 +18,12 @@
 declare ccc double %tanh(double)
 declare ccc double %atan2(double,double)
 declare ccc double %fmod(double,double)
+
+%__ll_math_frexp = internal constant [12 x sbyte] c"frexp......\\00"
+%__ll_math_hypot = internal constant [12 x sbyte] c"hypot......\\00"
+%__ll_math_ldexp = internal constant [12 x sbyte] c"ldexp......\\00"
+%__ll_math_modf  = internal constant [12 x sbyte] c"modf.......\\00"
+%__ll_math_pow   = internal constant [12 x sbyte] c"pow........\\00"
 """
 
 extfunctions = {}
@@ -41,37 +47,37 @@
     for function in functions:
         extfunctions["%ll_math_" + function] = ((), simple_function_template % locals())
 
-extfunctions["%ll_math_frexp"] = ((), """
+extfunctions["%ll_math_frexp"] = (("%__debug",), """
 internal fastcc %structtype.tuple2.6* %ll_math_frexp(double %x) {
-    ; XXX: TODO: ll_math_frexp
+    call fastcc void %__debug([12 x sbyte]* %__ll_math_frexp) ; XXX: TODO: ll_math_frexp
     ret %structtype.tuple2.6* null
 }
 """)
 
-extfunctions["%ll_math_hypot"] = ((), """
+extfunctions["%ll_math_hypot"] = (("%__debug",), """
 internal fastcc double %ll_math_hypot(double %x, double %y) {
-    ; XXX: TODO: ll_math_hypot
+    call fastcc void %__debug([12 x sbyte]* %__ll_math_hypot) ; XXX: TODO: ll_math_hypot
     ret double 0.0
 }
 """)
 
-extfunctions["%ll_math_ldexp"] = ((), """
+extfunctions["%ll_math_ldexp"] = (("%__debug",), """
 internal fastcc double %ll_math_ldexp(double %x, int %y) {
-    ; XXX: TODO: ll_math_ldexp
+    call fastcc void %__debug([12 x sbyte]* %__ll_math_ldexp) ; XXX: TODO: ll_math_ldexp
     ret double 0.0
 }
 """)
 
-extfunctions["%ll_math_modf"] = ((), """
-internal fastcc %structtype.tuple2.7* %ll_math_modf(double %x) {
-    ; XXX: TODO: ll_math_modf
-    ret %structtype.tuple2.7* null
+extfunctions["%ll_math_modf"] = (("%__debug",), """
+internal fastcc %structtype.tuple2.9* %ll_math_modf(double %x) {
+    call fastcc void %__debug([12 x sbyte]* %__ll_math_modf) ; XXX: TODO: ll_math_modf
+    ret %structtype.tuple2.9* null
 }
 """)
 
-extfunctions["%ll_math_pow"] = ((), """
+extfunctions["%ll_math_pow"] = (("%__debug",), """
 internal fastcc double %ll_math_pow(double %x, double %y) {
-    ; XXX: TODO: ll_math_pow
+    call fastcc void %__debug([12 x sbyte]* %__ll_math_pow) ; XXX: TODO: ll_math_pow
     ret double 0.0
 }
 """)

Modified: pypy/dist/pypy/translator/llvm2/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/ll_os.py	(original)
+++ pypy/dist/pypy/translator/llvm2/module/ll_os.py	Mon Aug 15 21:29:26 2005
@@ -7,7 +7,17 @@
 declare ccc int %read(int, sbyte*, int)
 declare ccc sbyte* %strncpy(sbyte*, sbyte*, int)
 declare ccc int %isatty(int)
-declare ccc int %fstat(int, int*)
+declare ccc int %stat(sbyte*, [32 x int]*)
+declare ccc int %fstat(int, [32 x int]*)
+
+%errno = external global int
+
+%__ll_os_ftruncate          = internal constant [12 x sbyte] c"ftruncate..\\00"
+%__ll_os_lseek              = internal constant [12 x sbyte] c"lseek......\\00"
+%__ll_os_stat               = internal constant [12 x sbyte] c"stat.......\\00"
+%__ll_os_fstat              = internal constant [12 x sbyte] c"fstat......\\00"
+%__ll_strtod_formatd        = internal constant [12 x sbyte] c"formatd....\\00"
+%__ll_strtod_parts_to_float = internal constant [12 x sbyte] c"parts2flt..\\00"
 """
 
 extfunctions = {}
@@ -71,51 +81,171 @@
 
 """)
 
-extfunctions["%ll_os_fstat"] = ((), """
-internal fastcc %structtype.tuple10* %ll_os_fstat(int %fd) {
-    ;%st = alloca int, uint 32
-    ;%error = call ccc int %fstat(int %fd, int* %st)
-    ;;TODO XXX if error: raise exception
-    ;;%ret = %ll_stat_result__Signed__Signed__Signed__Signed__Signed__Signed__Signed__Signed__Signed__Signed(
-    ;%ret = alloca %structtype.tuple10   ;ERROR
-    ;store int %s
-    ;ret %structtype.tuple10* %ret
-    ret %structtype.tuple10* null
-}
-
-""")
-
-extfunctions["%ll_os_ftruncate"] = ((), """
+extfunctions["%ll_os_ftruncate"] = (("%__debug",), """
 internal fastcc void %ll_os_ftruncate(int %x, int %y) {
-    ; XXX: TODO: ll_os_ftruncate
+    call fastcc void %__debug([12 x sbyte]* %__ll_os_ftruncate) ; XXX: TODO: ll_os_ftruncate
     ret void
 }
 """)
 
-extfunctions["%ll_os_lseek"] = ((), """
+extfunctions["%ll_os_lseek"] = (("%__debug",), """
 internal fastcc int %ll_os_lseek(int %x, int %y, int %z) {
-    ; XXX: TODO: ll_os_lseek
+    call fastcc void %__debug([12 x sbyte]* %__ll_os_lseek) ; XXX: TODO: ll_os_lseek
     ret int 0
 }
 """)
 
-extfunctions["%ll_os_stat"] = ((), """
+"""
+RPySTAT_RESULT* _stat_construct_result_helper(STRUCT_STAT st) {
+    long res0, res1, res2, res3, res4, res5, res6, res7, res8, res9;
+    res0 = (long)st.st_mode; 
+    res1 = (long)st.st_ino; /*XXX HAVE_LARGEFILE_SUPPORT!*/
+    res2 = (long)st.st_dev; /*XXX HAVE_LONG_LONG!*/
+    res3 = (long)st.st_nlink;
+    res4 = (long)st.st_uid;
+    res5 = (long)st.st_gid;
+    res6 = (long)st.st_size; /*XXX HAVE_LARGEFILE_SUPPORT!*/
+    res7 = (long)st.st_atime; /*XXX ignoring quite a lot of things for time here */
+    res8 = (long)st.st_mtime; /*XXX ignoring quite a lot of things for time here */
+    res9 = (long)st.st_ctime; /*XXX ignoring quite a lot of things for time here */
+    /*XXX ignoring BLOCK info here*/
+}
+
+return ll_stat_result(res0, res1, res2, res3, res4,
+    res5, res6, res7, res8, res9);
+}       
+
+RPySTAT_RESULT* LL_os_stat(RPyString * fname) {
+    STRUCT_STAT st;
+    int error = STAT(RPyString_AsString(fname), &st);
+    if (error != 0) {
+        RPYTHON_RAISE_OSERROR(errno);
+        return NULL;
+    }
+    return _stat_construct_result_helper(st);
+}       
+                                                                            
+RPySTAT_RESULT* LL_os_fstat(long fd) {
+    STRUCT_STAT st;
+    int error = FSTAT(fd, &st);
+    if (error != 0) {
+        RPYTHON_RAISE_OSERROR(errno);
+        return NULL;
+    }             
+    return _stat_construct_result_helper(st);
+} 
+"""
+
+extfunctions["%_stat_construct_result_helper"] = ((), """
+internal fastcc %structtype.tuple10* %_stat_construct_result_helper([32 x int]* %src) {
+
+    %src0ptr = getelementptr [32 x int]* %src, int 0, int 4
+    %src1ptr = getelementptr [32 x int]* %src, int 0, int 3
+    %src2ptr = getelementptr [32 x int]* %src, int 0, int 0
+    %src3ptr = getelementptr [32 x int]* %src, int 0, int 5
+    %src4ptr = getelementptr [32 x int]* %src, int 0, int 6
+    %src5ptr = getelementptr [32 x int]* %src, int 0, int 7
+    %src6ptr = getelementptr [32 x int]* %src, int 0, int 11
+    %src7ptr = getelementptr [32 x int]* %src, int 0, int 14
+    %src8ptr = getelementptr [32 x int]* %src, int 0, int 16
+    %src9ptr = getelementptr [32 x int]* %src, int 0, int 18
+
+    %src0 = load int* %src0ptr
+    %src1 = load int* %src1ptr
+    %src2 = load int* %src2ptr
+    %src3 = load int* %src3ptr
+    %src4 = load int* %src4ptr
+    %src5 = load int* %src5ptr
+    %src6 = load int* %src6ptr
+    %src7 = load int* %src7ptr
+    %src8 = load int* %src8ptr
+    %src9 = load int* %src9ptr
+
+    %malloc.Size.1162  = getelementptr %structtype.tuple10* null, uint 1
+    %malloc.SizeU.1162 = cast %structtype.tuple10* %malloc.Size.1162 to uint
+    %malloc.Ptr.1162   = call fastcc sbyte* %gc_malloc_atomic(uint %malloc.SizeU.1162)
+    %dest              = cast sbyte* %malloc.Ptr.1162 to %structtype.tuple10*
+
+    %dest0ptr = getelementptr [32 x int]* %dest, int 0, int 0
+    %dest1ptr = getelementptr [32 x int]* %dest, int 0, int 1
+    %dest2ptr = getelementptr [32 x int]* %dest, int 0, int 2
+    %dest3ptr = getelementptr [32 x int]* %dest, int 0, int 3
+    %dest4ptr = getelementptr [32 x int]* %dest, int 0, int 4
+    %dest5ptr = getelementptr [32 x int]* %dest, int 0, int 5
+    %dest6ptr = getelementptr [32 x int]* %dest, int 0, int 6
+    %dest7ptr = getelementptr [32 x int]* %dest, int 0, int 7
+    %dest8ptr = getelementptr [32 x int]* %dest, int 0, int 8
+    %dest9ptr = getelementptr [32 x int]* %dest, int 0, int 9
+
+    store int %src0, int* %dest0ptr
+    store int %src1, int* %dest1ptr
+    store int %src2, int* %dest2ptr
+    store int %src3, int* %dest3ptr
+    store int %src4, int* %dest4ptr
+    store int %src5, int* %dest5ptr
+    store int %src6, int* %dest6ptr
+    store int %src7, int* %dest7ptr
+    store int %src8, int* %dest8ptr
+    store int %src9, int* %dest9ptr
+
+    ret %structtype.tuple10* %dest
+}
+""")
+
+extfunctions["%ll_os_stat"] = (("%cast", "%__debug", "%_stat_construct_result_helper"), """
 internal fastcc %structtype.tuple10* %ll_os_stat(%structtype.rpy_string* %s) {
-    ; XXX: TODO: ll_os_stat
+
+    call fastcc void %__debug([12 x sbyte]* %__ll_os_stat) ; XXX: Test: ll_os_stat
+
+    %st       = alloca [32 x int]
+    %filename = call fastcc sbyte* %cast(%structtype.rpy_string* %s)
+    %error    = call ccc int %stat(sbyte* %filename, [32 x int]* %st)
+    %cond     = seteq int %error, 0
+    br bool %cond, label %cool, label %bwa
+
+bwa:
+    %errno_ = load int* %errno
+    call fastcc void %ll_raise_OSError__Signed(int %errno_)
+    ret %structtype.tuple10* null
+
+cool:
+    %result = call fastcc %structtype.tuple10* %_stat_construct_result_helper([32 x int]* %st)
+    ret %structtype.tuple10* %result
+}
+""")
+
+extfunctions["%ll_os_fstat"] = (("%__debug",), """
+internal fastcc %structtype.tuple10* %ll_os_fstat(int %fd) {
+
+    call fastcc void %__debug([12 x sbyte]* %__ll_os_fstat) ; XXX: Test: ll_os_fstat
+
+    %st    = alloca [32 x int]
+    %error = call ccc int %fstat(int %fd, [32 x int]* %st)
+    %cond  = seteq int %error, 0
+    br bool %cond, label %cool, label %bwa
+
+bwa:
+    %errno_ = load int* %errno
+    call fastcc void %ll_raise_OSError__Signed(int %errno_)
     ret %structtype.tuple10* null
+
+cool:
+    %result = call fastcc %structtype.tuple10* %_stat_construct_result_helper([32 x int]* %st)
+    ret %structtype.tuple10* %result
 }
+
 """)
 
-extfunctions["%ll_strtod_formatd"] = ((), """
+extfunctions["%ll_strtod_formatd"] = (("%__debug",), """
 internal fastcc %structtype.rpy_string* %ll_strtod_formatd(%structtype.rpy_string* %s, double %x) {
-    ; XXX: TODO: ll_strtod_formatd
+    call fastcc void %__debug([12 x sbyte]* %__ll_strtod_formatd) ; XXX: TODO: ll_strtod_formatd
     ret %structtype.rpy_string* null
 }
 """)
 
-extfunctions["%"] = ((), """
+extfunctions["%ll_strtod_parts_to_float"] = (("%__debug",), """
 internal fastcc double %ll_strtod_parts_to_float(%structtype.rpy_string* s0, %structtype.rpy_string* s1, %structtype.rpy_string* s2, %structtype.rpy_string* s3) {
-    ; XXX: TODO: ll_strtod_parts_to_float
+    call fastcc void %__debug([12 x sbyte]* %__ll_strtod_parts_to_float) ; XXX: TODO: ll_strtod_parts_to_float
     ret double 0.0
 }
 """)

Modified: pypy/dist/pypy/translator/llvm2/module/support.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/support.py	(original)
+++ pypy/dist/pypy/translator/llvm2/module/support.py	Mon Aug 15 21:29:26 2005
@@ -1,11 +1,21 @@
 extdeclarations = """
 declare ccc double %pow(double, double)
 declare ccc double %fmod(double, double)
+declare ccc int %puts(sbyte*)
 """
 
 
 extfunctions = {}
 
+extfunctions["%__debug"] = ((), """
+void %__debug([12 x sbyte]* %msg12) {
+    %msg = getelementptr [12 x sbyte]* %msg12, long 0, long 0
+    call int %puts(sbyte* %msg)
+    ret void
+}
+
+""")
+
 extfunctions["%cast"] = ((), """
 internal fastcc sbyte* %cast(%structtype.rpy_string* %structstring) {
     %source1ptr = getelementptr %structtype.rpy_string* %structstring, int 0, uint 1, uint 1
@@ -15,7 +25,6 @@
 
 """)
 
-
 #abs functions
 extfunctions["%int_abs"] = ((), """
 internal fastcc int %int_abs(int %x) {

Modified: pypy/dist/pypy/translator/llvm2/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_extfunc.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_extfunc.py	Mon Aug 15 21:29:26 2005
@@ -95,28 +95,48 @@
 # following from translator/c/test/test_extfunc.py Revision: 15320 (jul 29th 2005)
 
 def test_os_stat():
-    py.test.skip("ll_os_stat not implemented")
     filename = str(py.magic.autopath())
-    def call_stat(n):
+    def call_stat0():
         st = os.stat(filename)
-        return st[n]
-    f = compile_function(call_stat, [int])
-    assert f(0) == os.stat(filename)[0]
-    assert f(1) == os.stat(filename)[1]
-    assert f(2) == os.stat(filename)[2]
+        return st[0]
+    def call_stat1():
+        st = os.stat(filename)
+        return st[1]
+    def call_stat2():
+        st = os.stat(filename)
+        return st[2]
+    f0 = compile_function(call_stat0, [])
+    f1 = compile_function(call_stat1, [])
+    f2 = compile_function(call_stat2, [])
+    st = os.stat(filename)
+    assert f0() == st[0]
+    assert f1() == st[1]
+    assert f2() == st[2]
 
 def test_os_fstat():
-    py.test.skip("ll_os_fstat not implemented")
     filename = str(py.magic.autopath())
-    def call_fstat(n):
+    def call_fstat0():
+        fd = os.open(filename, os.O_RDONLY, 0777)
+        st = os.fstat(fd)
+        os.close(fd)
+        return st[0]
+    def call_fstat1():
+        fd = os.open(filename, os.O_RDONLY, 0777)
+        st = os.fstat(fd)
+        os.close(fd)
+        return st[1]
+    def call_fstat2():
         fd = os.open(filename, os.O_RDONLY, 0777)
         st = os.fstat(fd)
         os.close(fd)
-        return st[0]    #XXX want to use 0 here!
-    f = compile_function(call_fstat, [int])
-    assert f(0) == os.stat(filename)[0]
-    assert f(1) == os.stat(filename)[1]
-    assert f(2) == os.stat(filename)[2]
+        return st[2]
+    f0 = compile_function(call_fstat0, [])
+    f1 = compile_function(call_fstat1, [])
+    f2 = compile_function(call_fstat2, [])
+    st = os.stat(filename)
+    assert f0() == st[0]
+    assert f1() == st[1]
+    assert f2() == st[2]
 
 def test_getcwd():
     py.test.skip("ll_os_getcwd not implemented")
@@ -164,7 +184,6 @@
         yield math_function_test, funcname
 
 def test_os_path_exists():
-    py.test.skip("ll_os_stat not implemented")
     tmpfile = str(udir.join('test_os_path_exists.TMP'))
     def fn():
         return os.path.exists(tmpfile)
@@ -175,7 +194,6 @@
     assert f() == False
 
 def test_os_path_isdir():
-    py.test.skip("ll_os_stat not implemented")
     directory = "./."
     def fn():
         return os.path.isdir(directory)



More information about the Pypy-commit mailing list