[pypy-svn] r29693 - in pypy/dist/pypy/translator/llvm/pyllvm: . test

simonb at codespeak.net simonb at codespeak.net
Thu Jul 6 18:24:43 CEST 2006


Author: simonb
Date: Thu Jul  6 18:24:39 2006
New Revision: 29693

Added:
   pypy/dist/pypy/translator/llvm/pyllvm/test/addnumbers.ll
      - copied unchanged from r29680, pypy/dist/pypy/translator/llvm/pyllvm/test/addnumbers.s
   pypy/dist/pypy/translator/llvm/pyllvm/test/hello.ll
      - copied unchanged from r29680, pypy/dist/pypy/translator/llvm/pyllvm/test/hello.s
Removed:
   pypy/dist/pypy/translator/llvm/pyllvm/test/addnumbers.s
   pypy/dist/pypy/translator/llvm/pyllvm/test/hello.s
Modified:
   pypy/dist/pypy/translator/llvm/pyllvm/pyllvm.py
   pypy/dist/pypy/translator/llvm/pyllvm/test/test_ee.py
Log:
asserting that ExecutionEngine is a singleton. (simon and eric)

Modified: pypy/dist/pypy/translator/llvm/pyllvm/pyllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/pyllvm/pyllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/pyllvm/pyllvm.py	Thu Jul  6 18:24:39 2006
@@ -17,14 +17,15 @@
             M = Module()
         self.instance = ExistingModuleProvider__init__(M.instance)
 
-global ee_hack
+ee_hack = None
 
 class ExecutionEngine(Wrapper):
     def __init__(self, MP=None, ForceInterpreter=False):
+        global ee_hack
+        assert ee_hack is None, "can only make one ExecutionEngine"
         if not MP:
             MP = ExistingModuleProvider();
         self.instance = ExecutionEngine__create__(MP.instance, ForceInterpreter)
-        global ee_hack
         ee_hack = self.instance #XXX how to get to the executionengine from a function?
 
     # XXX cast to actual Python Module (can't we automate this?)
@@ -61,7 +62,7 @@
         llvmvalues = ParamType()
         for i, arg in enumerate(args):
             llvmvalues[i] = to_llvm_value(arg, ft.getParamType(i)).LongVal
-        pLlvmValues = cast(llvmvalues, c_void_p) #would like to cast to c_longlong_p
+        pLlvmValues = cast(llvmvalues, c_void_p)
         llvmreturnvalue = ExecutionEngine_runFunction(ee_hack, self.instance, pLlvmValues)
         return to_python_value(llvmreturnvalue, ft.getReturnType())
 

Modified: pypy/dist/pypy/translator/llvm/pyllvm/test/test_ee.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/pyllvm/test/test_ee.py	(original)
+++ pypy/dist/pypy/translator/llvm/pyllvm/test/test_ee.py	Thu Jul  6 18:24:39 2006
@@ -1,8 +1,8 @@
 import py
 from pypy.translator.llvm.buildllvm import llvm_is_on_path
-if not llvm_is_on_path():
-    py.test.skip("llvm not found")
-py.test.skip('aborts with SIGIOT on the snake machine :-(')
+#if not llvm_is_on_path():
+#    py.test.skip("llvm not found")
+#py.test.skip('aborts with SIGIOT on the snake machine :-(')
 
 try:
     from pypy.translator.llvm.pyllvm import pyllvm
@@ -11,26 +11,26 @@
 
 from pypy.translator.llvm.pyllvm.test import ll_snippet
 
-
-def test_execution_engine():
-    ee = pyllvm.ExecutionEngine()
-    ee = pyllvm.ExecutionEngine()
-    ee = pyllvm.ExecutionEngine()
-    del ee  #XXX not actualy deleted at the moment!!!
-    ee2 = pyllvm.ExecutionEngine()
-    ee2 = pyllvm.ExecutionEngine()
-    ee2 = pyllvm.ExecutionEngine()
+ee = None
+def make_execution_engine():
+    global ee
+    if ee is None:
+        ee = pyllvm.ExecutionEngine()
+
+def test_execution_engine_singleton():
+    make_execution_engine()
+    py.test.raises(AssertionError, pyllvm.ExecutionEngine)
 
 codepath = py.path.local(__file__).dirpath()
 
 def test_load():
