[pypy-svn] r14344 - pypy/dist/pypy/translator

ericvrp at codespeak.net ericvrp at codespeak.net
Wed Jul 6 16:44:31 CEST 2005


Author: ericvrp
Date: Wed Jul  6 16:44:30 2005
New Revision: 14344

Modified:
   pypy/dist/pypy/translator/backendoptimization.py
Log:
transform extenral functions calls to their c equivalant


Modified: pypy/dist/pypy/translator/backendoptimization.py
==============================================================================
--- pypy/dist/pypy/translator/backendoptimization.py	(original)
+++ pypy/dist/pypy/translator/backendoptimization.py	Wed Jul  6 16:44:30 2005
@@ -5,6 +5,7 @@
 from pypy.objspace.flow.model import traverse, mkentrymap, checkgraph
 from pypy.tool.unionfind import UnionFind
 from pypy.rpython.lltype import Void
+from pypy.rpython.extfunctable import table as extfunctable
 
 def remove_same_as(graph):
     """Remove all 'same_as' operations.
@@ -57,6 +58,28 @@
     for func, graph in translator.flowgraphs.iteritems():
         traverse(visit, graph)
  
+def rename_extfunc_calls(translator):
+    def visit(block): 
+        if isinstance(block, Block):
+            for op in block.operations:
+                if op.opname != 'direct_call':
+                    continue
+                functionref = op.args[0]
+                if not isinstance(functionref, Constant):
+                    continue
+                _callable = functionref.value._obj._callable
+                for func, extfuncinfo in extfunctable.iteritems():  # precompute a dict?
+                    if _callable is not extfuncinfo.ll_function or not extfuncinfo.backend_functiontemplate:
+                        continue
+                    language, functionname = extfuncinfo.backend_functiontemplate.split(':')
+                    if language is 'C':
+                        old_name = functionref.value._obj._name[:]
+                        functionref.value._obj._name = functionname
+                        #print 'rename_extfunc_calls: %s -> %s' % (old_name, functionref.value._obj._name)
+                        break
+    for func, graph in translator.flowgraphs.iteritems():
+        traverse(visit, graph)
+ 
 def SSI_to_SSA(graph):
     """Rename the variables in a flow graph as much as possible without
     violating the SSA rule.  'SSI' means that each Variable in a flow graph is



More information about the Pypy-commit mailing list