Mercurial > lcfOS
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/libs/compiler/core/bitreader.py Mon Dec 24 13:21:13 2012 +0100 @@ -0,0 +1,28 @@ +from .errors import CompilerException +import struct + +def bits(f): + while True: + Byte = f.read(1) + for i in range(8): + yield Byte & 0x1 + Byte >>= 1 + +class BitReader: + def __init__(self, f): + self.stream = bits(f) + self.curword = None + def parseModule(self): + if self.read(8) != ord('B') or self.read(8) != ord('C'): + raise CompilerException('Invalid bitcode signature') + for bitsig in [0x0, 0xC, 0xE, 0xD]: + if self.read(4) != bitsig: + raise CompilerException('Invalid bitcode signature') + + def read(self, numbits): + if numbits == 8: + b = self.stream.read(1) + print(b) + return int(b[0]) + return 2 +