# HG changeset patch # User windel # Date 1356351673 -3600 # Node ID 1be00bcfaabb95d376b112092e135e8bc52d9c0c # Parent f7ec7517cabbc159424a03365ecfac4676cd3c85 Last parts before movage diff -r f7ec7517cabb -r 1be00bcfaabb python/libs/compiler/core/bitreader.py --- /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 + diff -r f7ec7517cabb -r 1be00bcfaabb python/libs/compiler/core/module.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/libs/compiler/core/module.py Mon Dec 24 13:21:13 2012 +0100 @@ -0,0 +1,4 @@ + +class Module: + pass + diff -r f7ec7517cabb -r 1be00bcfaabb python/libs/compiler/test.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/libs/compiler/test.py Mon Dec 24 13:21:13 2012 +0100 @@ -0,0 +1,8 @@ + +from core import BitReader + +with open('main.s.bc', 'rb') as f: + br = BitReader(f) + br.parseModule() + print(br) +