diff python/target/msp430.py @ 341:4d204f6f7d4e devel

Rewrite of assembler parts
author Windel Bouwman
date Fri, 28 Feb 2014 18:07:14 +0100
parents 6f4753202b9a
children
line wrap: on
line diff
--- a/python/target/msp430.py	Sun Feb 23 16:24:01 2014 +0100
+++ b/python/target/msp430.py	Fri Feb 28 18:07:14 2014 +0100
@@ -5,7 +5,27 @@
 import types
 
 # Create the target class (singleton):
-msp430target = Target("MSP430")
+
+class Msp430T(Target):
+    def __init__(self):
+        super().__init__('msp430')
+        self.asm_keywords = []
+        self.assembler_rules = []
+        self.add_keyword('mov')
+        self.add_keyword('r13')
+        self.add_keyword('r14')
+        self.add_keyword('r15')
+        R0 = None # TODO
+        self.add_rule('reg', ['r13'], lambda rhs: r13)
+        self.add_rule('reg', ['r14'], lambda rhs: r14)
+        self.add_rule('reg', ['r15'], lambda rhs: r15)
+        self.add_instruction(['mov', 'reg', ',', 'reg'],
+            lambda rhs: Mov(rhs[1], rhs[3]))
+        
+        self.add_keyword('reti')
+        self.add_instruction(['reti'], lambda rhs: reti_ins())
+
+msp430target = Msp430T()
 
 REGISTER_MODE = 1
 SYMBOLIC_MODE = 3
@@ -96,18 +116,16 @@
 # Single operand arithmatic:
 #########################
 
-@msp430target.instruction
 class reti_ins(MSP430Instruction):
     mnemonic = 'reti'
-    operands = ()
     def encode(self):
         h = 0x1300
         return pack_ins(h)
 
 class OneOpArith(MSP430Instruction):
-    operands = (MSP430Reg, )
     def __init__(self, op1):
         self.op1 = op1
+
     def encode(self):
         # TODO:
         bits[15:10] = '00100'
@@ -139,42 +157,34 @@
         h = (1 << 13) | (self.condition << 10) | (self.offset)
         return pack_ins(h)
 
-@msp430target.instruction
 class jnz_ins(JumpInstruction):
     mnemonic = 'jnz'
     condition = 0
 
-@msp430target.instruction
 class jz_ins(JumpInstruction):
     mnemonic = 'jz'
     condition = 1
 
-@msp430target.instruction
 class jnc_ins(JumpInstruction):
     mnemonic = 'jnc'
     condition = 2
 
-@msp430target.instruction
 class jc_ins(JumpInstruction):
     mnemonic = 'jc'
     condition = 3
 
-@msp430target.instruction
 class jn_ins(JumpInstruction):
     mnemonic = 'jn'
     condition = 4
 
-@msp430target.instruction
 class jge_ins(JumpInstruction):
     mnemonic = 'jge'
     condition = 5
 
-@msp430target.instruction
 class jl_ins(JumpInstruction):
     mnemonic = 'jl'
     condition = 6
 
-@msp430target.instruction
 class jmp_ins(JumpInstruction):
     mnemonic = 'jmp'
     condition = 7
@@ -185,7 +195,6 @@
 
 
 class TwoOpArith(MSP430Instruction):
-    operands = (MSP430Operand, MSP430Operand)
     def __init__(self, src, dst):
         self.op1 = src
         self.op2 = dst
@@ -220,12 +229,13 @@
     """ Helper function to define a two operand arithmetic instruction """
     members = {'mnemonic': mne, 'opcode': opc}
     ins_cls = type(mne + '_ins', (TwoOpArith,), members)
-    msp430target.addInstruction(ins_cls)
 
-twoOpIns('mov', 4)
+class Mov(TwoOpArith):
+    """ Adds the source to the destination """
+    mnemonic = 'mov'
+    opcode = 4
 
 # This is equivalent to the helper function twoOpIns:
-@msp430target.instruction
 class add_ins(TwoOpArith):
     """ Adds the source to the destination """
     mnemonic = 'add'