changeset 94:1be00bcfaabb

Last parts before movage
author windel
date Mon, 24 Dec 2012 13:21:13 +0100
parents f7ec7517cabb
children 4a37d6992bd3
files python/libs/compiler/core/bitreader.py python/libs/compiler/core/module.py python/libs/compiler/test.py
diffstat 3 files changed, 40 insertions(+), 0 deletions(-) [+]
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
+
--- /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
+   
--- /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)
+