Mercurial > lcfOS
comparison python/outstream.py @ 249:e41e4109addd
Added current position arrow
author | Windel Bouwman |
---|---|
date | Fri, 26 Jul 2013 20:26:05 +0200 |
parents | 81752b0f85a5 |
children | f5fba5b554d7 |
comparison
equal
deleted
inserted
replaced
248:b10d46e5c8dd | 249:e41e4109addd |
---|---|
1 import binascii | 1 import binascii |
2 from target import Instruction, Label | 2 from target import Instruction, Label, DebugInfo |
3 | 3 |
4 """ | 4 """ |
5 The output stream is a stream of instructions that can be output | 5 The output stream is a stream of instructions that can be output |
6 to a file or binary or hexfile. | 6 to a file or binary or hexfile. |
7 """ | 7 """ |
22 insword = i.encode() | 22 insword = i.encode() |
23 assert type(insword) is bytes | 23 assert type(insword) is bytes |
24 d.extend(insword) | 24 d.extend(insword) |
25 return bytes(d) | 25 return bytes(d) |
26 | 26 |
27 def debugInfos(self): | |
28 di = [i for i in self.instructions if isinstance(i, DebugInfo)] | |
29 return di | |
30 | |
27 class OutputStream: | 31 class OutputStream: |
28 def __init__(self): | 32 def __init__(self): |
29 self.sections = {} | 33 self.sections = {} |
30 self.currentSection = None | 34 self.currentSection = None |
31 | 35 |
33 assert self.currentSection | 37 assert self.currentSection |
34 self.sections[self.currentSection].emit(item) | 38 self.sections[self.currentSection].emit(item) |
35 | 39 |
36 def selectSection(self, s): | 40 def selectSection(self, s): |
37 self.currentSection = s | 41 self.currentSection = s |
38 if not s in self.sections: | 42 self.getSection(s) |
39 self.sections[s] = Section() | |
40 | 43 |
41 def getLabelAddress(self, lname): | 44 def getLabelAddress(self, lname): |
42 assert isinstance(lname, str) | 45 assert isinstance(lname, str) |
43 for s in self.sections.values(): | 46 for s in self.sections.values(): |
44 for i in s.instructions: | 47 for i in s.instructions: |
45 if type(i) is Label: | 48 if type(i) is Label: |
46 if i.name == lname: | 49 if i.name == lname: |
47 return i.address | 50 return i.address |
48 return 0 | 51 return 0 |
52 | |
53 def getSection(self, name): | |
54 if not name in self.sections: | |
55 self.sections[name] = Section() | |
56 return self.sections[name] | |
49 | 57 |
50 def backpatch(self): | 58 def backpatch(self): |
51 """ Fixup references to other parts in the assembler """ | 59 """ Fixup references to other parts in the assembler """ |
52 for s in self.sections: | 60 for s in self.sections: |
53 # TODO parameterize this: | 61 # TODO parameterize this: |