annotate python/target/armregisters.py @ 341:4d204f6f7d4e devel

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