comparison python/outstream.py @ 225:1c7364bd74c7

Fixed pointer deref
author Windel Bouwman
date Thu, 11 Jul 2013 07:42:30 +0200
parents 1fa3e0050b49
children 83781bd10fdb
comparison
equal deleted inserted replaced
224:5af52987f5bd 225:1c7364bd74c7
1 import binascii 1 import binascii
2 from asmnodes import ALabel 2 from asmnodes import ALabel, AComment
3 """ 3 """
4 The output stream is a stream of instructions that can be output 4 The output stream is a stream of instructions that can be output
5 to a file or binary or hexfile. 5 to a file or binary or hexfile.
6 """ 6 """
7 7
11 11
12 class OutputStream: 12 class OutputStream:
13 def __init__(self): 13 def __init__(self):
14 self.sections = {} 14 self.sections = {}
15 self.currentSection = None 15 self.currentSection = None
16
16 def emit(self, item): 17 def emit(self, item):
17 self.sections[self.currentSection].append(item) 18 self.sections[self.currentSection].append(item)
18 19
19 def align(self, alignment): 20 def align(self, alignment):
20 self.emit(Alignment(alignment)) 21 self.emit(Alignment(alignment))
34 address = 0x02000000 35 address = 0x02000000
35 else: 36 else:
36 address = 0x0 37 address = 0x0
37 for i in self.sections[s]: 38 for i in self.sections[s]:
38 i.address = address 39 i.address = address
39 if type(i) is ALabel: 40 if type(i) in [ALabel, AComment]:
40 continue 41 continue
41 if type(i) is Alignment: 42 if type(i) is Alignment:
42 while (address % i.align) != 0: 43 while (address % i.align) != 0:
43 address += 1 44 address += 1
44 continue 45 continue
51 self.dumpSection(s) 52 self.dumpSection(s)
52 53
53 def dumpSection(self, s): 54 def dumpSection(self, s):
54 print('.section '+s) 55 print('.section '+s)
55 for i in self.sections[s]: 56 for i in self.sections[s]:
56 if type(i) is ALabel: 57 if type(i) in [ALabel, AComment]:
57 print(i) 58 print(i)
58 elif type(i) is Alignment: 59 elif type(i) is Alignment:
59 pass 60 pass
60 else: 61 else:
61 addr = i.address 62 addr = i.address