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

rxe at codespeak.net rxe at codespeak.net
Thu Aug 25 16:09:20 CEST 2005


Author: rxe
Date: Thu Aug 25 16:09:14 2005
New Revision: 16496

Modified:
   pypy/dist/pypy/translator/llvm2/genllvm.py
   pypy/dist/pypy/translator/llvm2/module/extfunction.py
   pypy/dist/pypy/translator/llvm2/module/genexterns.c
   pypy/dist/pypy/translator/llvm2/module/ll_math.py
   pypy/dist/pypy/translator/llvm2/test/test_extfunc.py
Log:
Added the rest of math functions - but we have conflicts between checkins...resolving. (ericvrp/rxe)



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 25 16:09:14 2005
@@ -41,6 +41,7 @@
     ll_lines = []
     funcnames = {
         "%ll_frexp_result__Float_Signed"       : True,
+        "%ll_modf_result__Float_Float"         : True,
         "%prepare_and_raise_ZeroDivisionError" : True,
         "%prepare_and_raise_OverflowError"     : True,
         "%prepare_and_raise_ValueError"        : True,
@@ -177,7 +178,14 @@
 
         j = os.path.join
         p = j(j(os.path.dirname(__file__), "module"), "genexterns.c")
-        return get_ll(open(p).read(), extern_dir, ['ll_math_frexp', 'll_math_is_error'])
+        math_fns  = 'acos asin atan ceil cos cosh exp fabs floor log log10 atan2 fmod '
+        math_fns += 'sin sinh sqrt tan tanh frexp modf pow hypot ldexp is_error'
+        #XXX
+        fns2 = [x[1:] for x in extfuncnode.ExternalFuncNode.used_external_functions.keys()]
+        fns = ["ll_math_is_error"]
+        fns += [('ll_math_%s' % f) for f in math_fns.split() if f in fns2]
+
+        return get_ll(open(p).read(), extern_dir, fns)
 
     def gen_llvm_source(self, func=None):
         if self.debug:  print 'gen_llvm_source begin) ' + time.ctime()
@@ -201,8 +209,6 @@
         extern_decls = self.post_setup_externs()
         self.translator.rtyper.specialize_more_blocks()
         self.db.setup_all()
-
-        self.generate_llfile(extern_decls)
  
         #if self.debug:  print 'gen_llvm_source typ_decl.writedatatypedecl) ' + time.ctime()
         #if self.debug:  print 'gen_llvm_source n_nodes) %d' % len(self.db.getnodes())
@@ -314,6 +320,11 @@
         entryfunc_name = t[1].split('(')[0]
         if entryfunc_name != 'main' and entryfunc_name == 'entry_point': #XXX just to get on with translate_pypy
             extfuncnode.ExternalFuncNode.used_external_functions['%main'] = True
+        extfuncnode.ExternalFuncNode.used_external_functions['%prepare_and_raise_OverflowError'] = True
+        extfuncnode.ExternalFuncNode.used_external_functions['%prepare_and_raise_ValueError'] = True
+        extfuncnode.ExternalFuncNode.used_external_functions['%prepare_and_raise_ZeroDivisionError'] = True
+
+        self.generate_llfile(extern_decls)
 
         if self.debug:  print 'gen_llvm_source used_external_functions) ' + time.ctime()
         depdone = {}
@@ -341,7 +352,7 @@
                       filename,
                       really_compile=True,
                       standalone=False,
-                      optimize=True,
+                      optimize=False,
                       exe_name=None):
 
         if not llvm_is_on_path():

Modified: pypy/dist/pypy/translator/llvm2/module/extfunction.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/extfunction.py	(original)
+++ pypy/dist/pypy/translator/llvm2/module/extfunction.py	Thu Aug 25 16:09:14 2005
@@ -41,9 +41,9 @@
 
 extfunctions = {}   #dependencies, llvm-code
 
-import support, ll_os, ll_os_path, ll_time, ll_math, ll_strtod
+import support, ll_os, ll_os_path, ll_time, ll_strtod
 
-for module in (support, ll_os, ll_os_path, ll_time, ll_math, ll_strtod):
+for module in (support, ll_os, ll_os_path, ll_time, ll_strtod):
     extdeclarations += module.extdeclarations
     extfunctions.update(module.extfunctions)
 extdeclarations += '\n;application function prototypes'

Modified: pypy/dist/pypy/translator/llvm2/module/genexterns.c
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/genexterns.c	(original)
+++ pypy/dist/pypy/translator/llvm2/module/genexterns.c	Thu Aug 25 16:09:14 2005
@@ -17,6 +17,7 @@
 void prepare_and_raise_OverflowError(char *);
 void prepare_and_raise_ValueError(char *);
 
