diff python/target.py @ 234:83781bd10fdb

wip
author Windel Bouwman
date Sun, 14 Jul 2013 19:29:21 +0200
parents 1fa3e0050b49
children ff40407c0240
line wrap: on
line diff
--- a/python/target.py	Sun Jul 14 12:28:23 2013 +0200
+++ b/python/target.py	Sun Jul 14 19:29:21 2013 +0200
@@ -21,7 +21,7 @@
     def Create(cls, vop):
         if type(vop) is ANumber and vop.number < 256:
             return cls(vop.number)
-        
+
 class Imm3:
     def __init__(self, imm):
         assert imm < 8
@@ -33,9 +33,21 @@
         if type(vop) is ANumber and vop.number < 8:
             return cls(vop.number)
 
-class Label:
+class Instruction:
+    def encode(self):
+        raise NotImplementedError('Instruction {0} has no encode yet, TODO'.format(type(self)))
+    def resolve(self, f):
+        pass
+
+
+class PseudoInstruction(Instruction):
+    pass
+
+
+class Label(PseudoInstruction):
     def __init__(self, name):
         self.name = name
+        self.address = 0
 
     @classmethod
     def Create(cls, vop):
@@ -43,13 +55,28 @@
             name = vop.name
             return cls(name)
 
+class Comment(PseudoInstruction):
+    def __init__(self, txt):
+        self.txt = txt
+    def __repr__(self):
+        return '; {}'.format(self.txt)
+
+class Alignment(PseudoInstruction):
+    def __init__(self, a):
+        self.align = a
+    def encode(self):
+        pad = []
+        address = self.address
+        while (address % i.align) != 0:
+            address += 1
+            pad.append(0)
+        return bytes(pad)
+
+
 class Register(Operand):
     def __init__(self, name):
         self.name = name
 
-class Instruction:
-    def encode(self):
-        raise NotImplementedError('Instruction {0} has no encode yet, TODO'.format(type(self)))
 
 class Target:
     def __init__(self, name, desc=''):