diff python/testasm.py @ 195:37ac6c016e0f

Expanded asm subsystem
author Windel Bouwman
date Fri, 31 May 2013 21:06:44 +0200
parents b01429a5d695
children ec2b423cdbea
line wrap: on
line diff
--- a/python/testasm.py	Wed May 29 22:36:37 2013 +0200
+++ b/python/testasm.py	Fri May 31 21:06:44 2013 +0200
@@ -3,6 +3,7 @@
 import unittest
 import libasm
 import ppci
+from libasm import AInstruction, ABinop, AUnop, ASymbol, ALabel, ANumber
 
 class AssemblerTestCase(unittest.TestCase):
     """ 
@@ -41,12 +42,45 @@
         asmline = 'a: mov rax, [rbx + 2]'
         a = libasm.Assembler()
         a.parse_line(asmline)
+        output = []
+        output.append(ALabel('a'))
+        output.append(AInstruction('mov', [ASymbol('rax'), AUnop('[]', ASymbol('rbx') + ANumber(2))]))
+        self.assertSequenceEqual(output, a.output)
 
     def testParse3(self):
         # A label must be optional:
         asmline = 'mov rax, 1'
         a = libasm.Assembler()
         a.parse_line(asmline)
+        output = []
+        output.append(AInstruction('mov', [ASymbol('rax'), ANumber(1)]))
+        self.assertSequenceEqual(output, a.output)
+
+    def testParse4(self):
+        # Test 3 operands:
+        asmline = 'add rax, [4*rbx + 22], rcx'
+        a = libasm.Assembler()
+        a.parse_line(asmline)
+        output = []
+        ops = []
+        ops.append(ASymbol('rax'))
+        ops.append(AUnop('[]', ANumber(4) * ASymbol('rbx') + ANumber(22)))
+        ops.append(ASymbol('rcx'))
+        output.append(AInstruction('add', ops))
+        self.assertSequenceEqual(output, a.output)
+
+    def testParse5(self):
+        # An instruction must be optional:
+        asmline = 'lab1:'
+        a = libasm.Assembler()
+        a.parse_line(asmline)
+        output = []
+        output.append(ALabel('lab1'))
+        self.assertSequenceEqual(output, a.output)
+    
+    def testX86(self):
+        # TODO
+        pass
 
 if __name__ == '__main__':
     unittest.main()