annotate python/ppci/target/arm/__init__.py @ 342:86b02c98a717 devel

Moved target directory
author Windel Bouwman
date Sat, 01 Mar 2014 15:40:31 +0100
parents
children b4882ff0ed06
rev   line source
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
1
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
2 from ..basetarget import Target
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
3 from ..arm.registers import R0, R1, R2, R3, R4, R5, R6, R7, SP, LR, PC
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
4 from ..arm.registers import register_range
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
5
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
6 from .instructions import Mov
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
7
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
8 class ArmArmTarget(Target):
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
9 def __init__(self):
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
10 super().__init__('arm_arm')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
11
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
12 # Assembly grammar:
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
13 self.add_keyword('mov')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
14 self.add_keyword('r0')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
15 self.add_keyword('r1')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
16 self.add_keyword('r2')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
17 self.add_keyword('r3')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
18 self.add_keyword('r4')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
19 self.add_keyword('r5')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
20 self.add_keyword('r6')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
21 self.add_keyword('r7')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
22
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
23 self.add_rule('reg', ['r0'], lambda rhs: R0)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
24 self.add_rule('reg', ['r1'], lambda rhs: R1)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
25 self.add_rule('reg', ['r2'], lambda rhs: R2)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
26 self.add_rule('reg', ['r3'], lambda rhs: R3)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
27 self.add_rule('reg', ['r4'], lambda rhs: R4)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
28 self.add_rule('reg', ['r5'], lambda rhs: R5)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
29 self.add_rule('reg', ['r6'], lambda rhs: R6)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
30 self.add_rule('reg', ['r7'], lambda rhs: R7)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
31
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
32
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
33 self.add_instruction(['mov', 'reg', ',', 'imm8'],
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
34 lambda rhs: Mov(rhs[1], rhs[3]))
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
35
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
36 self.add_rule('imm32', ['val32'], lambda x: x[0].val)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
37 self.add_rule('imm32', ['imm8'], lambda x: x[0])
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
38 self.add_rule('imm8', ['val8'], lambda x: x[0].val)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
39 self.add_rule('imm8', ['imm5'], lambda x: x[0])
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
40 self.add_rule('imm5', ['val5'], lambda x: x[0].val)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
41 self.add_rule('imm5', ['imm3'], lambda x: x[0])
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
42 self.add_rule('imm3', ['val3'], lambda x: x[0].val)