Mercurial > lcfOS
comparison python/ppci/target/arm/frame.py @ 353:b8ad45b3a573
Started with strings
author | Windel Bouwman |
---|---|
date | Sun, 09 Mar 2014 18:49:10 +0100 |
parents | 3bb7dcfe5529 |
children | 5477e499b039 |
comparison
equal
deleted
inserted
replaced
352:899ae3aea803 | 353:b8ad45b3a573 |
---|---|
1 from ... import ir | 1 from ... import ir |
2 from ..basetarget import Label, Alignment | 2 from ..basetarget import Label, Alignment |
3 from ...irmach import AbstractInstruction, Frame | 3 from ...irmach import AbstractInstruction, Frame |
4 from .instructions import Dcd, Add, Sub, Push, Pop, Mov | 4 from .instructions import Dcd, Add, Sub, Push, Pop, Mov, Db |
5 from .registers import R0, R1, R2, R3, R4, R5, R6, R7, R8, R11, LR, PC, SP | 5 from .registers import R0, R1, R2, R3, R4, R5, R6, R7, R8, R11, LR, PC, SP |
6 | 6 |
7 | 7 |
8 class ArmFrame(Frame): | 8 class ArmFrame(Frame): |
9 """ Arm specific frame for functions. """ | 9 """ Arm specific frame for functions. """ |
49 if lvar not in self.locVars: | 49 if lvar not in self.locVars: |
50 self.locVars[lvar] = self.stacksize | 50 self.locVars[lvar] = self.stacksize |
51 self.stacksize = self.stacksize + 4 | 51 self.stacksize = self.stacksize + 4 |
52 return self.locVars[lvar] | 52 return self.locVars[lvar] |
53 | 53 |
54 def addConstant(self, value): | 54 def add_constant(self, value): |
55 lab_name = '{}_literal_{}'.format(self.name, len(self.constants)) | 55 lab_name = '{}_literal_{}'.format(self.name, len(self.constants)) |
56 self.constants.append((lab_name, value)) | 56 self.constants.append((lab_name, value)) |
57 return lab_name | 57 return lab_name |
58 | 58 |
59 def prologue(self): | 59 def prologue(self): |
76 post.append(Add(SP, SP, self.stacksize)) | 76 post.append(Add(SP, SP, self.stacksize)) |
77 post += [ | 77 post += [ |
78 Pop({PC, R11}), | 78 Pop({PC, R11}), |
79 Alignment(4) # Align at 4 bytes | 79 Alignment(4) # Align at 4 bytes |
80 ] | 80 ] |
81 | |
81 # Add constant literals: | 82 # Add constant literals: |
82 for ln, v in self.constants: | 83 for ln, v in self.constants: |
83 post.extend([Label(ln), Dcd(v)]) | 84 if isinstance(v, int): |
85 post.extend([Label(ln), Dcd(v)]) | |
86 elif isinstance(v, str): | |
87 post.extend([Label(ln), Dcd(len(v))]) | |
88 for c in v: | |
89 post.append(Db(ord(c))) | |
90 post.append(Alignment(4)) # Align at 4 bytes | |
91 else: | |
92 raise Exception() | |
84 return post | 93 return post |
85 | 94 |
86 def EntryExitGlue3(self): | 95 def EntryExitGlue3(self): |
87 """ | 96 """ |
88 Add code for the prologue and the epilogue. Add a label, the | 97 Add code for the prologue and the epilogue. Add a label, the |