-    ee = pyllvm.ExecutionEngine()
-    ee.parse(codepath.join("hello.s").read())
-    ee.parse(codepath.join("addnumbers.s").read())
+    make_execution_engine()
+    ee.parse(codepath.join("hello.ll").read())
+    ee.parse(codepath.join("addnumbers.ll").read())
 
 def test_functions():
-    ee = pyllvm.ExecutionEngine()
-    ee.parse(codepath.join("hello.s").read())
+    make_execution_engine()
+    ee.parse(codepath.join("hello.ll").read())
     mod = ee.getModule()
     assert mod.n_functions() == 2
     #TODO
@@ -44,8 +44,8 @@
     py.test.raises(Exception, mod.n_functions, "string")
 
 def test_call_parse_once():
-    ee = pyllvm.ExecutionEngine()
-    ee.parse(codepath.join("hello.s").read())
+    make_execution_engine()
+    ee.parse(codepath.join("hello.ll").read())
     f = ee.getModule().getNamedFunction
     hello = f("hello")
     gethellostr = f("gethellostr")
@@ -54,12 +54,12 @@
 
 def test_call_parse_twice():
     py.test.skip("WIP")
-    ee = pyllvm.ExecutionEngine()
-    ee.parse(codepath.join("hello.s").read())
+    make_execution_engine()
+    ee.parse(codepath.join("hello.ll").read())
     f = ee.getModule().getNamedFunction
     f1 = f("gethellostr")
     assert f1() == "hello world\n"
-    ee.parse(codepath.join("addnumbers.s").read())
+    ee.parse(codepath.join("addnumbers.ll").read())
     f2 = f("add")
     assert f2(10, 32) == 42
     assert f1() == "hello world\n"
@@ -72,7 +72,7 @@
     the function at execution time. Not sure if we really need this
     particular feature. It appears that 'calc' requires a forward
     declaration to add1 otherwise a segfault will occur!"""
-    ee = pyllvm.ExecutionEngine()
+    make_execution_engine()
     ee.parse(ll_snippet.calc)
     ee.parse(ll_snippet.add1)
     f = ee.getModule().getNamedFunction
@@ -84,7 +84,7 @@
     """similar to test_call_between_parsed_code with additional complexity
     because we rebind the add1 function to another version after it the
     first version already has been used."""
-    ee = pyllvm.ExecutionEngine()
+    make_execution_engine()
     ee.parse(ll_snippet.calc)
     ee.parse(ll_snippet.add1)
     f = ee.getModule().getNamedFunction
@@ -95,7 +95,7 @@
     assert f("calc")(142) == 242
 
 def test_share_data_between_parsed_code():
-    ee = pyllvm.ExecutionEngine()
+    make_execution_engine()
     ee.parse(ll_snippet.global_int_a_is_100)
     ee.parse(ll_snippet.add1_to_global_int_a)
     ee.parse(ll_snippet.sub10_from_global_int_a)
@@ -108,7 +108,7 @@
 def test_native_code(): #examine JIT generate native (assembly) code
     py.test.skip("WIP")
     pyllvm.toggle_print_machineinstrs()
-    ee = pyllvm.ExecutionEngine()
+    make_execution_engine()
     ee.parse(ll_snippet.calc)
     ee.parse(ll_snippet.add1)
     f = ee.getModule().getNamedFunction
@@ -117,7 +117,7 @@
 
 def test_delete_function(): #this will only work if nothing uses Fn of course!
     py.test.skip("WIP")
-    ee = pyllvm.ExecutionEngine()
+    make_execution_engine()
     mod = ee.getModule()
     ee.parse(ll_snippet.calc)
     ee.parse(ll_snippet.add1)



More information about the Pypy-commit mailing list