comparison python/target.py @ 234:83781bd10fdb

wip
author Windel Bouwman
date Sun, 14 Jul 2013 19:29:21 +0200
parents 1fa3e0050b49
children ff40407c0240
comparison
equal deleted inserted replaced
233:d3dccf12ca88 234:83781bd10fdb
19 19
20 @classmethod 20 @classmethod
21 def Create(cls, vop): 21 def Create(cls, vop):
22 if type(vop) is ANumber and vop.number < 256: 22 if type(vop) is ANumber and vop.number < 256:
23 return cls(vop.number) 23 return cls(vop.number)
24 24
25 class Imm3: 25 class Imm3:
26 def __init__(self, imm): 26 def __init__(self, imm):
27 assert imm < 8 27 assert imm < 8
28 assert type(imm) is int 28 assert type(imm) is int
29 self.imm = imm 29 self.imm = imm
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 Label: 36 class Instruction:
37 def encode(self):
38 raise NotImplementedError('Instruction {0} has no encode yet, TODO'.format(type(self)))
39 def resolve(self, f):
40 pass
41
42
43 class PseudoInstruction(Instruction):
44 pass
45
46
47 class Label(PseudoInstruction):
37 def __init__(self, name): 48 def __init__(self, name):
38 self.name = name 49 self.name = name
50 self.address = 0
39 51
40 @classmethod 52 @classmethod
41 def Create(cls, vop): 53 def Create(cls, vop):
42 if type(vop) is ASymbol: 54 if type(vop) is ASymbol:
43 name = vop.name 55 name = vop.name
44 return cls(name) 56 return cls(name)
45 57
58 class Comment(PseudoInstruction):
59 def __init__(self, txt):
60 self.txt = txt
61 def __repr__(self):
62 return '; {}'.format(self.txt)
63
64 class Alignment(PseudoInstruction):
65 def __init__(self, a):
66 self.align = a
67 def encode(self):
68 pad = []
69 address = self.address
70 while (address % i.align) != 0:
71 address += 1
72 pad.append(0)
73 return bytes(pad)
74
75
46 class Register(Operand): 76 class Register(Operand):
47 def __init__(self, name): 77 def __init__(self, name):
48 self.name = name 78 self.name = name
49 79
50 class Instruction:
51 def encode(self):
52 raise NotImplementedError('Instruction {0} has no encode yet, TODO'.format(type(self)))
53 80
54 class Target: 81 class Target:
55 def __init__(self, name, desc=''): 82 def __init__(self, name, desc=''):
56 self.name = name 83 self.name = name
57 self.desc = desc 84 self.desc = desc