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

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Apr 1 02:50:58 CEST 2005


Author: cfbolz
Date: Fri Apr  1 02:50:58 2005
New Revision: 10208

Modified:
   pypy/dist/pypy/translator/llvm/genllvm.py
   pypy/dist/pypy/translator/llvm/llvmbc.py
   pypy/dist/pypy/translator/llvm/representation.py
   pypy/dist/pypy/translator/llvm/test/llvmsnippet.py
   pypy/dist/pypy/translator/llvm/test/test_genllvm.py
Log:
fixed a bug. 


Modified: pypy/dist/pypy/translator/llvm/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/genllvm.py	Fri Apr  1 02:50:58 2005
@@ -159,4 +159,28 @@
             yield l_dep1
     yield l_repr
 
+<<<<<<< .mine
 
+## class AAA(object):
+##     def __init__(self):
+##         self.a = 1
+
+## class BBB(AAA):
+##     def __init__(self):
+##         self.a = 2
+##         self.b = 2
+
+## def f1(flag):
+##     if flag:
+##         a = AAA()
+##     else:
+##         a = BBB()
+##     return a.a
+
+## t = Translator(f1, simplifying=True)
+## a = t.annotate([bool])
+## t.view()
+## f = llvmcompile(t)
+=======
+
+>>>>>>> .r10207

Modified: pypy/dist/pypy/translator/llvm/llvmbc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/llvmbc.py	(original)
+++ pypy/dist/pypy/translator/llvm/llvmbc.py	Fri Apr  1 02:50:58 2005
@@ -73,6 +73,9 @@
         self.instructions.append(s +
             ", ".join([a.typed_name() for a in l_args]) + ")")
 
+    def invoke(self, l_target, l_func, l_args, errorblock):
+        pass
+
     def ret(self, l_value):
         self.instructions.append("ret %s" % l_value.typed_name())
 
@@ -134,3 +137,11 @@
             s += ["\t%s\n" % ins]
         return "".join(s)
 
+
+class ExceptionBasicBlock(BasicBlock):
+    def __init__(self, label, regularblock, exceptblock):
+        self.label = label
+        self.exceptblock = exceptblock
+        self.regularblock = regularblock
+        self.llvmblocks = []
+        self.instructions = []

Modified: pypy/dist/pypy/translator/llvm/representation.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/representation.py	(original)
+++ pypy/dist/pypy/translator/llvm/representation.py	Fri Apr  1 02:50:58 2005
@@ -830,7 +830,7 @@
                 self.llvm_func = llvmbc.Function(self.llvmfuncdef(), lblock)
             else:
                 self.llvm_func.basic_block(lblock)
-            #Create Phi nodes (but not for the first node)
+            #Create Phi nodes (but not for the first block)
             incoming_links = []
             def visit(node):
                 if isinstance(node, Link) and node.target == pyblock:
@@ -847,25 +847,14 @@
                     l_v2 = self.gen.get_repr(incoming_links[0].args[i])
                     self.dependencies.update([l_arg, l_switch, l_v1, l_v2])
                     lblock.select(l_arg, l_select, l_v1, l_v2)
-            #special case for isinstance blocks:
-            #if the type changes a cast is neccessary
-            elif len(incoming_links) == 1:
-                link = incoming_links[0]
-                for i, arg in enumerate(pyblock.inputargs):
-                    l_arg = self.gen.get_repr(arg)
-                    l_value = self.gen.get_repr(link.args[i])
-                    self.dependencies.update([l_arg, l_value])
-                    if l_arg.llvmtype() == l_value.llvmtype():
-                        lblock.phi(
-                            l_arg, [l_value],
-                            ["%%block%i" % self.blocknum[link.prevblock]])
-                    else:
-                        lblock.cast(l_arg, l_value)
             elif len(incoming_links) != 0:
                 for i, arg in enumerate(pyblock.inputargs):
                     l_arg = self.gen.get_repr(arg)
                     l_values = [self.gen.get_repr(l.args[i])
                                 for l in incoming_links]
+                    for j in range(len(l_values)):
+                        if l_values[j].llvmtype() != l_arg.llvmtype():
+                            l_values[j] = l_values[j].alt_types[l_arg.llvmtype()]
                     self.dependencies.add(l_arg)
                     self.dependencies.update(l_values)
                     lblock.phi(l_arg, l_values,
@@ -894,6 +883,24 @@
                             "Dispatched on: %s" % l_arg0
                             
                         raise CompileError, s
+            # XXX: If a variable is passed to another block and has a different
+            # type there, we have to make the cast in this block since the phi
+            # instructions in the next block cannot be preceded by any other
+            # instrcution
+            for link in pyblock.exits:
+                for i, arg in enumerate(link.args):
+                    localtype = self.annotator.binding(arg)
+                    targettype = self.annotator.binding(
+                        link.target.inputargs[i])
+                    l_targettype = self.gen.get_repr(targettype)
+                    l_localtype = self.gen.get_repr(localtype)
+                    l_local = self.gen.get_repr(arg)
+                    self.dependencies.update([l_targettype, l_localtype,
+                                              l_local])
+                    if l_targettype.llvmname() != l_localtype.llvmname():
+                        l_tmp = self.gen.get_local_tmp(l_targettype, self)
+                        lblock.cast(l_tmp, l_local)
+                        l_local.alt_types = {l_targettype.llvmname(): l_tmp}
             #Create branches
             if pyblock.exitswitch is None:
                 if pyblock.exits == ():

Modified: pypy/dist/pypy/translator/llvm/test/llvmsnippet.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/llvmsnippet.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/llvmsnippet.py	Fri Apr  1 02:50:58 2005
@@ -226,6 +226,23 @@
     c = CCC()
     return ifisinstance(a) + ifisinstance(b) + ifisinstance(c)
 
+class CLA(object):
+    def __init__(self):
+        self.a = 1
+
+class CLB(CLA):
+    def __init__(self):
+        self.a = 2
+        self.b = 1
+
+def merge_classes(flag):
+    if flag:
+        a = CLA()
+    else:
+        a = CLB()
+    return a.a
+
+
 #string snippets
 def string_f1(i):
     j = 0

Modified: pypy/dist/pypy/translator/llvm/test/test_genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/test_genllvm.py	Fri Apr  1 02:50:58 2005
@@ -219,6 +219,11 @@
     def test_flow_type(self):
         f = compile_function(llvmsnippet.flow_type, [])
         assert f() == 16
+
+    def test_merge_class(self):
+        f = compile_function(llvmsnippet.merge_classes, [bool])
+        assert f(True) == 1
+        assert f(False) == 2
     
 class TestString(object):
     def setup_method(self, method):



More information about the Pypy-commit mailing list