+
 int ll_math_is_error(double x) {
 	if (errno == ERANGE) {
 		if (!x) 

Modified: pypy/dist/pypy/translator/llvm2/module/ll_math.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/ll_math.py	(original)
+++ pypy/dist/pypy/translator/llvm2/module/ll_math.py	Thu Aug 25 16:09:14 2005
@@ -1,84 +0,0 @@
-extdeclarations = """
-;ll_math.py
-declare ccc double %acos(double)
-declare ccc double %asin(double)
-declare ccc double %atan(double)
-declare ccc double %ceil(double)
-declare ccc double %cos(double)
-declare ccc double %cosh(double)
-declare ccc double %exp(double)
-declare ccc double %fabs(double)
-declare ccc double %floor(double)
-declare ccc double %log(double)
-declare ccc double %log10(double)
-declare ccc double %sin(double)
-declare ccc double %sinh(double)
-declare ccc double %sqrt(double)
-declare ccc double %tan(double)
-declare ccc double %tanh(double)
-declare ccc double %atan2(double,double)
-declare ccc double %fmod(double,double)
-
-%__ll_math_frexp = constant [12 x sbyte] c"frexp......\\00"
-%__ll_math_hypot = constant [12 x sbyte] c"hypot......\\00"
-%__ll_math_ldexp = constant [12 x sbyte] c"ldexp......\\00"
-%__ll_math_modf  = constant [12 x sbyte] c"modf.......\\00"
-%__ll_math_pow   = constant [12 x sbyte] c"pow........\\00"
-"""
-
-extfunctions = {}
-
-#functions with a one-to-one C equivalent
-simple_functions = [
-    ('double %x', ['acos','asin','atan','ceil','cos','cosh','exp','fabs',
-                   'floor','log','log10','sin','sinh','sqrt','tan','tanh']),
-    ('double %x, double %y', ['atan2','fmod']),
-    ]
-
-simple_function_template = """
-ccc double %%ll_math_%(function)s(%(params)s) {
-    %%t = call ccc double %%%(function)s(%(params)s)
-    ret double %%t
-}
-
-"""
-
-for params, functions in simple_functions:
-    for function in functions:
-        extfunctions["%ll_math_" + function] = ((), simple_function_template % locals())
-
-extfunctions["%ll_math_hypot"] = (("%__debug",), """
-ccc double %ll_math_hypot(double %x, double %y) {
-    call ccc void %__debug([12 x sbyte]* %__ll_math_hypot) ; XXX: TODO: ll_math_hypot
-    ret double 0.0
-}
-""")
-
-extfunctions["%ll_math_ldexp"] = (("%__debug",), """
-ccc double %ll_math_ldexp(double %x, int %y) {
-    call ccc void %__debug([12 x sbyte]* %__ll_math_ldexp) ; XXX: TODO: ll_math_ldexp
-    ret double 0.0
-}
-""")
-
-extfunctions["%ll_math_modf"] = (("%__debug",), """
-ccc %RPyMODF_RESULT* %ll_math_modf(double %x) {
-    call ccc void %__debug([12 x sbyte]* %__ll_math_modf) ; XXX: TODO: ll_math_modf
-    ret %RPyMODF_RESULT* null
-}
-""")
-
-extfunctions["%ll_math_pow"] = (("%__debug",), """
-ccc double %ll_math_pow(double %x, double %y) {
-    call ccc void %__debug([12 x sbyte]* %__ll_math_pow) ; XXX: TODO: ll_math_pow
-    ret double 0.0
-}
-""")
-#;;;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-
-
-extfunctions["%ll_math_frexp"] = (("%prepare_and_raise_OverflowError",
-                                   "%prepare_and_raise_ValueError"), """
-""")
-
-

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 25 16:09:14 2005
@@ -156,12 +156,12 @@
     assert res == fn(10.123)
 
 def test_math_modf():
-    py.test.skip("ll_math_modf not implemented (next)")
     from math import modf
     def fn(x):
-        return modf(x)
+        res = modf(x)
+        return res[0] + res[1]
     f = compile_function(fn, [float])
-    assert f(10.123) == modf(10.123)
+    assert f(10.123) == fn(10.123)
 
 simple_math_functions = [
     'acos', 'asin', 'atan', 'ceil', 'cos', 'cosh', 'exp', 'fabs',



More information about the Pypy-commit mailing list