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

ericvrp at codespeak.net ericvrp at codespeak.net
Thu Aug 18 10:54:51 CEST 2005


Author: ericvrp
Date: Thu Aug 18 10:54:50 2005
New Revision: 16128

Modified:
   pypy/dist/pypy/translator/llvm2/genllvm.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:
refactoring: moving %main(..) out of genllvm.py


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 18 10:54:50 2005
@@ -168,24 +168,6 @@
         for typ_decl in self.db.getnodes():
             typ_decl.writeimpl(codewriter)
 
-        if self.debug:  print 'gen_llvm_source used_external_functions) ' + time.ctime()
-        depdone = {}
-        for funcname,value in extfuncnode.ExternalFuncNode.used_external_functions.iteritems():
-            deps = dependencies(funcname,[])
-            deps.reverse()
-            for dep in deps:
-                if dep not in depdone:
-                    try:
-                        llvm_code = extfunctions[dep][1]
-                    except KeyError:
-                        msg = 'primitive function %s has no implementation' % dep
-                        codewriter.comment('XXX: Error: ' + msg)
-                        #raise Exception('primitive function %s has no implementation' %(dep,))
-                        continue
-                    for extfunc in llvm_code.split('\n'):
-                        codewriter.append(extfunc)
-                    depdone[dep] = True
-
         if self.debug:  print 'gen_llvm_source entrypoint) ' + time.ctime()
         #XXX use codewriter methods here
         decl = self.entrynode.getdecl()
@@ -217,30 +199,25 @@
         # 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(int %argc, sbyte** %argv) {")
-            codewriter.append("entry:")
-            codewriter.append("    %pypy_argv = call fastcc %RPyListOfString* %ll_newlist__listPtrConst_Signed.2(int 0)")
-            codewriter.append("    br label %no_exit")
-            codewriter.newline()
-            codewriter.append("no_exit:")
-            codewriter.append("    %indvar = phi uint [ %indvar.next, %no_exit ], [ 0, %entry ]")
-            codewriter.append("    %i.0.0 = cast uint %indvar to int")
-            codewriter.append("    %tmp.8 = getelementptr sbyte** %argv, uint %indvar")
-            codewriter.append("    %tmp.9 = load sbyte** %tmp.8")
-            codewriter.newline()
-            codewriter.append("    %rpy = call fastcc %RPyString* %string_to_RPyString(sbyte* %tmp.9)")
-            codewriter.append("    call fastcc void %ll_append__listPtr_rpy_stringPtr(%RPyListOfString* %pypy_argv, %RPyString* %rpy)")
-            codewriter.newline()
-            codewriter.append("    %inc = add int %i.0.0, 1")
-            codewriter.append("    %tmp.2 = setlt int %inc, %argc")
-            codewriter.append("    %indvar.next = add uint %indvar, 1")
-            codewriter.append("    br bool %tmp.2, label %no_exit, label %loopexit")
-            codewriter.append("loopexit:")
-            codewriter.newline()
-            codewriter.append("    %ret  = call fastcc int %entry_point(%structtype.list* %pypy_argv)")
-            codewriter.append("    ret int %ret")
-            codewriter.append("}")
-            codewriter.newline()
+            extfuncnode.ExternalFuncNode.used_external_functions['%main'] = True
+
+        if self.debug:  print 'gen_llvm_source used_external_functions) ' + time.ctime()
+        depdone = {}
+        for funcname,value in extfuncnode.ExternalFuncNode.used_external_functions.iteritems():
+            deps = dependencies(funcname,[])
+            deps.reverse()
+            for dep in deps:
+                if dep not in depdone:
+                    try:
+                        llvm_code = extfunctions[dep][1]
+                    except KeyError:
+                        msg = 'primitive function %s has no implementation' % dep
+                        codewriter.comment('XXX: Error: ' + msg)
+                        #raise Exception('primitive function %s has no implementation' %(dep,))
+                        continue
+                    for extfunc in llvm_code.split('\n'):
+                        codewriter.append(extfunc)
+                    depdone[dep] = True
 
         comment("End of file") ; nl()
         if self.debug:  print 'gen_llvm_source return) ' + time.ctime()

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	Thu Aug 18 10:54:50 2005
@@ -15,9 +15,6 @@
 
 %errno = external global int
 
-%__print_debug_info         = internal global bool false
-%__print_debug_info_option  = internal constant [19 x sbyte] c"--print-debug-info\\00"
-
 %__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"

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	Thu Aug 18 10:54:50 2005
@@ -4,6 +4,9 @@
 declare ccc int %puts(sbyte*)
 declare ccc int %strlen(sbyte*)
 declare ccc int %strcmp(sbyte*, sbyte*)
+
+%__print_debug_info         = internal global bool false
+%__print_debug_info_option  = internal constant [19 x sbyte] c"--print-debug-info\\00"
 """
 
 
@@ -12,13 +15,13 @@
 extfunctions["%__debug"] = ((), """
 internal fastcc void %__debug([12 x sbyte]* %msg12) {
     %cond = load bool* %__print_debug_info
-    br bool %__print_debug_info, label %print_it, label %do_nothing
+    br bool %cond, label %print_it, label %do_nothing
 
 do_nothing:
     ret void
     
 print_it:
-    %msg = getelementptr [12 x sbyte]* %msg12, long 0, long 0
+    %msg = getelementptr [12 x sbyte]* %msg12, int 0, int 0
     call int %puts(sbyte* %msg)
     ret void
 }
@@ -234,3 +237,42 @@
     ret int %%t
 }
 """ % locals())
+
+extfunctions["%main"] = (("%string_to_RPyString"), """
+int %main(int %argc, sbyte** %argv) {
+entry:
+    %pypy_argv = call fastcc %RPyListOfString* %ll_newlist__listPtrConst_Signed.2(int 0)
+    br label %no_exit
+
+no_exit:
+    %indvar = phi uint [ %indvar.next, %next_arg ], [ 0, %entry ]
+    %i.0.0 = cast uint %indvar to int
+    %tmp.8 = getelementptr sbyte** %argv, uint %indvar
+    %tmp.9 = load sbyte** %tmp.8
+
+    %t    = getelementptr [19 x sbyte]* %__print_debug_info_option, int 0, int 0
+    %res  = call ccc int %strcmp(sbyte* %tmp.9, sbyte* %t)
+    %cond = seteq int %res, 0
+    br bool %cond, label %debugging, label %not_debugging
+
+debugging:
+    store bool true, bool* %__print_debug_info
+    br label %next_arg
+
+not_debugging:
+    %rpy = call fastcc %RPyString* %string_to_RPyString(sbyte* %tmp.9)
+    call fastcc void %ll_append__listPtr_rpy_stringPtr(%RPyListOfString* %pypy_argv, %RPyString* %rpy)
+    br label %next_arg
+
+next_arg:
+    %inc = add int %i.0.0, 1
+    %tmp.2 = setlt int %inc, %argc
+    %indvar.next = add uint %indvar, 1
+    br bool %tmp.2, label %no_exit, label %loopexit
+
+loopexit:
+
+    %ret  = call fastcc int %entry_point(%structtype.list* %pypy_argv)
+    ret int %ret
+}
+""")

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	Thu Aug 18 10:54:50 2005
@@ -193,7 +193,7 @@
     os.unlink(tmpfile)
     assert f() == False
 
-def test_os_path_exists2():
+def test_dynamic_string_null_termination():
     # forces malloc / versus pbc for NUL testing of C string
     tmpfile = str(udir.join('test_os_path_exists.TMP'))
     def fn(l):



More information about the Pypy-commit mailing list