Mercurial > lcfOS
comparison python/target/basetarget.py @ 335:582a1aaa3983
Added long branch format
author | Windel Bouwman |
---|---|
date | Mon, 17 Feb 2014 20:41:30 +0100 |
parents | 6f4753202b9a |
children | 4d204f6f7d4e |
comparison
equal
deleted
inserted
replaced
334:6f4753202b9a | 335:582a1aaa3983 |
---|---|
56 | 56 |
57 | 57 |
58 class Instruction: | 58 class Instruction: |
59 """ Base instruction class """ | 59 """ Base instruction class """ |
60 def encode(self): | 60 def encode(self): |
61 raise NotImplementedError('Instruction {0} has no encode yet, TODO'.format(type(self))) | 61 return bytes() |
62 | 62 |
63 def resolve(self, f): | 63 def relocations(self): |
64 pass | 64 return [] |
65 | |
66 def symbols(self): | |
67 return [] | |
65 | 68 |
66 | 69 |
67 class Nop(Instruction): | 70 class Nop(Instruction): |
68 """ Instruction that does nothing and has zero size """ | 71 """ Instruction that does nothing and has zero size """ |
69 def encode(self): | 72 def encode(self): |
75 | 78 |
76 | 79 |
77 class Label(PseudoInstruction): | 80 class Label(PseudoInstruction): |
78 def __init__(self, name): | 81 def __init__(self, name): |
79 self.name = name | 82 self.name = name |
80 self.address = 0 | |
81 | 83 |
82 def __repr__(self): | 84 def __repr__(self): |
83 return '{}:'.format(self.name) | 85 return '{}:'.format(self.name) |
84 | 86 |
85 def encode(self): | 87 def symbols(self): |
86 return bytes() | 88 return [self.name] |
87 | 89 |
88 @classmethod | 90 @classmethod |
89 def Create(cls, vop): | 91 def Create(cls, vop): |
90 if type(vop) is ASymbol: | 92 if type(vop) is ASymbol: |
91 name = vop.name | 93 name = vop.name |
110 def __repr__(self): | 112 def __repr__(self): |
111 return 'ALIGN({})'.format(self.align) | 113 return 'ALIGN({})'.format(self.align) |
112 | 114 |
113 def encode(self): | 115 def encode(self): |
114 pad = [] | 116 pad = [] |
115 address = self.address | 117 # TODO |
118 address = 0 | |
116 while (address % self.align) != 0: | 119 while (address % self.align) != 0: |
117 address += 1 | 120 address += 1 |
118 pad.append(0) | 121 pad.append(0) |
119 return bytes(pad) | 122 return bytes(pad) |
120 | 123 |
123 def __init__(self, i): | 126 def __init__(self, i): |
124 self.info = i | 127 self.info = i |
125 | 128 |
126 def __repr__(self): | 129 def __repr__(self): |
127 return 'DebugInfo: {}'.format(self.info) | 130 return 'DebugInfo: {}'.format(self.info) |
128 | |
129 def encode(self): | |
130 return bytes() | |
131 | 131 |
132 | 132 |
133 class Register(Operand): | 133 class Register(Operand): |
134 def __init__(self, name): | 134 def __init__(self, name): |
135 self.name = name | 135 self.name = name |