Mercurial > lcfOS
view python/ppci/core/bitreader.py @ 101:af0d7913677a
Fixes and splitting into 3 stage
author | windel |
---|---|
date | Mon, 24 Dec 2012 17:55:08 +0100 |
parents | 4a37d6992bd3 |
children | ed230e947dc6 |
line wrap: on
line source
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