Beispiel #1
0
def test_format_assembler_list():
    ssarepr = SSARepr("test")
    i0, i1 = Register('int', 0), Register('int', 1)
    ssarepr.insns = [
        ('foobar', ListOfKind('int', [i0, Constant(123, lltype.Signed), i1])),
    ]
    asm = format_assembler(ssarepr)
    expected = """
        foobar I[%i0, $123, %i1]
    """
    assert asm == str(py.code.Source(expected)).strip() + '\n'
Beispiel #2
0
 def print_ssa_repr(self, ssarepr, portal_jitdriver, verbose):
     if verbose:
         print '%s:' % (ssarepr.name,)
         print format_assembler(ssarepr)
     else:
         log.dot()
     dir = udir.ensure("jitcodes", dir=1)
     if portal_jitdriver:
         name = "%02d_portal_runner" % (portal_jitdriver.index,)
     elif ssarepr.name and ssarepr.name != '?':
         name = ssarepr.name
     else:
         name = 'unnamed' % id(ssarepr)
     i = 1
     extra = ''
     while name+extra in self._seen_files:
         i += 1
         extra = '.%d' % i
     self._seen_files.add(name+extra)
     dir.join(name+extra).write(format_assembler(ssarepr))
Beispiel #3
0
def test_format_assembler_float():
    ssarepr = SSARepr("test")
    i1, r2, f3 = Register('int', 1), Register('ref', 2), Register('float', 3)
    ssarepr.insns = [
        ('foobar', i1, r2, f3),
    ]
    asm = format_assembler(ssarepr)
    expected = """
        foobar %i1, %r2, %f3
    """
    assert asm == str(py.code.Source(expected)).strip() + '\n'
Beispiel #4
0
def test_format_assembler_list():
    ssarepr = SSARepr("test")
    i0, i1 = Register('int', 0), Register('int', 1)
    ssarepr.insns = [
        ('foobar', ListOfKind('int', [i0, Constant(123, lltype.Signed), i1])),
        ]
    asm = format_assembler(ssarepr)
    expected = """
        foobar I[%i0, $123, %i1]
    """
    assert asm == str(py.code.Source(expected)).strip() + '\n'
Beispiel #5
0
def test_format_assembler_float():
    ssarepr = SSARepr("test")
    i1, r2, f3 = Register('int', 1), Register('ref', 2), Register('float', 3)
    ssarepr.insns = [
        ('foobar', i1, r2, f3),
        ]
    asm = format_assembler(ssarepr)
    expected = """
        foobar %i1, %r2, %f3
    """
    assert asm == str(py.code.Source(expected)).strip() + '\n'
Beispiel #6
0
def test_format_assembler_simple():
    ssarepr = SSARepr("test")
    i0, i1, i2 = Register('int', 0), Register('int', 1), Register('int', 2)
    ssarepr.insns = [
        ('int_add', i0, i1, '->', i2),
        ('int_return', i2),
        ]
    asm = format_assembler(ssarepr)
    expected = """
        int_add %i0, %i1 -> %i2
        int_return %i2
    """
    assert asm == str(py.code.Source(expected)).strip() + '\n'
Beispiel #7
0
 def print_ssa_repr(self, ssarepr, portal_jitdriver, verbose):
     if verbose:
         print '%s:' % (ssarepr.name, )
         print format_assembler(ssarepr)
     else:
         log.dot()
     dir = udir.ensure("jitcodes", dir=1)
     if portal_jitdriver:
         name = "%02d_portal_runner" % (portal_jitdriver.index, )
     elif ssarepr.name and ssarepr.name != '?':
         name = ssarepr.name
     else:
         name = 'unnamed' % id(ssarepr)
     i = 1
     # escape <lambda> names for windows
     name = name.replace('<lambda>', '_(lambda)_')
     extra = ''
     while name + extra in self._seen_files:
         i += 1
         extra = '.%d' % i
     self._seen_files.add(name + extra)
     dir.join(name + extra).write(format_assembler(ssarepr))
Beispiel #8
0
def test_format_assembler_const_struct():
    S = lltype.GcStruct('S', ('x', lltype.Signed))
    s = lltype.malloc(S)
    s.x = 123
    ssarepr = SSARepr("test")
    ssarepr.insns = [
        ('foobar', '->', Constant(s, lltype.typeOf(s))),
        ]
    asm = format_assembler(ssarepr)
    expected = """
        foobar -> $<* struct S>
    """
    assert asm == str(py.code.Source(expected)).strip() + '\n'
Beispiel #9
0
def test_format_assembler_const_struct():
    S = lltype.GcStruct('S', ('x', lltype.Signed))
    s = lltype.malloc(S)
    s.x = 123
    ssarepr = SSARepr("test")
    ssarepr.insns = [
        ('foobar', '->', Constant(s, lltype.typeOf(s))),
    ]
    asm = format_assembler(ssarepr)
    expected = """
        foobar -> $<* struct S>
    """
    assert asm == str(py.code.Source(expected)).strip() + '\n'
