[pypy-svn] r15551 - pypy/dist/pypy/translator/llvm2/demo

rxe at codespeak.net rxe at codespeak.net
Wed Aug 3 14:09:29 CEST 2005


Author: rxe
Date: Wed Aug  3 14:09:25 2005
New Revision: 15551

Added:
   pypy/dist/pypy/translator/llvm2/demo/__init__.py
   pypy/dist/pypy/translator/llvm2/demo/run.py
Modified:
   pypy/dist/pypy/translator/llvm2/demo/   (props changed)
   pypy/dist/pypy/translator/llvm2/demo/bpnn.py   (contents, props changed)
   pypy/dist/pypy/translator/llvm2/demo/richards.py   (contents, props changed)
Log:
Refactor interface.


Added: pypy/dist/pypy/translator/llvm2/demo/__init__.py
==============================================================================

Modified: pypy/dist/pypy/translator/llvm2/demo/bpnn.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/demo/bpnn.py	(original)
+++ pypy/dist/pypy/translator/llvm2/demo/bpnn.py	Wed Aug  3 14:09:25 2005
@@ -245,40 +245,5 @@
     return 0
     
 if __name__ == "__main__":
-    from pypy.translator.llvm2.genllvm import compile_function
-    import py
-
-    import sys
-    compile_llvm = True
-    if len(sys.argv) > 1:
-        if sys.argv[1] == "p":
-            main()
-            compile_llvm = False
-        elif sys.argv[1] == "c":
-
-            from pypy.translator.translator import Translator
-            t = Translator(main)    
-            a = t.annotate([])            
-            t.specialize()    
-            f = t.ccompile()
-            f()
-
-            compile_llvm = False
-
-    if compile_llvm:
-        compile_function(main, [])    
-
-        # generate runnable bytecode with the following command
-        os.write(1, 'Generating standalone LLVM bytecode:\n')
-        cmd = "llvmc -O5 -Tasm=-enable-correct-eh-support -v -L /usr/lib/ -lm -lgc /tmp/usession-current/main_optimized.bc -o bpnn"
-        os.write(1, cmd + '\n')
-        os.system(cmd)
-
-        # run with the following command
-        os.write(1, 'Running standalone LLVM bytecode:\n')
-        cmd = "./bpnn"
-        os.write(1, cmd + '\n')
-        os.system(cmd)
-
-    os.write(1, 'Running on top of CPython:\n')
-    main()
+    from pypy.translator.llvm2.demo.run import run
+    run(main, "bpnn")

Modified: pypy/dist/pypy/translator/llvm2/demo/richards.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/demo/richards.py	(original)
+++ pypy/dist/pypy/translator/llvm2/demo/richards.py	Wed Aug  3 14:09:25 2005
@@ -1,3 +1,5 @@
+import os
+
 
 # based on a Java version:
 #  Based on original version written in BCPL by Dr Martin Richards
@@ -127,8 +129,6 @@
 
 
 
-
-
 tracing = False
 layout = 0
 
@@ -344,8 +344,6 @@
 
 import time
 
-
-
 def schedule():
     t = taskWorkArea.taskList
     while t is not None:
@@ -392,21 +390,25 @@
             schedule()
 
             if taskWorkArea.holdCount == 9297 and taskWorkArea.qpktCount == 23246:
-                pass
+                os.write(1, "iteration %d\n" % i)
             else:
                 return False
 
         return True
 
+class FailedRun(Exception):
+    pass
+
 def entry_point():
     r = Richards()
+    if not r:
+        raise FailedRun
     startTime = time.time()
     result = r.run()
     endTime = time.time()
     return result, startTime, endTime
 
 def main():
-    import os
     os.write(1, "Richards benchmark (Python) starting... \n")
     result, startTime, endTime = entry_point()
     if not result:
@@ -419,28 +421,5 @@
     return 0
 
 if __name__ == "__main__":
-    from pypy.translator.llvm2.genllvm import compile_function
-    import py
-
-    import sys
-    compile_llvm = True
-    if len(sys.argv) > 1:
-        if sys.argv[1] == "p":
-            main()
-            compile_llvm = False
-        elif sys.argv[1] == "c":
-
-            from pypy.translator.translator import Translator
-            t = Translator(main)    
-            a = t.annotate([])            
-            t.specialize()    
-            f = t.ccompile()
-            f()
-
-            compile_llvm = False
-
-    if compile_llvm:
-        compile_function(main, [])    
-
-        # run with the following command
-        "llvmc -Tasm=-enable-correct-eh-support -v -L /usr/lib/ -lm -lgc main_optimized.bc -o go"
+    from pypy.translator.llvm2.demo.run import run
+    run(main, "richards")

Added: pypy/dist/pypy/translator/llvm2/demo/run.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm2/demo/run.py	Wed Aug  3 14:09:25 2005
@@ -0,0 +1,54 @@
+import py
+import os
+import sys
+
+from pypy.translator.llvm2.genllvm import compile_function
+from pypy.translator.translator import Translator
+
+def p():
+    print 'Running on top of CPython:'
+    entry_point()
+
+def c():
+    print "Running genc'd version on top of CPython:"
+    t = Translator(entry_point)    
+    a = t.annotate([])
+    t.specialize()
+    f = t.ccompile()
+    f()
+
+def l(name):
+    compile_function(entry_point, [])
+
+    # generate runnable bytecode with the following command
+    print 'Generating standalone LLVM bytecode:'
+    cmd = "llvmc -O5 -Tasm=-enable-correct-eh-support -v -L /usr/lib/ -lm -lgc /tmp/usession-current/main_optimized.bc -o %s" % name
+    print cmd
+    os.system(cmd)
+
+    # run with the following command
+    print 'Running standalone LLVM bytecode:'
+    cmd = "./%s" % name
+    print cmd
+    os.system(cmd)
+
+def run(ep, name="go"):
+    global entry_point
+    entry_point = ep
+    
+    run_all = True
+    if len(sys.argv) > 1:
+        if sys.argv[1] == "p":
+            c()
+            run_all = False
+        elif sys.argv[1] == "c":
+            c()
+            run_all = False
+        elif sys.argv[1] == "l":
+            l(name)
+            run_all = False
+            
+    if run_all:
+        l(name)
+        c()
+        p()



More information about the Pypy-commit mailing list