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

ericvrp at codespeak.net ericvrp at codespeak.net
Tue Aug 16 12:38:47 CEST 2005


Author: ericvrp
Date: Tue Aug 16 12:38:45 2005
New Revision: 16098

Modified:
   pypy/dist/pypy/translator/llvm2/arraynode.py
   pypy/dist/pypy/translator/llvm2/build_llvm_module.py
   pypy/dist/pypy/translator/llvm2/codewriter.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:
* some cleaning up (mostly malloc output)

* added external function ll_getcwd and str->rpystring casting



Modified: pypy/dist/pypy/translator/llvm2/arraynode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/arraynode.py	(original)
+++ pypy/dist/pypy/translator/llvm2/arraynode.py	Tue Aug 16 12:38:45 2005
@@ -3,11 +3,8 @@
 from pypy.translator.llvm2.log import log
 from pypy.translator.llvm2.node import LLVMNode, ConstantLLVMNode
 from pypy.translator.llvm2 import varsize 
-import itertools
 log = log.structnode
 
-nextnum = itertools.count().next
-
 class ArrayTypeNode(LLVMNode):
     def __init__(self, db, array):
         assert isinstance(array, lltype.Array)
@@ -20,7 +17,6 @@
         # for the array type in llvm source code 
         # constructor_decl is used to declare the constructor
         # for the array type (see writeimpl)
-        c = nextnum()
         name = ""        
         if isinstance(arraytype, lltype.Ptr):
             name += "ptr_"

Modified: pypy/dist/pypy/translator/llvm2/build_llvm_module.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/build_llvm_module.py	(original)
+++ pypy/dist/pypy/translator/llvm2/build_llvm_module.py	Tue Aug 16 12:38:45 2005
@@ -13,12 +13,8 @@
 from pypy.translator.llvm2.genllvm import use_boehm_gc
 from pypy.translator.llvm2.log import log
 
