Debian Codegraph @

rpython/jit/backend/ppc/test/test_form.py

raw symbols SCIP
1 from py.test import raises
2
3 from rpython.jit.backend.ppc.form import Form, FormException
4 from rpython.jit.backend.ppc.field import Field
5 from rpython.jit.backend.ppc.opassembler import OpAssembler as Assembler
6
7 # 0 31
8 # +-------------------------------+
9 # | h | l |
10 # +-------------------------------+
11 # | hh | hl | lh | ll |
12 # +-------------------------------+
13
14 test_fieldmap = {
15 'l' : Field('l', 16, 31),
16 'h' : Field('h', 0, 15),
17 'll': Field('ll', 24, 31),
18 'lh': Field('lh', 16, 23),
19 'hl': Field('hl', 8, 15),
20 'hh': Field('hh', 0, 7),
21 }
22
23 def p(a):
24 import struct
25 w = a.insts[-1].assemble()
26 return struct.pack('>i', w)
27
28 class TForm(Form):
29 fieldmap = test_fieldmap
30
31 class TestForms(object):
32 def test_bitclash(self):
33 raises(FormException, TForm, 'h', 'hh')
34 raises(FormException, TForm,
35 Field('t1', 0, 0), Field('t2', 0, 0))
36
37 def test_basic(self):
38 class T(Assembler):
39 i = TForm('h', 'l')()
40 j = i(h=1)
41 k = i(l=3)
42 raises(FormException, k, l=0)
43 insts = []
44 a = T()
45 a.i(5, 6)
46 assert p(a) == '\000\005\000\006'
47 a = T()
48 a.j(2)
49 assert p(a) == '\000\001\000\002'
50 a = T()
51 a.k(4)
52 assert p(a) == '\000\004\000\003'
53
54 def test_defdesc(self):
55 class T(Assembler):
56 i = TForm('hh', 'hl', 'lh', 'll')()
57 i.default(hl=0).default(hh=1)
58 insts = []
59 a = T()
60 a.i(1, 2, 3, 4)
61 assert p(a) == '\001\002\003\004'
62 a = T()
63 a.i(1, 3, 4)
64 assert p(a) == '\001\000\003\004'
65 a = T()
66 a.i(3, 4)
67 assert p(a) == '\001\000\003\004'