comparison python/target.py @ 235:ff40407c0240

Fix ALabel to Label
author Windel Bouwman
date Mon, 15 Jul 2013 17:20:37 +0200
parents 83781bd10fdb
children 8786811a5a59
comparison
equal deleted inserted replaced
234:83781bd10fdb 235:ff40407c0240
1 from asmnodes import ASymbol, AInstruction, ALabel, ANumber 1 from asmnodes import ASymbol, AInstruction, ANumber
2 from ppci import CompilerError 2 from ppci import CompilerError
3 3
4 """ 4 """
5 Base classes for defining a target 5 Base classes for defining a target
6 """ 6 """
31 @classmethod 31 @classmethod
32 def Create(cls, vop): 32 def Create(cls, vop):
33 if type(vop) is ANumber and vop.number < 8: 33 if type(vop) is ANumber and vop.number < 8:
34 return cls(vop.number) 34 return cls(vop.number)
35 35
36 class Imm32:
37 def __init__(self, imm):
38 assert imm < 2**32
39 assert type(imm) is int
40 self.imm = imm
41
42 @classmethod
43 def Create(cls, vop):
44 if type(vop) is ANumber and vop.number < 2**32:
45 return cls(vop.number)
46
47
48 class LabelRef:
49 def __init__(self, name):
50 self.name = name
51
52 @classmethod
53 def Create(cls, vop):
54 if type(vop) is ASymbol:
55 return cls(vop.name)
56
36 class Instruction: 57 class Instruction:
37 def encode(self): 58 def encode(self):
38 raise NotImplementedError('Instruction {0} has no encode yet, TODO'.format(type(self))) 59 raise NotImplementedError('Instruction {0} has no encode yet, TODO'.format(type(self)))
39 def resolve(self, f): 60 def resolve(self, f):
40 pass 61 pass
47 class Label(PseudoInstruction): 68 class Label(PseudoInstruction):
48 def __init__(self, name): 69 def __init__(self, name):
49 self.name = name 70 self.name = name
50 self.address = 0 71 self.address = 0
51 72
73 def __repr__(self):
74 return '{}:'.format(self.name)
75
76 def encode(self):
77 return bytes()
78
52 @classmethod 79 @classmethod
53 def Create(cls, vop): 80 def Create(cls, vop):
54 if type(vop) is ASymbol: 81 if type(vop) is ASymbol:
55 name = vop.name 82 name = vop.name
56 return cls(name) 83 return cls(name)
57 84
85
58 class Comment(PseudoInstruction): 86 class Comment(PseudoInstruction):
59 def __init__(self, txt): 87 def __init__(self, txt):
60 self.txt = txt 88 self.txt = txt
89 def encode(self):
90 return bytes()
61 def __repr__(self): 91 def __repr__(self):
62 return '; {}'.format(self.txt) 92 return '; {}'.format(self.txt)
93
63 94
64 class Alignment(PseudoInstruction): 95 class Alignment(PseudoInstruction):
65 def __init__(self, a): 96 def __init__(self, a):
66 self.align = a 97 self.align = a
98
99 def __repr__(self):
100 return 'ALIGN({})'.format(self.align)
101
67 def encode(self): 102 def encode(self):
68 pad = [] 103 pad = []
69 address = self.address 104 address = self.address
70 while (address % i.align) != 0: 105 while (address % self.align) != 0:
71 address += 1 106 address += 1
72 pad.append(0) 107 pad.append(0)
73 return bytes(pad) 108 return bytes(pad)
74 109
75 110