diff python/target/basetarget.py @ 292:534b94b40aa8

Fixup reorganize
author Windel Bouwman
date Wed, 27 Nov 2013 08:06:42 +0100
parents 7b38782ed496
children b145f8e6050b
line wrap: on
line diff
--- a/python/target/basetarget.py	Sun Nov 24 11:24:15 2013 +0100
+++ b/python/target/basetarget.py	Wed Nov 27 08:06:42 2013 +0100
@@ -12,47 +12,36 @@
 
 # standard immediates:
 
-class Imm8:
+class ImmBase:
     def __init__(self, imm):
-        assert imm < 256
+        assert type(imm) is int
+        assert imm < self.Max()
         self.imm = imm
 
     @classmethod
-    def Create(cls, vop):
-        if type(vop) is ANumber and vop.number < 256:
-            return cls(vop.number)
-
-class Imm7:
-    def __init__(self, imm):
-        assert imm < 128
-        self.imm = imm
+    def Max(cls):
+        return 2**cls.bits
 
     @classmethod
     def Create(cls, vop):
-        if type(vop) is ANumber and vop.number < 128:
+        if type(vop) is ANumber and vop.number < cls.Max():
             return cls(vop.number)
 
-class Imm3:
-    def __init__(self, imm):
-        assert imm < 8
-        assert type(imm) is int
-        self.imm = imm
+
+class Imm3(ImmBase):
+    bits = 3
 
-    @classmethod
-    def Create(cls, vop):
-        if type(vop) is ANumber and vop.number < 8:
-            return cls(vop.number)
+
+class Imm7(ImmBase):
+    bits = 7
 
-class Imm32:
-    def __init__(self, imm):
-        assert imm < 2**32
-        assert type(imm) is int
-        self.imm = imm
+
+class Imm8(ImmBase):
+    bits = 8
 
-    @classmethod
-    def Create(cls, vop):
-        if type(vop) is ANumber and vop.number < 2**32:
-            return cls(vop.number)
+
+class Imm32(ImmBase):
+    bits = 32
 
 
 class LabelRef:
@@ -65,9 +54,12 @@
         if type(vop) is ASymbol:
             return cls(vop.name)
 
+
 class Instruction:
+    """ Base instruction class """
     def encode(self):
         raise NotImplementedError('Instruction {0} has no encode yet, TODO'.format(type(self)))
+
     def resolve(self, f):
         pass
 
@@ -77,7 +69,6 @@
     def encode(self):
         return bytes()
 
-    
 
 class PseudoInstruction(Instruction):
     pass
@@ -127,6 +118,7 @@
             pad.append(0)
         return bytes(pad)
 
+
 class DebugInfo(PseudoInstruction):
     def __init__(self, i):
         self.info = i
@@ -137,6 +129,7 @@
     def encode(self):
         return bytes()
 
+
 class Register(Operand):
     def __init__(self, name):
         self.name = name
@@ -195,4 +188,3 @@
                 if all(isinstance(rop, optype) for rop, optype in zip(rops, ic.operands)):
                     return ic(*rops)
         raise CompilerError('No suitable instruction found for "{0}"'.format(vi))
-