diff python/ppci/outstream.py @ 366:39bf68bf1891

Fix sample tests and deterministic build
author Windel Bouwman
date Fri, 21 Mar 2014 09:43:01 +0100
parents 442fb043d149
children 6df89163e114
line wrap: on
line diff
--- a/python/ppci/outstream.py	Wed Mar 19 22:32:04 2014 +0100
+++ b/python/ppci/outstream.py	Fri Mar 21 09:43:01 2014 +0100
@@ -1,7 +1,7 @@
 import logging
 import binascii
-from ppci.target import Instruction, Alignment
-from ppci.objectfile import ObjectFile
+from .target import Instruction, Alignment
+from .objectfile import ObjectFile
 
 """
  The output stream is a stream of instructions that can be output
@@ -10,6 +10,7 @@
 
 
 class OutputStream:
+    """ Interface to generator code with. """
     def emit(self, item):
         raise NotImplementedError('Abstract base class')
 
@@ -17,28 +18,6 @@
         raise NotImplementedError('Abstract base class')
 
 
-class OutputStreamWriter:
-    def __init__(self, extra_indent=''):
-        self.extra_indent = extra_indent
-
-    def dump(self, stream, f):
-        for s in sorted(stream.sections.keys()):
-            # print('.section '+ s)
-            self.dumpSection(stream.sections[s], f)
-
-    def dumpSection(self, s, f):
-        for i in s.instructions:
-            addr = i.address
-            insword = i.encode()
-            assert type(insword) is bytes
-            insword = binascii.hexlify(bytes(reversed(insword))).decode('ascii')
-            asm = str(i)
-            if len(insword) == 0:
-                print('        {}'.format(asm), file=f)
-            else:
-                print('    0x{0:08x} 0x{1} {2}'.format(addr, insword, asm), file=f)
-
-
 class BinaryOutputStream(OutputStream):
     """ Output stream that writes to object file """
     def __init__(self, obj_file):
@@ -91,8 +70,8 @@
 
 class MasterOutputStream(OutputStream):
     """ Stream that emits to multiple sub streams """
-    def __init__(self):
-        self.substreams = []
+    def __init__(self, substreams=[]):
+        self.substreams = list(substreams)  # Use copy constructor!!!
 
     def add_substream(self, output_stream):
         self.substreams.append(output_stream)