diff python/target.py @ 206:6c6bf8890d8a

Added push and pop encodings
author Windel Bouwman
date Fri, 28 Jun 2013 16:49:38 +0200
parents d77cb5962cc5
children 1fa3e0050b49
line wrap: on
line diff
--- a/python/target.py	Sun Jun 23 18:23:18 2013 +0200
+++ b/python/target.py	Fri Jun 28 16:49:38 2013 +0200
@@ -1,4 +1,4 @@
-from asmnodes import ASymbol, AInstruction, ALabel
+from asmnodes import ASymbol, AInstruction, ALabel, ANumber
 from ppci import CompilerError
 
 """
@@ -10,6 +10,39 @@
    """ Single machine operand """
    pass
 
+# standard immediates:
+
+class Imm8:
+    def __init__(self, imm):
+        assert imm < 256
+        self.imm = imm
+
+    @classmethod
+    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
+        assert type(imm) is int
+        self.imm = imm
+
+    @classmethod
+    def Create(cls, vop):
+        if type(vop) is ANumber and vop.number < 8:
+            return cls(vop.number)
+
+class Label:
+    def __init__(self, name):
+        self.name = name
+
+    @classmethod
+    def Create(cls, vop):
+        if type(vop) is ASymbol:
+            name = vop.name
+            return cls(name)
+
 class Register(Operand):
     def __init__(self, name):
         self.name = name
@@ -30,6 +63,14 @@
         self.addInstruction(cls)
         return cls
 
+    def check(self):
+        """ Check target """
+        for i in self.instructions:
+            assert hasattr(i, 'mnemonic')
+            assert hasattr(i, 'operands'), str(i)
+            assert type(i.mnemonic) is str
+            assert type(i.operands) is tuple, str(i)
+
     def addInstruction(self, ins_class):
         self.instructions.append(ins_class)