[pypy-svn] r16749 - in pypy/release/0.7.x/pypy/translator/llvm: . module test

ericvrp at codespeak.net ericvrp at codespeak.net
Sat Aug 27 14:01:37 CEST 2005


Author: ericvrp
Date: Sat Aug 27 14:01:36 2005
New Revision: 16749

Modified:
   pypy/release/0.7.x/pypy/translator/llvm/genllvm.py
   pypy/release/0.7.x/pypy/translator/llvm/module/support.py
   pypy/release/0.7.x/pypy/translator/llvm/test/test_exc_operation.py
Log:
simplified module/support.py

removed test skipping


Modified: pypy/release/0.7.x/pypy/translator/llvm/genllvm.py
==============================================================================
--- pypy/release/0.7.x/pypy/translator/llvm/genllvm.py	(original)
+++ pypy/release/0.7.x/pypy/translator/llvm/genllvm.py	Sat Aug 27 14:01:36 2005
@@ -318,6 +318,7 @@
 
         for f in "prepare_and_raise_OverflowError prepare_and_raise_ValueError "\
 	         "prepare_and_raise_ZeroDivisionError prepare_and_raise_IOError "\
+                 "prepare_ZeroDivisionError prepare_OverflowError prepare_ValueError "\
 		 "RPyString_FromString RPyString_AsString RPyString_Size".split():
             extfuncnode.ExternalFuncNode.used_external_functions["%" + f] = True
 

Modified: pypy/release/0.7.x/pypy/translator/llvm/module/support.py
==============================================================================
--- pypy/release/0.7.x/pypy/translator/llvm/module/support.py	(original)
+++ pypy/release/0.7.x/pypy/translator/llvm/module/support.py	Sat Aug 27 14:01:36 2005
@@ -5,31 +5,12 @@
 declare ccc int %strcmp(sbyte*, sbyte*)
 declare ccc sbyte* %memset(sbyte*, int, uint)
 declare ccc sbyte* %strncpy(sbyte *, sbyte *, int)
