[pypy-svn] r15578 - in pypy/dist/pypy/translator/llvm2: . test
ericvrp at codespeak.net
ericvrp at codespeak.net
Wed Aug 3 22:38:12 CEST 2005
Author: ericvrp
Date: Wed Aug 3 22:38:11 2005
New Revision: 15578
Modified:
pypy/dist/pypy/translator/llvm2/funcnode.py
pypy/dist/pypy/translator/llvm2/opwriter.py
pypy/dist/pypy/translator/llvm2/test/test_exception.py
Log:
Some refactoring to move more exception handling code together.
One more exception test.
Modified: pypy/dist/pypy/translator/llvm2/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/funcnode.py (original)
+++ pypy/dist/pypy/translator/llvm2/funcnode.py Wed Aug 3 22:38:11 2005
@@ -122,7 +122,8 @@
self.write_block_operations(codewriter, block)
self.write_block_branches(codewriter, block)
- def write_block_phi_nodes(self, codewriter, block):
+ def get_phi_data(self, block):
+ data = []
entrylinks = mkentrymap(self.graph)[block]
entrylinks = [x for x in entrylinks if x.prevblock is not None]
inputargs = self.db.repr_arg_multi(block.inputargs)
@@ -135,13 +136,13 @@
if link.prevblock.exitswitch == Constant(last_exception) and \
link.prevblock.exits[0].target != block:
blocknames[i] += '_exception_found_branchto_' + self.block_to_name[block]
+ data.append( (arg, type_, names, blocknames) )
+ return data
+
+ def write_block_phi_nodes(self, codewriter, block):
+ for arg, type_, names, blocknames in self.get_phi_data(block):
if type_ != "void":
- if arg.startswith('%last_exc_value_') and type_ == '%structtype.object*':
- e = self.db._translator.rtyper.getexceptiondata()
- lltype_of_exception_value = ('%structtype.' + e.lltype_of_exception_value.TO.__name__ + '*')
- codewriter.load(arg, lltype_of_exception_value, '%last_exception_value')
- else:
- codewriter.phi(arg, type_, names, blocknames)
+ codewriter.phi(arg, type_, names, blocknames)
def write_block_branches(self, codewriter, block):
#assert len(block.exits) <= 2 #more exits are possible (esp. in combination with exceptions)
Modified: pypy/dist/pypy/translator/llvm2/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/opwriter.py (original)
+++ pypy/dist/pypy/translator/llvm2/opwriter.py Wed Aug 3 22:38:11 2005
@@ -260,6 +260,9 @@
lltype_of_exception_type = ('%structtype.' +
e.lltype_of_exception_type.TO.__name__
+ '*')
+ lltype_of_exception_value = ('%structtype.' +
+ e.lltype_of_exception_value.TO.__name__
+ + '*')
self.codewriter.label(exc_label)
@@ -269,11 +272,24 @@
etype = self.db.obj2node[link.llexitcase._obj]
current_exception_type = etype.get_ref()
- #self.codewriter.comment('etype=%s, current_exception_type=%s' % (str(etype.ref), str(current_exception_type)))
target = self.node.block_to_name[link.target]
exc_found_label = block_label + '_exception_found_branchto_' + target
- exc_found_labels.append( (exc_found_label, target) )
+ last_exc_type_var, last_exc_value_var = None, None
+
+ for p in self.node.get_phi_data(link.target):
+ arg, type_, names, blocknames = p
+ for name, blockname in zip(names, blocknames):
+ if blockname != exc_found_label:
+ continue
+ #XXX might want to refactor the next few lines
+ if name.startswith('%last_exception_'):
+ last_exc_type_var = name
+ if name.startswith('%last_exc_value_'):
+ last_exc_value_var = name
+
+ t = (exc_found_label,target,last_exc_type_var,last_exc_value_var)
+ exc_found_labels.append(t)
not_this_exception_label = block_label + '_not_exception_' + etype.ref[1:]
@@ -297,8 +313,13 @@
self.codewriter.comment('reraise when exception is not caught')
self.codewriter.unwind()
- for label, target in exc_found_labels:
+ for label, target, last_exc_type_var, last_exc_value_var in exc_found_labels:
self.codewriter.label(label)
+ if last_exc_type_var:
+ self.codewriter.load(last_exc_type_var, lltype_of_exception_type, '%last_exception_type')
+ if last_exc_value_var:
+ self.codewriter.load(last_exc_value_var, lltype_of_exception_value, '%last_exception_value')
+
self.codewriter.br_uncond(target)
def malloc(self, op):
Modified: pypy/dist/pypy/translator/llvm2/test/test_exception.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_exception.py (original)
+++ pypy/dist/pypy/translator/llvm2/test/test_exception.py Wed Aug 3 22:38:11 2005
@@ -116,12 +116,11 @@
py.test.raises(Exception, "f(10)")
def test_reraise2():
- py.test.skip("PyPy interpreter not happy with this test")
def fn(n):
lst = range(10)
try:
getitem(lst,n)
- except e:
+ except Exception, e:
raise e
return 4
f = compile_function(fn, [int])
More information about the Pypy-commit
mailing list