comparison python/libs/compiler/core/bitreader.py @ 94:1be00bcfaabb

Last parts before movage
author windel
date Mon, 24 Dec 2012 13:21:13 +0100
parents
children
comparison
equal deleted inserted replaced
93:f7ec7517cabb 94:1be00bcfaabb
1 from .errors import CompilerException
2 import struct
3
4 def bits(f):
5 while True:
6 Byte = f.read(1)
7 for i in range(8):
8 yield Byte & 0x1
9 Byte >>= 1
10
11 class BitReader:
12 def __init__(self, f):
13 self.stream = bits(f)
14 self.curword = None
15 def parseModule(self):
16 if self.read(8) != ord('B') or self.read(8) != ord('C'):
17 raise CompilerException('Invalid bitcode signature')
18 for bitsig in [0x0, 0xC, 0xE, 0xD]:
19 if self.read(4) != bitsig:
20 raise CompilerException('Invalid bitcode signature')
21
22 def read(self, numbits):
23 if numbits == 8:
24 b = self.stream.read(1)
25 print(b)
26 return int(b[0])
27 return 2
28