comparison python/outstream.py @ 250:f5fba5b554d7

Removal of obsolete editor
author Windel Bouwman
date Sun, 28 Jul 2013 19:07:51 +0200
parents e41e4109addd
children 04c19282a5aa
comparison
equal deleted inserted replaced
249:e41e4109addd 250:f5fba5b554d7
7 """ 7 """
8 8
9 9
10 class Section: 10 class Section:
11 def __init__(self): 11 def __init__(self):
12 self.address = 0
12 self.instructions = [] 13 self.instructions = []
13 14
14 def emit(self, item): 15 def emit(self, item):
15 assert isinstance(item, Instruction) 16 assert isinstance(item, Instruction)
16 self.instructions.append(item) 17 self.instructions.append(item)
33 self.sections = {} 34 self.sections = {}
34 self.currentSection = None 35 self.currentSection = None
35 36
36 def emit(self, item): 37 def emit(self, item):
37 assert self.currentSection 38 assert self.currentSection
38 self.sections[self.currentSection].emit(item) 39 self.currentSection.emit(item)
39 40
40 def selectSection(self, s): 41 def selectSection(self, sname):
41 self.currentSection = s 42 self.currentSection = self.getSection(sname)
42 self.getSection(s)
43 43
44 def getLabelAddress(self, lname): 44 def getLabelAddress(self, lname):
45 assert isinstance(lname, str) 45 assert isinstance(lname, str)
46 for s in self.sections.values(): 46 for s in self.sections.values():
47 for i in s.instructions: 47 for i in s.instructions:
55 self.sections[name] = Section() 55 self.sections[name] = Section()
56 return self.sections[name] 56 return self.sections[name]
57 57
58 def backpatch(self): 58 def backpatch(self):
59 """ Fixup references to other parts in the assembler """ 59 """ Fixup references to other parts in the assembler """
60 for s in self.sections: 60 for s in self.sections.values():
61 # TODO parameterize this: 61 address = s.address
62 if s == 'code': 62 for i in s.instructions:
63 address = 0x08000000
64 elif s == 'data':
65 address = 0x02000000
66 else:
67 address = 0x0
68
69 for i in self.sections[s].instructions:
70 i.address = address 63 i.address = address
71 i.resolve(self.getLabelAddress) 64 i.resolve(self.getLabelAddress)
72 bts = i.encode() 65 bts = i.encode()
73 address += len(bts) 66 address += len(bts)
74 67