Mercurial > lcfOS
diff python/target/armtoken.py @ 340:c7cc54c0dfdf devel
Test featurebranch
author | Windel Bouwman |
---|---|
date | Sun, 23 Feb 2014 16:24:01 +0100 |
parents | |
children | 4d204f6f7d4e |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/target/armtoken.py Sun Feb 23 16:24:01 2014 +0100 @@ -0,0 +1,53 @@ + +def val2bit(v, bits): + b = [] + for i in range(bits): + b.append(bool((1<<i) & v)) + #b.reverse() + return b + + +def bit_range(b, e): + getter = lambda s: s[b:e] + def setter(s, v): + s[b:e] = v + return property(getter, setter) + + +class ThumbToken: + def __init__(self): + self.bit_value = 0 + + def set_bit(self, i, value): + value = bool(value) + assert i in range(0, 16) + mask = 1 << i + if value: + self.bit_value |= mask + else: + self.bit_value &= (~mask) + + def __getitem__(self, key): + return False + + def __setitem__(self, key, value): + if type(key) is int: + self.set_bit(key, value) + elif type(key) is slice: + assert key.step is None + bits = key.stop - key.start + value_bits = val2bit(value, bits) + for i in range(key.start, key.stop): + self.set_bit(i, value_bits[i - key.start]) + else: + raise KeyError() + + rd = bit_range(0, 3) + + def encode(self): + return u16(self.bit_value) + + +class ArmToken: + pass +