-
-%__print_debug_info         = internal global bool false
-%__print_debug_info_option  = internal constant [19 x sbyte] c"--print-debug-info\\00"
 """
 
 
 extfunctions = {}
 
-extfunctions["%__debug"] = ((), """
-internal fastcc void %__debug([12 x sbyte]* %msg12) {
-    %cond = load bool* %__print_debug_info
-    br bool %cond, label %print_it, label %do_nothing
-
-do_nothing:
-    ret void
-    
-print_it:
-    %msg = getelementptr [12 x sbyte]* %msg12, int 0, int 0
-    call int %puts(sbyte* %msg)
-    ret void
-}
-
-""")
-
-extfunctions["%RPyString_AsString"] = (("%RPyString_FromString",), """
+extfunctions["%RPyString_AsString"] = ((), """
 internal fastcc sbyte* %RPyString_AsString(%RPyString* %structstring) {
     %source1ptr = getelementptr %RPyString* %structstring, int 0, uint 1, uint 1
     %source1 = cast [0 x sbyte]* %source1ptr to sbyte*
@@ -97,8 +78,8 @@
 
 #prepare exceptions
 for exc in "ZeroDivisionError OverflowError ValueError".split():    #_ZER _OVF _VAL
-    extfunctions["%%__prepare_%(exc)s" % locals()] = ((), """
-internal fastcc void %%__prepare_%(exc)s() {
+    extfunctions["%%prepare_%(exc)s" % locals()] = ((), """
+internal fastcc void %%prepare_%(exc)s() {
     %%exception_value = call fastcc %%RPYTHON_EXCEPTION* %%pypy_instantiate_%(exc)s()
     %%tmp             = getelementptr %%RPYTHON_EXCEPTION* %%exception_value, int 0, uint 0
     %%exception_type  = load %%RPYTHON_EXCEPTION_VTABLE** %%tmp
@@ -129,7 +110,7 @@
     %%cond = seteq %s %%y, 0
     br bool %%cond, label %%is_0, label %%is_not_0
 is_0:
-    call fastcc void %%__prepare_ZeroDivisionError()
+    call fastcc void %%prepare_ZeroDivisionError()
     unwind
 
 is_not_0:
@@ -145,7 +126,7 @@
     %cond2 = setne int %x, -2147483648
     br bool %cond2, label %return_block, label %ovf
 ovf:
-    call fastcc void %__prepare_OverflowError()
+    call fastcc void %prepare_OverflowError()
     unwind
 """
 
@@ -157,7 +138,7 @@
     for prefix_type_ in "int:int uint:uint".split():
         prefix, type_ = prefix_type_.split(':')
         type_zer_test = zer_test % type_
-        extfunctions["%%%(prefix)s_%(func)s" % locals()] = (("%__prepare_ZeroDivisionError",), """
+        extfunctions["%%%(prefix)s_%(func)s" % locals()] = ((), """
 internal fastcc %(type_)s %%%(prefix)s_%(func)s(%(type_)s %%x, %(type_)s %%y) {
     %(type_zer_test)s
     %%z = %(inst)s %(type_)s %%x, %%y
@@ -169,7 +150,7 @@
 
 #unary with OverflowError only
 
-extfunctions["%int_neg_ovf"] = (("%__prepare_OverflowError",), """
+extfunctions["%int_neg_ovf"] = ((), """
 internal fastcc int %%int_neg_ovf(int %%x) {
 block1:
     %%x2 = sub int 0, %%x
@@ -179,7 +160,7 @@
 }
 """ % locals())
 
-extfunctions["%int_abs_ovf"] = (("%__prepare_OverflowError",), """
+extfunctions["%int_abs_ovf"] = ((), """
 internal fastcc int %%int_abs_ovf(int %%x) {
 block0:
     %%cond1 = setge int %%x, 0
@@ -196,7 +177,7 @@
 
 #binary with OverflowError only
 
-extfunctions["%int_add_ovf"] = (("%__prepare_OverflowError",), """
+extfunctions["%int_add_ovf"] = ((), """
 internal fastcc int %%int_add_ovf(int %%x, int %%y) {
     %%t = add int %%x, %%y
     %(int_ovf_test)s
@@ -206,7 +187,7 @@
 }
 """ % locals())
 
-extfunctions["%int_sub_ovf"] = (("%__prepare_OverflowError",), """
+extfunctions["%int_sub_ovf"] = ((), """
 internal fastcc int %%int_sub_ovf(int %%x, int %%y) {
     %%t = sub int %%x, %%y
     %(int_ovf_test)s
@@ -216,7 +197,7 @@
 }
 """ % locals())
 
-extfunctions["%int_mul_ovf"] = (("%__prepare_OverflowError",), """
+extfunctions["%int_mul_ovf"] = ((), """
 internal fastcc int %%int_mul_ovf(int %%x, int %%y) {
     %%t = mul int %%x, %%y
     %(int_ovf_test)s
@@ -229,7 +210,7 @@
 
 #binary with OverflowError and ValueError
 
-extfunctions["%int_lshift_ovf_val"] = (("%__prepare_OverflowError","%__prepare_ValueError"), """
+extfunctions["%int_lshift_ovf_val"] = ((), """
 internal fastcc int %%int_lshift_ovf_val(int %%x, int %%y) {
     %%yu = cast int %%y to ubyte
     %%t = shl int %%x, ubyte %%yu
@@ -243,7 +224,7 @@
 
 #binary with OverflowError and ZeroDivisionError
 
-extfunctions["%int_floordiv_ovf_zer"] = (("%__prepare_OverflowError","%__prepare_ZeroDivisionError"), """
+extfunctions["%int_floordiv_ovf_zer"] = ((), """
 internal fastcc int %%int_floordiv_ovf_zer(int %%x, int %%y) {
     %(int_zer_test)s
     %%t = div int %%x, %%y
@@ -254,7 +235,7 @@
 }
 """ % locals())
 
-extfunctions["%int_mod_ovf_zer"] = (("%__prepare_OverflowError","%__prepare_ZeroDivisionError"), """
+extfunctions["%int_mod_ovf_zer"] = ((), """
 internal fastcc int %%int_mod_ovf_zer(int %%x, int %%y) {
     %(int_zer_test)s
     %%t = rem int %%x, %%y
@@ -265,36 +246,11 @@
 }
 """ % locals())
 
-extfunctions["%main_noargs"] = [(), """
-int %main(int %argc, sbyte** %argv) {
-entry:
-    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:
-    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
+# main functions to be moved to genexterns
 
-loopexit:
+extfunctions["%main_noargs"] = [(), """
+int %main(int %argc, sbyte** %argv) {
     %ret  = call fastcc int %pypy_main_noargs()
     ret int %ret
 }
@@ -311,29 +267,14 @@
     %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* %RPyString_FromString(sbyte* %tmp.9)
     call fastcc void %pypy_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 %pypy_entry_point(%structtype.list* %pypy_argv)
     ret int %ret
 }

Modified: pypy/release/0.7.x/pypy/translator/llvm/test/test_exc_operation.py
==============================================================================
--- pypy/release/0.7.x/pypy/translator/llvm/test/test_exc_operation.py	(original)
+++ pypy/release/0.7.x/pypy/translator/llvm/test/test_exc_operation.py	Sat Aug 27 14:01:36 2005
@@ -2,6 +2,7 @@
 import sys
 from pypy.translator.llvm.test.runtest import compile_function
 from pypy.rpython.rarithmetic import r_uint, ovfcheck, ovfcheck_lshift
+from pypy.translator.test import snippet 
 
 def test_zerodiv_int():
     def zerodiv_int(n):
@@ -69,37 +70,32 @@
     for i in (-sys.maxint-1, -sys.maxint, 0, sys.maxint-1, sys.maxint):
         assert f(i) == abs_int_ovf(i)
 
-from pypy.translator.test import snippet 
+############################
 
 def test_int_overflow():
-    py.test.skip("int_add_ovf operation missing (raises)")
     fn = compile_function(snippet.add_func, [int])
     raises(OverflowError, fn, sys.maxint)
 
 def test_int_div_ovf_zer():
-    py.test.skip("int_floordiv_ovf_zer operation missing (raises)")
     fn = compile_function(snippet.div_func, [int])
     raises(OverflowError, fn, -1)
     raises(ZeroDivisionError, fn, 0)
 
 def test_int_mod_ovf_zer():
-    py.test.skip("int_mod_ovf_zer operation missing (raises)")
     fn = compile_function(snippet.mod_func, [int])
     raises(OverflowError, fn, -1)
     raises(ZeroDivisionError, fn, 0)
 
 def test_int_rshift_val():
-    py.test.skip("int_rshift_val operation missing (raises)")
     fn = compile_function(snippet.rshift_func, [int])
     raises(ValueError, fn, -1)
 
 def test_int_lshift_ovf_val():
-    py.test.skip("int_lshift_ovf_val operation missing (raises)")
     fn = compile_function(snippet.lshift_func, [int])
     raises(ValueError, fn, -1)
+    raises(OverflowError, fn, 1)
 
 def test_uint_arith():
-    py.test.skip("uint_floordiv_zer operation missing (raises)")
     def fn(i):
         try:
             return ~(i*(i+1))/(i-1)
@@ -111,7 +107,6 @@
         assert f(i) == fn(i)
 
 def test_int_add_ovf():
-    py.test.skip("int add incorrect overflow test")
     def add_func(i):
         try:
             return ovfcheck(i + 1)
@@ -124,7 +119,6 @@
     assert f(sys.maxint) == 123
 
 def test_int_sub_ovf():
-    py.test.skip("ovf test")
     def sub_func(i):
         try:
             return ovfcheck(i - 1)
@@ -136,25 +130,10 @@
     assert f(sys.maxint) == sub_func(sys.maxint)
     assert f(sys.maxint) == 123
 
-def test_int_div_ovf_zer():
-    py.test.skip("ovf test")
-    f = compile_function(snippet.div_func)
-    raises(OverflowError, fn, -1)
-    raises(ZeroDivisionError, fn, 0)
-
-def test_int_mod_ovf_zer():
-    py.test.skip("ovf test")
-    f = compile_function(snippet.mod_func)
-    raises(OverflowError, fn, -1)
-    raises(ZeroDivisionError, fn, 0)
-
-def test_int_rshift_val():
-    py.test.skip("ovf test")
-    f = compile_function(snippet.rshift_func)
-    raises(ValueError, fn, -1)
-
-def test_int_lshift_ovf_val():
-    py.test.skip("ovf test")
-    f = compile_function(snippet.lshift_func)
-    raises(ValueError, fn, -1)
-    raises(OverflowError, fn, 1)
+def test_shift_with_overflow(self):
+    shl = compile_function(llvmsnippet.shiftleft, [int, int])
+    shr = compile_function(llvmsnippet.shiftright, [int, int])
+    for i in [1, 2, 3, 100000, 2000000, sys.maxint - 1]:
+        for j in [1, 2, 3, 100000, 2000000, sys.maxint - 1]:
+            assert shl(i, j) == i << j
+            assert shr(i, j) == i >> j



More information about the Pypy-commit mailing list