Mercurial > lcfOS
comparison python/ppci/target/arm/__init__.py @ 386:2a970e7270e2
Added repeat assembler macro
author | Windel Bouwman |
---|---|
date | Thu, 01 May 2014 17:40:59 +0200 |
parents | 6df89163e114 |
children | c0d9837acde8 |
comparison
equal
deleted
inserted
replaced
385:d056b552d3f4 | 386:2a970e7270e2 |
---|---|
19 def __init__(self, target): | 19 def __init__(self, target): |
20 super().__init__(target) | 20 super().__init__(target) |
21 self.target.add_keyword('section') | 21 self.target.add_keyword('section') |
22 self.target.add_instruction(['section', 'ID'], | 22 self.target.add_instruction(['section', 'ID'], |
23 lambda rhs: self.select_section(rhs[1].val)) | 23 lambda rhs: self.select_section(rhs[1].val)) |
24 self.target.add_keyword('repeat') | |
25 self.target.add_keyword('endrepeat') | |
26 self.target.add_instruction(['repeat', 'imm32'], self.begin_repeat) | |
27 self.target.add_instruction(['endrepeat'], self.end_repeat) | |
28 | |
24 self.make_parser() | 29 self.make_parser() |
25 self.lit_pool = [] | 30 self.lit_pool = [] |
26 self.lit_counter = 0 | 31 self.lit_counter = 0 |
32 self.inMacro = False | |
33 | |
34 def prepare(self): | |
35 self.inMacro = False | |
36 | |
37 def begin_repeat(self, rhs): | |
38 if self.inMacro: | |
39 raise Exception() | |
40 self.inMacro = True | |
41 self.rep_count = rhs[1] | |
42 self.recording = [] | |
43 | |
44 def end_repeat(self, rhs): | |
45 if not self.inMacro: | |
46 raise Exception() | |
47 self.inMacro = False | |
48 for rec in self.recording * self.rep_count: | |
49 self.emit(*rec) | |
50 | |
51 def emit(self, *args): | |
52 if self.inMacro: | |
53 self.recording.append(args) | |
54 else: | |
55 super().emit(*args) | |
27 | 56 |
28 def select_section(self, name): | 57 def select_section(self, name): |
29 self.flush() | 58 self.flush() |
30 self.stream.select_section(name) | 59 self.stream.select_section(name) |
31 | 60 |
32 def flush(self): | 61 def flush(self): |
62 if self.inMacro: | |
63 raise Exception() | |
33 while self.lit_pool: | 64 while self.lit_pool: |
34 i = self.lit_pool.pop(0) | 65 i = self.lit_pool.pop(0) |
35 self.emit(i) | 66 self.emit(i) |
36 | 67 |
37 def add_literal(self, v): | 68 def add_literal(self, v): |
40 self.lit_counter += 1 | 71 self.lit_counter += 1 |
41 label_name = "_lit_{}".format(self.lit_counter) | 72 label_name = "_lit_{}".format(self.lit_counter) |
42 self.lit_pool.append(Label(label_name)) | 73 self.lit_pool.append(Label(label_name)) |
43 self.lit_pool.append(Dcd(v)) | 74 self.lit_pool.append(Dcd(v)) |
44 return label_name | 75 return label_name |
76 | |
45 | 77 |
46 class ArmTarget(Target): | 78 class ArmTarget(Target): |
47 def __init__(self): | 79 def __init__(self): |
48 super().__init__('arm') | 80 super().__init__('arm') |
49 self.make_parser() | 81 self.make_parser() |