annotate python/ppci/target/arm/registers.py @ 353:b8ad45b3a573

Started with strings
author Windel Bouwman
date Sun, 09 Mar 2014 18:49:10 +0100
parents 86b02c98a717
children
rev   line source
340
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
1
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
2 from ..basetarget import Register
340
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
3
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
4 class ArmRegister(Register):
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
5 def __init__(self, num, name):
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
6 super().__init__(name)
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
7 self.num = num
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
8
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
9 def __repr__(self):
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
10 return self.name
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
11
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
12
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
13 class Reg8Op(ArmRegister):
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
14 pass
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
15
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
16
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
17 def get_register(n):
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
18 for x in registers:
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
19 if x.num == n:
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
20 return x
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
21 raise Exception('No register found with this number')
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
22
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
23 def register_range(a, b):
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
24 """ Return set of registers from a to b """
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
25 assert a.num < b.num
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
26 return {get_register(n) for n in range(a.num, b.num + 1)}
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
27
340
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
28
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
29 R0 = Reg8Op(0, 'r0')
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
30 R1 = Reg8Op(1, 'r1')
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
31 R2 = Reg8Op(2, 'r2')
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
32 R3 = Reg8Op(3, 'r3')
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
33 R4 = Reg8Op(4, 'r4')
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
34 R5 = Reg8Op(5, 'r5')
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
35 R6 = Reg8Op(6, 'r6')
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
36 R7 = Reg8Op(7, 'r7')
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
37 R8 = ArmRegister(8, 'r8')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
38 R9 = ArmRegister(9, 'r9')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
39 R10 = ArmRegister(10, 'r10')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
40 R11 = ArmRegister(11, 'r11')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
41 R12 = ArmRegister(12, 'r12')
340
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
42
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
43 # Other registers:
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
44 # TODO
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
45 SP = ArmRegister(13, 'sp')
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
46 LR = ArmRegister(14, 'lr')
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
47 PC = ArmRegister(15, 'pc')
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
48
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents:
diff changeset
49 registers = [R0, R1, R2, R3, R4, R5, R6, R7, SP, LR, PC]