Beispiel #10
0
def test_format_assembler_simple():
    ssarepr = SSARepr("test")
    i0, i1, i2 = Register('int', 0), Register('int', 1), Register('int', 2)
    ssarepr.insns = [
        ('int_add', i0, i1, '->', i2),
        ('int_return', i2),
    ]
    asm = format_assembler(ssarepr)
    expected = """
        int_add %i0, %i1 -> %i2
        int_return %i2
    """
    assert asm == str(py.code.Source(expected)).strip() + '\n'
Beispiel #11
0
def test_format_assembler_descr():
    class FooDescr(AbstractDescr):
        def __repr__(self):
            return 'hi_there!'
    ssarepr = SSARepr("test")
    ssarepr.insns = [
        ('foobar', FooDescr()),
        ]
    asm = format_assembler(ssarepr)
    expected = """
        foobar hi_there!
    """
    assert asm == str(py.code.Source(expected)).strip() + '\n'
Beispiel #12
0
def test_format_assembler_descr():
    class FooDescr(AbstractDescr):
        def __repr__(self):
            return 'hi_there!'

    ssarepr = SSARepr("test")
    ssarepr.insns = [
        ('foobar', FooDescr()),
    ]
    asm = format_assembler(ssarepr)
    expected = """
        foobar hi_there!
    """
    assert asm == str(py.code.Source(expected)).strip() + '\n'
Beispiel #13
0
 def assemble(self, ssarepr, jitcode=None):
     """Take the 'ssarepr' representation of the code and assemble
     it inside the 'jitcode'.  If jitcode is None, make a new one.
     """
     self.setup(ssarepr.name)
     ssarepr._insns_pos = []
     for insn in ssarepr.insns:
         ssarepr._insns_pos.append(len(self.code))
         self.write_insn(insn)
     self.fix_labels()
     self.check_result()
     if jitcode is None:
         jitcode = JitCode(ssarepr.name)
     jitcode._ssarepr = ssarepr
     self.make_jitcode(jitcode)
     if self._count_jitcodes < 20:  # stop if we have a lot of them
         jitcode._dump = format_assembler(ssarepr)
     self._count_jitcodes += 1
     return jitcode
Beispiel #14
0
 def assemble(self, ssarepr, jitcode=None):
     """Take the 'ssarepr' representation of the code and assemble
     it inside the 'jitcode'.  If jitcode is None, make a new one.
     """
     self.setup(ssarepr.name)
     ssarepr._insns_pos = []
     for insn in ssarepr.insns:
         ssarepr._insns_pos.append(len(self.code))
         self.write_insn(insn)
     self.fix_labels()
     self.check_result()
     if jitcode is None:
         jitcode = JitCode(ssarepr.name)
     jitcode._ssarepr = ssarepr
     self.make_jitcode(jitcode)
     if self._count_jitcodes < 20:    # stop if we have a lot of them
         jitcode._dump = format_assembler(ssarepr)
     self._count_jitcodes += 1
     return jitcode
Beispiel #15
0
def test_format_assembler_loop():
    ssarepr = SSARepr("test")
    i0, i1 = Register('int', 0), Register('int', 1)
    ssarepr.insns = [
        (Label('L1'),),
        ('goto_if_not_int_gt', i0, Constant(0, lltype.Signed), TLabel('L2')),
        ('int_add', i1, i0, '->', i1),
        ('int_sub', i0, Constant(1, lltype.Signed), '->', i0),
        ('goto', TLabel('L1')),
        (Label('L2'),),
        ('int_return', i1),
        ]
    asm = format_assembler(ssarepr)
    expected = """
        L1:
        goto_if_not_int_gt %i0, $0, L2
        int_add %i1, %i0 -> %i1
        int_sub %i0, $1 -> %i0
        goto L1
        L2:
        int_return %i1
    """
    assert asm == str(py.code.Source(expected)).strip() + '\n'
Beispiel #16
0
def test_format_assembler_loop():
    ssarepr = SSARepr("test")
    i0, i1 = Register('int', 0), Register('int', 1)
    ssarepr.insns = [
        (Label('L1'), ),
        ('goto_if_not_int_gt', i0, Constant(0, lltype.Signed), TLabel('L2')),
        ('int_add', i1, i0, '->', i1),
        ('int_sub', i0, Constant(1, lltype.Signed), '->', i0),
        ('goto', TLabel('L1')),
        (Label('L2'), ),
        ('int_return', i1),
    ]
    asm = format_assembler(ssarepr)
    expected = """
        L1:
        goto_if_not_int_gt %i0, $0, L2
        int_add %i1, %i0 -> %i1
        int_sub %i0, $1 -> %i0
        goto L1
        L2:
        int_return %i1
    """
    assert asm == str(py.code.Source(expected)).strip() + '\n'
Beispiel #17
0
 def dump(self):
     if self._ssarepr is None:
         return '<no dump available for %r>' % (self.name, )
     else:
         from pypy.jit.codewriter.format import format_assembler
         return format_assembler(self._ssarepr)
Beispiel #18
0
 def dump(self):
     if self._ssarepr is None:
         return '<no dump available for %r>' % (self.name,)
     else:
         from pypy.jit.codewriter.format import format_assembler
         return format_assembler(self._ssarepr)