Mercurial > lcfOS
comparison python/outstream.py @ 235:ff40407c0240
Fix ALabel to Label
author | Windel Bouwman |
---|---|
date | Mon, 15 Jul 2013 17:20:37 +0200 |
parents | 83781bd10fdb |
children | 8786811a5a59 |
comparison
equal
deleted
inserted
replaced
234:83781bd10fdb | 235:ff40407c0240 |
---|---|
14 | 14 |
15 def emit(self, item): | 15 def emit(self, item): |
16 assert isinstance(item, Instruction) | 16 assert isinstance(item, Instruction) |
17 self.sections[self.currentSection].append(item) | 17 self.sections[self.currentSection].append(item) |
18 | 18 |
19 def align(self, alignment): | |
20 self.emit(Alignment(alignment)) | |
21 | |
22 def selectSection(self, s): | 19 def selectSection(self, s): |
23 self.currentSection = s | 20 self.currentSection = s |
24 if not s in self.sections: | 21 if not s in self.sections: |
25 self.sections[s] = [] | 22 self.sections[s] = [] |
26 | 23 |
27 def getLabelAddress(self, l): | 24 def getLabelAddress(self, lname): |
28 assert isinstance(l, Label) | 25 assert isinstance(lname, str) |
29 for s in self.sections.values(): | 26 for s in self.sections.values(): |
30 for i in s: | 27 for i in s: |
31 if type(i) is Label: | 28 if type(i) is Label: |
32 if i.name == l.name: | 29 if i.name == lname: |
33 return i.address | 30 return i.address |
34 return 0 | 31 return 0 |
35 | 32 |
36 def backpatch(self): | 33 def backpatch(self): |
37 """ Fixup references to other parts in the assembler """ | 34 """ Fixup references to other parts in the assembler """ |
60 addr = i.address | 57 addr = i.address |
61 insword = i.encode() | 58 insword = i.encode() |
62 assert type(insword) is bytes | 59 assert type(insword) is bytes |
63 insword = binascii.hexlify(bytes(reversed(insword))).decode('ascii') | 60 insword = binascii.hexlify(bytes(reversed(insword))).decode('ascii') |
64 asm = str(i) | 61 asm = str(i) |
65 print(' 0x{0:08x} 0x{1} {2}'.format(addr, insword, asm)) | 62 if len(insword) == 0: |
63 print(' {}'.format(asm)) | |
64 else: | |
65 print(' 0x{0:08x} 0x{1} {2}'.format(addr, insword, asm)) | |
66 | 66 |
67 class TextOutputStream(OutputStream): | 67 class TextOutputStream(OutputStream): |
68 pass | 68 pass |
69 | 69 |
70 class BinOutputStream(OutputStream): | 70 class BinOutputStream(OutputStream): |