[pypy-svn] r17615 - pypy/dist/pypy/translator/llvm

ericvrp at codespeak.net ericvrp at codespeak.net
Sat Sep 17 17:41:44 CEST 2005


Author: ericvrp
Date: Sat Sep 17 17:41:43 2005
New Revision: 17615

Modified:
   pypy/dist/pypy/translator/llvm/codewriter.py
   pypy/dist/pypy/translator/llvm/funcnode.py
   pypy/dist/pypy/translator/llvm/opwriter.py
   pypy/dist/pypy/translator/llvm/varsize.py
Log:
Intermediate checking before implementing another exception handling
policy. The LLVM invoke/unwind instructions cause plain ugly looking code!
A lot of setjmp/longjmp's make the resulting assembly and c code very
hard to read.


Modified: pypy/dist/pypy/translator/llvm/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/codewriter.py	(original)
+++ pypy/dist/pypy/translator/llvm/codewriter.py	Sat Sep 17 17:41:43 2005
@@ -81,10 +81,10 @@
         self.append("}") 
 
     def ret(self, type_, ref): 
-        self.indent("ret %s %s" % (type_, ref))
-
-    def ret_void(self):
-        self.indent("ret void")
+        if type_ == 'void':
+            self.indent("ret void")
+        else:
+            self.indent("ret %s %s" % (type_, ref))
 
     def unwind(self):
         self.indent("unwind")
@@ -109,35 +109,26 @@
     # allocas or varargs in the caller. If the "tail" marker is present, the function
     # call is eligible for tail call optimization. Note that calls may be marked
     # "tail" even if they do not occur before a ret instruction. 
-    def call(self, targetvar, returntype, functionref, argrefs, argtypes, tail=DEFAULT_TAIL, cconv=DEFAULT_CCONV):
+    def call(self, targetvar, returntype, functionref, argrefs, argtypes, label=None, except_label=None, tail=DEFAULT_TAIL, cconv=DEFAULT_CCONV):
         if cconv is not 'fastcc':
             tail_ = ''
         else:
             tail_ = tail
 	if tail_:
 		tail_ += ' '
-        arglist = ["%s %s" % item for item in zip(argtypes, argrefs)]
-        self.indent("%s = %scall %s %s %s(%s)" % (targetvar, tail_, cconv, returntype, functionref,
-                                             ", ".join(arglist)))
-
-    def call_void(self, functionref, argrefs, argtypes, tail=DEFAULT_TAIL, cconv=DEFAULT_CCONV):
-        if cconv is not 'fastcc':
-            tail_ = ''
+        args = ", ".join(["%s %s" % item for item in zip(argtypes, argrefs)])
+        if except_label:
+            assert label
+            instruction = 'invoke'
+            optional    = ' to label %%%s except label %%%s' % (label, except_label)
         else:
-            tail_ = tail
-	if tail_:
-		tail_ += ' '
-        arglist = ["%s %s" % item for item in zip(argtypes, argrefs)]
-        self.indent("%scall %s void %s(%s)" % (tail_, cconv, functionref, ", ".join(arglist)))
-
-    def invoke(self, targetvar, returntype, functionref, argrefs, argtypes, label, except_label, cconv=DEFAULT_CCONV):
-        arglist = ["%s %s" % item for item in zip(argtypes, argrefs)]
-        self.indent("%s = invoke %s %s %s(%s) to label %%%s except label %%%s" % (targetvar, cconv, returntype, functionref,
-                                             ", ".join(arglist), label, except_label))
-
-    def invoke_void(self, functionref, argrefs, argtypes, label, except_label, cconv=DEFAULT_CCONV):
-        arglist = ["%s %s" % item for item in zip(argtypes, argrefs)]
-        self.indent("invoke %s void %s(%s) to label %%%s except label %%%s" % (cconv, functionref, ", ".join(arglist), label, except_label))
+            assert not label
+            instruction = 'call'
+            optional    = ''
+        if returntype == 'void':
+            self.indent("%s%s %s void %s(%s)%s" % (tail_, instruction, cconv, functionref, args, optional))
+        else:
+            self.indent("%s = %s%s %s %s %s(%s)%s" % (targetvar, tail_, instruction, cconv, returntype, functionref, args, optional))
 
     def cast(self, targetvar, fromtype, fromvar, targettype):
     	if fromtype == 'void' and targettype == 'void':