-class CompileError(exceptions.Exception):
-    pass
-
-SOURCES = "time.ii ".split()
-
-EXCEPTIONS_SWITCHES   = "-enable-correct-eh-support --regalloc iterativescan"
+EXCEPTIONS_SWITCHES   = "-enable-correct-eh-support"
+#--regalloc iterativescan" #unstable (http://llvm.cs.uiuc.edu/docs/ReleaseNotes.html)
 
 OPTIMIZATION_SWITCHES = (" ".join([
 

Modified: pypy/dist/pypy/translator/llvm2/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/codewriter.py	(original)
+++ pypy/dist/pypy/translator/llvm2/codewriter.py	Tue Aug 16 12:38:45 2005
@@ -9,7 +9,6 @@
         self.f = f
         self.show_line_numbers = show_line_number
         self.n_lines = 0
-        self.count = count().next
 
     def append(self, line): 
         self.n_lines += 1
@@ -70,6 +69,7 @@
                     % (intty, cond, defaultdest, labels))
 
     def openfunc(self, decl, is_entrynode=False): 
+        self.malloc_count = count(0).next
         self.newline()
         if is_entrynode:
             linkage_type = ''
@@ -127,12 +127,16 @@
                         "%(fromvar)s to %(targettype)s" % locals())
 
     def malloc(self, targetvar, type_, size=1, atomic=False):
-        cnt = self.count()
+        n = self.malloc_count()
+        if n:
+            cnt = ".%d" % n
+        else:
+            cnt = ""
         postfix = ('', '_atomic')[atomic]
-        self.indent("%%malloc.Size.%(cnt)d = getelementptr %(type_)s* null, uint %(size)s" % locals())
-        self.indent("%%malloc.SizeU.%(cnt)d = cast %(type_)s* %%malloc.Size.%(cnt)d to uint" % locals())
-        self.indent("%%malloc.Ptr.%(cnt)d = call fastcc sbyte* %%gc_malloc%(postfix)s(uint %%malloc.SizeU.%(cnt)d)" % locals())
-        self.indent("%(targetvar)s = cast sbyte* %%malloc.Ptr.%(cnt)d to %(type_)s*" % locals())
+        self.indent("%%malloc.Size%(cnt)s = getelementptr %(type_)s* null, uint %(size)s" % locals())
+        self.indent("%%malloc.SizeU%(cnt)s = cast %(type_)s* %%malloc.Size%(cnt)s to uint" % locals())
+        self.indent("%%malloc.Ptr%(cnt)s = call fastcc sbyte* %%gc_malloc%(postfix)s(uint %%malloc.SizeU%(cnt)s)" % locals())
+        self.indent("%(targetvar)s = cast sbyte* %%malloc.Ptr%(cnt)s to %(type_)s*" % locals())
 
     def getelementptr(self, targetvar, type, typevar, *indices):
         res = "%(targetvar)s = getelementptr %(type)s %(typevar)s, int 0, " % locals()

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	Tue Aug 16 12:38:45 2005
@@ -6,14 +6,17 @@
 declare ccc int %write(int, sbyte*, int)
 declare ccc int %read(int, sbyte*, int)
 declare ccc sbyte* %strncpy(sbyte*, sbyte*, int)
+declare ccc int %strlen(sbyte*)
 declare ccc int %isatty(int)
 declare ccc int %stat(sbyte*, [32 x int]*)
 declare ccc int %fstat(int, [32 x int]*)
 declare ccc int %lseek(int, int, int)
 declare ccc int %ftruncate(int, int)
+declare ccc sbyte* %getcwd(sbyte*, int)
 
 %errno = external global int
 
+%__ll_os_getcwd             = internal constant [12 x sbyte] c"getcwd.....\\00"
 %__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"
@@ -32,6 +35,21 @@
 
 """)
 
+extfunctions["%ll_os_getcwd"] = (("%string_to_RPyString", "%__debug"), """
+internal fastcc %RPyString* %ll_os_getcwd() {
+
+    call fastcc void %__debug([12 x sbyte]* %__ll_os_getcwd) ; XXX: Test: ll_os_getcwd
+
+    %s = alloca sbyte, uint 1024
+    %res = call ccc sbyte* %getcwd(sbyte* %s, int 1023)
+    ;if %res == null: raise...
+
+    %cwd = call fastcc %RPyString* %string_to_RPyString(sbyte* %s)
+    ret %RPyString* %cwd
+}
+
+""")
+
 extfunctions["%ll_os_close"] = ((), """
 internal fastcc void %ll_os_close(int %fd) {
     call ccc void %close(int %fd)
@@ -102,60 +120,19 @@
 }
 """)
 
-"""
-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 %RPySTAT_RESULT* %_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
+    %src0ptr = getelementptr [32 x int]* %src, int 0, uint 4    ;st_mode
+    %src1ptr = getelementptr [32 x int]* %src, int 0, uint 3    ;st_ino
+    %src2ptr = getelementptr [32 x int]* %src, int 0, uint 0    ;st_dev
+    %src3ptr = getelementptr [32 x int]* %src, int 0, uint 5    ;st_nlink
+    %src4ptr = getelementptr [32 x int]* %src, int 0, uint 6    ;st_uid
+    %src5ptr = getelementptr [32 x int]* %src, int 0, uint 7    ;st_gid
+    %src6ptr = getelementptr [32 x int]* %src, int 0, uint 11   ;st_size
+    %src7ptr = getelementptr [32 x int]* %src, int 0, uint 14   ;st_atime
+    %src8ptr = getelementptr [32 x int]* %src, int 0, uint 16   ;st_mtime
+    %src9ptr = getelementptr [32 x int]* %src, int 0, uint 18   ;st_ctime
 
     %src0 = load int* %src0ptr
     %src1 = load int* %src1ptr
@@ -168,10 +145,10 @@
     %src8 = load int* %src8ptr
     %src9 = load int* %src9ptr
 
-    %malloc.Size.1162  = getelementptr %RPySTAT_RESULT* null, uint 1
-    %malloc.SizeU.1162 = cast %RPySTAT_RESULT* %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 %RPySTAT_RESULT*
+    %malloc.Size  = getelementptr %RPySTAT_RESULT* null, uint 1
+    %malloc.SizeU = cast %RPySTAT_RESULT* %malloc.Size to uint
+    %malloc.Ptr   = call fastcc sbyte* %gc_malloc_atomic(uint %malloc.SizeU)
+    %dest         = cast sbyte* %malloc.Ptr to %RPySTAT_RESULT*
 
     %dest0ptr = getelementptr %RPySTAT_RESULT* %dest, int 0, uint 0
     %dest1ptr = getelementptr %RPySTAT_RESULT* %dest, int 0, uint 1

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	Tue Aug 16 12:38:45 2005
@@ -25,6 +25,20 @@
 
 """)
 
+extfunctions["%string_to_RPyString"] = ((), """
+internal fastcc %RPyString* %string_to_RPyString(sbyte* %s) {
+    %len       = call ccc int %strlen(sbyte* %s)
+    %rpy       = call fastcc %RPyString* %RPyString_New__Signed(int %len)
+    %rpystrptr = getelementptr %RPyString* %rpy, int 0, uint 1, uint 1
+    %rpystr    = cast [0 x sbyte]* %rpystrptr to sbyte*
+
+    call ccc sbyte* %strncpy(sbyte* %rpystr, sbyte* %s, int %len)
+
+    ret %RPyString* %rpy
+}
+
+""")
+
 #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	Tue Aug 16 12:38:45 2005
@@ -138,13 +138,12 @@
     assert f1() == st[1]
     assert f2() == st[2]
 
-def test_getcwd():
-    py.test.skip("ll_os_getcwd not implemented")
+def test_os_getcwd():
+    cwd = os.getcwd()
     def does_stuff():
-        return os.getcwd()
+        return os.getcwd() == cwd
     f1 = compile_function(does_stuff, [])
-    res = f1()
-    assert res == os.getcwd()
+    assert f1()
 
 def test_math_frexp():
     py.test.skip("ll_math_frexp not implemented")



More information about the Pypy-commit mailing list