Mercurial > lcfOS
diff python/ppci/outstream.py @ 348:442fb043d149
Added log option to zcc
author | Windel Bouwman |
---|---|
date | Sat, 08 Mar 2014 15:32:33 +0100 |
parents | 3bb7dcfe5529 |
children | 39bf68bf1891 |
line wrap: on
line diff
--- a/python/ppci/outstream.py Fri Mar 07 17:05:32 2014 +0100 +++ b/python/ppci/outstream.py Sat Mar 08 15:32:33 2014 +0100 @@ -1,3 +1,4 @@ +import logging import binascii from ppci.target import Instruction, Alignment from ppci.objectfile import ObjectFile @@ -12,7 +13,7 @@ def emit(self, item): raise NotImplementedError('Abstract base class') - def selectSection(self, sname): + def select_section(self, sname): raise NotImplementedError('Abstract base class') @@ -63,13 +64,43 @@ while section.Size % item.align != 0: section.add_data(bytes([0])) - def selectSection(self, sname): + def select_section(self, sname): self.currentSection = self.obj_file.get_section(sname) class DummyOutputStream(OutputStream): + """ Stream that implements the bare minimum and does nothing """ def emit(self, item): pass - def selectSection(self, sname): + def select_section(self, sname): pass + + +class LoggerOutputStream(OutputStream): + """ Stream that emits instructions as text in the log """ + def __init__(self): + self.logger = logging.getLogger('LoggerOutputStream') + + def emit(self, item): + self.logger.debug(str(item)) + + def select_section(self, sname): + self.logger.debug('.section {}'.format(sname)) + + +class MasterOutputStream(OutputStream): + """ Stream that emits to multiple sub streams """ + def __init__(self): + self.substreams = [] + + def add_substream(self, output_stream): + self.substreams.append(output_stream) + + def emit(self, item): + for output_stream in self.substreams: + output_stream.emit(item) + + def select_section(self, sname): + for output_stream in self.substreams: + output_stream.select_section(sname)