Modified: pypy/dist/pypy/translator/llvm/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/funcnode.py	(original)
+++ pypy/dist/pypy/translator/llvm/funcnode.py	Sat Sep 17 17:41:43 2005
@@ -205,10 +205,7 @@
         self.write_block_phi_nodes(codewriter, block)
         inputargtype = self.db.repr_arg_type(block.inputargs[0])
         inputarg = self.db.repr_arg(block.inputargs[0])
-        if inputargtype != "void":
-            codewriter.ret(inputargtype, inputarg)
-        else:
-            codewriter.ret_void()
+        codewriter.ret(inputargtype, inputarg)
 
     def _is_raise_new_exception(self, block):
         is_raise_new = False

Modified: pypy/dist/pypy/translator/llvm/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/opwriter.py	(original)
+++ pypy/dist/pypy/translator/llvm/opwriter.py	Sat Sep 17 17:41:43 2005
@@ -285,13 +285,9 @@
         functionref = self.db.repr_arg(op_args[0])
         argrefs = self.db.repr_arg_multi(op_args[1:])
         argtypes = self.db.repr_arg_type_multi(op_args[1:])
-        if returntype != "void":
-            if self.db.is_function_ptr(op.result):
-                returntype = "%s (%s)*" % (returntype, ", ".join(argtypes))
-            self.codewriter.call(targetvar, returntype, functionref, argrefs,
-                                 argtypes)
-        else:
-            self.codewriter.call_void(functionref, argrefs, argtypes)
+        if self.db.is_function_ptr(op.result):
+            returntype = "%s (%s)*" % (returntype, ", ".join(argtypes))
+        self.codewriter.call(targetvar,returntype,functionref,argrefs,argtypes)
 
     def invoke(self, op):
         op_args = [arg for arg in op.args
@@ -332,13 +328,10 @@
 
 
 
-        if returntype != "void":
-            if self.db.is_function_ptr(op.result):  #use longhand form
-                returntype = "%s (%s)*" % (returntype, ", ".join(argtypes))
-            self.codewriter.invoke(targetvar, returntype, functionref, argrefs,
-                                   argtypes, none_label, exc_label)
-        else:
-            self.codewriter.invoke_void(functionref, argrefs, argtypes, none_label, exc_label)
+        if self.db.is_function_ptr(op.result):  #use longhand form
+            returntype = "%s (%s)*" % (returntype, ", ".join(argtypes))
+        self.codewriter.call(targetvar, returntype, functionref, argrefs,
+                             argtypes, none_label, exc_label)
 
         e = self.db.translator.rtyper.getexceptiondata()
         ll_exception_match       = '%pypy_' + e.ll_exception_match.__name__

Modified: pypy/dist/pypy/translator/llvm/varsize.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/varsize.py	(original)
+++ pypy/dist/pypy/translator/llvm/varsize.py	Sat Sep 17 17:41:43 2005
@@ -28,9 +28,9 @@
 
     if ARRAY is STR.chars:
         #XXX instead of memset we could probably just zero the hash and string terminator
-        codewriter.call_void('%llvm.memset', ['%ptr', '0', '%usize', '0'], ['sbyte*', 'ubyte', 'uint', 'uint'], cconv='ccc')
+        codewriter.call('%dummy', 'void', '%llvm.memset', ['%ptr', '0', '%usize', '0'], ['sbyte*', 'ubyte', 'uint', 'uint'], cconv='ccc')
     else:
-        codewriter.call_void('%llvm.memset', ['%ptr', '0', '%usize', '0'], ['sbyte*', 'ubyte', 'uint', 'uint'], cconv='ccc')
+        codewriter.call('%dummy', 'void', '%llvm.memset', ['%ptr', '0', '%usize', '0'], ['sbyte*', 'ubyte', 'uint', 'uint'], cconv='ccc')
 
     indices_to_arraylength = tuple(indices_to_array) + (("uint", 0),)
     # the following accesses the length field of the array 



More information about the Pypy-commit mailing list