[pypy-svn] pypy default: (fijal, arigo)

arigo commits-noreply at bitbucket.org
Wed Jan 19 17:34:16 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r40944:d5acdbe7b55a
Date: 2011-01-19 17:33 +0100
http://bitbucket.org/pypy/pypy/changeset/d5acdbe7b55a/

Log:	(fijal, arigo)

	Improve the error reporting from assembler.py, in case it sees an
	operation with a Constant(..., Void).

diff --git a/pypy/jit/codewriter/assembler.py b/pypy/jit/codewriter/assembler.py
--- a/pypy/jit/codewriter/assembler.py
+++ b/pypy/jit/codewriter/assembler.py
@@ -9,6 +9,10 @@
 from pypy.rpython.lltypesystem import lltype, llmemory, rclass
 
 
+class AssemblerError(Exception):
+    pass
+
+
 class Assembler(object):
 
     def __init__(self):
@@ -24,7 +28,7 @@
         """Take the 'ssarepr' representation of the code and assemble
         it inside the 'jitcode'.  If jitcode is None, make a new one.
         """
-        self.setup()
+        self.setup(ssarepr.name)
         ssarepr._insns_pos = []
         for insn in ssarepr.insns:
             ssarepr._insns_pos.append(len(self.code))
@@ -40,7 +44,7 @@
         self._count_jitcodes += 1
         return jitcode
 
-    def setup(self):
+    def setup(self, name):
         self.code = []
         self.constants_dict = {}
         self.constants_i = []
@@ -54,6 +58,7 @@
         self.startpoints = set()
         self.alllabels = set()
         self.resulttypes = {}
+        self.ssareprname = name
 
     def emit_reg(self, reg):
         if reg.index >= self.count_regs[reg.kind]:
@@ -62,8 +67,8 @@
 
     def emit_const(self, const, kind, allow_short=False):
         value = const.value
-        TYPE = lltype.typeOf(value)
         if kind == 'int':
+            TYPE = const.concretetype
             if isinstance(TYPE, lltype.Ptr):
                 assert TYPE.TO._gckind == 'raw'
                 self.see_raw_object(value)
@@ -82,10 +87,11 @@
             value = lltype.cast_opaque_ptr(llmemory.GCREF, value)
             constants = self.constants_r
         elif kind == 'float':
-            assert TYPE == lltype.Float
+            assert const.concretetype == lltype.Float
             constants = self.constants_f
         else:
-            raise NotImplementedError(const)
+            raise AssemblerError('unimplemented %r in %r' %
+                                 (const, self.ssareprname))
         key = (kind, Constant(value))
         if key not in self.constants_dict:
             constants.append(value)

diff --git a/pypy/jit/codewriter/test/test_assembler.py b/pypy/jit/codewriter/test/test_assembler.py
--- a/pypy/jit/codewriter/test/test_assembler.py
+++ b/pypy/jit/codewriter/test/test_assembler.py
@@ -1,5 +1,5 @@
 import py, struct
-from pypy.jit.codewriter.assembler import Assembler
+from pypy.jit.codewriter.assembler import Assembler, AssemblerError
 from pypy.jit.codewriter.flatten import SSARepr, Label, TLabel, Register
 from pypy.jit.codewriter.flatten import ListOfKind, IndirectCallTargets
 from pypy.jit.codewriter.jitcode import MissingLiveness
@@ -206,3 +206,12 @@
             py.test.raises(MissingLiveness, jitcode._live_vars, i)
     assert jitcode._live_vars(4) == '%i0 %i1 %i2'
     assert jitcode._live_vars(8) == '%i2'
+
+def test_assemble_error_string_constant():
+    ssarepr = SSARepr("test")
+    c = Constant('foobar', lltype.Void)
+    ssarepr.insns = [
+        ('duh', c),
+        ]
+    assembler = Assembler()
+    py.test.raises(AssemblerError, assembler.assemble, ssarepr)


More information about the Pypy-commit mailing list