comparison python/ppci/target/arm/__init__.py @ 345:b4882ff0ed06

Added more arm isa tests
author Windel Bouwman
date Sun, 02 Mar 2014 17:12:08 +0100
parents 86b02c98a717
children 3bb7dcfe5529
comparison
equal deleted inserted replaced
344:1378c4b027a0 345:b4882ff0ed06
1 1
2 from ..basetarget import Target 2 from ..basetarget import Target
3 from ..arm.registers import R0, R1, R2, R3, R4, R5, R6, R7, SP, LR, PC 3 from ..arm.registers import R0, R1, R2, R3, R4, R5, R6, R7
4 from ..arm.registers import R8, R9, R10, R11, R12, SP, LR, PC
4 from ..arm.registers import register_range 5 from ..arm.registers import register_range
5 6
6 from .instructions import Mov 7 from .instructions import Mov, Add, Sub, Orr1, B, Bl, Ble, Bgt, Beq
7 8
8 class ArmArmTarget(Target): 9 class ArmTarget(Target):
9 def __init__(self): 10 def __init__(self):
10 super().__init__('arm_arm') 11 super().__init__('arm_arm')
11 12
12 # Assembly grammar: 13 # Assembly grammar:
13 self.add_keyword('mov')
14 self.add_keyword('r0') 14 self.add_keyword('r0')
15 self.add_keyword('r1') 15 self.add_keyword('r1')
16 self.add_keyword('r2') 16 self.add_keyword('r2')
17 self.add_keyword('r3') 17 self.add_keyword('r3')
18 self.add_keyword('r4') 18 self.add_keyword('r4')
19 self.add_keyword('r5') 19 self.add_keyword('r5')
20 self.add_keyword('r6') 20 self.add_keyword('r6')
21 self.add_keyword('r7') 21 self.add_keyword('r7')
22 self.add_keyword('r8')
23 self.add_keyword('r9')
24 self.add_keyword('r10')
25 self.add_keyword('r11')
26 self.add_keyword('r12')
22 27
23 self.add_rule('reg', ['r0'], lambda rhs: R0) 28 self.add_rule('reg', ['r0'], lambda rhs: R0)
24 self.add_rule('reg', ['r1'], lambda rhs: R1) 29 self.add_rule('reg', ['r1'], lambda rhs: R1)
25 self.add_rule('reg', ['r2'], lambda rhs: R2) 30 self.add_rule('reg', ['r2'], lambda rhs: R2)
26 self.add_rule('reg', ['r3'], lambda rhs: R3) 31 self.add_rule('reg', ['r3'], lambda rhs: R3)
27 self.add_rule('reg', ['r4'], lambda rhs: R4) 32 self.add_rule('reg', ['r4'], lambda rhs: R4)
28 self.add_rule('reg', ['r5'], lambda rhs: R5) 33 self.add_rule('reg', ['r5'], lambda rhs: R5)
29 self.add_rule('reg', ['r6'], lambda rhs: R6) 34 self.add_rule('reg', ['r6'], lambda rhs: R6)
30 self.add_rule('reg', ['r7'], lambda rhs: R7) 35 self.add_rule('reg', ['r7'], lambda rhs: R7)
36 self.add_rule('reg', ['r8'], lambda rhs: R8)
37 self.add_rule('reg', ['r9'], lambda rhs: R9)
38 self.add_rule('reg', ['r10'], lambda rhs: R10)
39 self.add_rule('reg', ['r11'], lambda rhs: R11)
40 self.add_rule('reg', ['r12'], lambda rhs: R12)
31 41
32 42
43 self.add_keyword('mov')
33 self.add_instruction(['mov', 'reg', ',', 'imm8'], 44 self.add_instruction(['mov', 'reg', ',', 'imm8'],
34 lambda rhs: Mov(rhs[1], rhs[3])) 45 lambda rhs: Mov(rhs[1], rhs[3]))
35 46
36 self.add_rule('imm32', ['val32'], lambda x: x[0].val) 47 self.add_keyword('add')
37 self.add_rule('imm32', ['imm8'], lambda x: x[0]) 48 self.add_instruction(['add', 'reg', ',', 'reg', ',', 'imm32'],
38 self.add_rule('imm8', ['val8'], lambda x: x[0].val) 49 lambda rhs: Add(rhs[1], rhs[3], rhs[5]))
39 self.add_rule('imm8', ['imm5'], lambda x: x[0]) 50
40 self.add_rule('imm5', ['val5'], lambda x: x[0].val) 51 self.add_instruction(['add', 'reg', ',', 'reg', ',', 'reg'],
41 self.add_rule('imm5', ['imm3'], lambda x: x[0]) 52 lambda rhs: Add(rhs[1], rhs[3], rhs[5]))
42 self.add_rule('imm3', ['val3'], lambda x: x[0].val) 53
54 self.add_keyword('sub')
55 self.add_instruction(['sub', 'reg', ',', 'reg', ',', 'imm32'],
56 lambda rhs: Sub(rhs[1], rhs[3], rhs[5]))
57
58 self.add_instruction(['sub', 'reg', ',', 'reg', ',', 'reg'],
59 lambda rhs: Sub(rhs[1], rhs[3], rhs[5]))
60
61 self.add_keyword('orr')
62 self.add_instruction(['orr', 'reg', ',', 'reg', ',', 'reg'],
63 lambda rhs: Orr1(rhs[1], rhs[3], rhs[5]))
64
65
66 # Jumping:
67 self.add_keyword('b')
68 self.add_instruction(['b', 'ID'], lambda rhs: B(rhs[1].val))
69 self.add_keyword('ble')
70 self.add_instruction(['ble', 'ID'], lambda rhs: Ble(rhs[1].val))
71 self.add_keyword('bgt')
72 self.add_instruction(['bgt', 'ID'], lambda rhs: Bgt(rhs[1].val))
73 self.add_keyword('beq')
74 self.add_instruction(['beq', 'ID'], lambda rhs: Beq(rhs[1].val))
75
76 self.add_keyword('bl')
77 self.add_instruction(['bl', 'ID'], lambda rhs: Bl(rhs[1].val))