comparison python/target/armtoken.py @ 341:4d204f6f7d4e devel

Rewrite of assembler parts
author Windel Bouwman
date Fri, 28 Feb 2014 18:07:14 +0100
parents c7cc54c0dfdf
children
comparison
equal deleted inserted replaced
340:c7cc54c0dfdf 341:4d204f6f7d4e
1
2 import struct
3
4 def u16(h):
5 return struct.pack('<H', h)
1 6
2 def val2bit(v, bits): 7 def val2bit(v, bits):
3 b = [] 8 b = []
4 for i in range(bits): 9 for i in range(bits):
5 b.append(bool((1<<i) & v)) 10 b.append(bool((1<<i) & v))
12 def setter(s, v): 17 def setter(s, v):
13 s[b:e] = v 18 s[b:e] = v
14 return property(getter, setter) 19 return property(getter, setter)
15 20
16 21
17 class ThumbToken: 22 class Token:
18 def __init__(self):
19 self.bit_value = 0
20
21 def set_bit(self, i, value): 23 def set_bit(self, i, value):
22 value = bool(value) 24 value = bool(value)
23 assert i in range(0, 16) 25 assert i in range(0, 16)
24 mask = 1 << i 26 mask = 1 << i
25 if value: 27 if value:
40 for i in range(key.start, key.stop): 42 for i in range(key.start, key.stop):
41 self.set_bit(i, value_bits[i - key.start]) 43 self.set_bit(i, value_bits[i - key.start])
42 else: 44 else:
43 raise KeyError() 45 raise KeyError()
44 46
47 class ThumbToken(Token):
48 def __init__(self):
49 self.bit_value = 0
50
51
45 rd = bit_range(0, 3) 52 rd = bit_range(0, 3)
46 53
47 def encode(self): 54 def encode(self):
48 return u16(self.bit_value) 55 return u16(self.bit_value)
49 56
50 57
51 class ArmToken: 58 class ArmToken(Token):
52 pass 59 def __init__(self):
60 self.bit_value = 0
53 61