Mercurial > lcfOS
comparison python/testasm.py @ 195:37ac6c016e0f
Expanded asm subsystem
author | Windel Bouwman |
---|---|
date | Fri, 31 May 2013 21:06:44 +0200 |
parents | b01429a5d695 |
children | ec2b423cdbea |
comparison
equal
deleted
inserted
replaced
194:b01429a5d695 | 195:37ac6c016e0f |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 import unittest | 3 import unittest |
4 import libasm | 4 import libasm |
5 import ppci | 5 import ppci |
6 from libasm import AInstruction, ABinop, AUnop, ASymbol, ALabel, ANumber | |
6 | 7 |
7 class AssemblerTestCase(unittest.TestCase): | 8 class AssemblerTestCase(unittest.TestCase): |
8 """ | 9 """ |
9 Tests the assembler parts | 10 Tests the assembler parts |
10 """ | 11 """ |
39 | 40 |
40 def testParse2(self): | 41 def testParse2(self): |
41 asmline = 'a: mov rax, [rbx + 2]' | 42 asmline = 'a: mov rax, [rbx + 2]' |
42 a = libasm.Assembler() | 43 a = libasm.Assembler() |
43 a.parse_line(asmline) | 44 a.parse_line(asmline) |
45 output = [] | |
46 output.append(ALabel('a')) | |
47 output.append(AInstruction('mov', [ASymbol('rax'), AUnop('[]', ASymbol('rbx') + ANumber(2))])) | |
48 self.assertSequenceEqual(output, a.output) | |
44 | 49 |
45 def testParse3(self): | 50 def testParse3(self): |
46 # A label must be optional: | 51 # A label must be optional: |
47 asmline = 'mov rax, 1' | 52 asmline = 'mov rax, 1' |
48 a = libasm.Assembler() | 53 a = libasm.Assembler() |
49 a.parse_line(asmline) | 54 a.parse_line(asmline) |
55 output = [] | |
56 output.append(AInstruction('mov', [ASymbol('rax'), ANumber(1)])) | |
57 self.assertSequenceEqual(output, a.output) | |
58 | |
59 def testParse4(self): | |
60 # Test 3 operands: | |
61 asmline = 'add rax, [4*rbx + 22], rcx' | |
62 a = libasm.Assembler() | |
63 a.parse_line(asmline) | |
64 output = [] | |
65 ops = [] | |
66 ops.append(ASymbol('rax')) | |
67 ops.append(AUnop('[]', ANumber(4) * ASymbol('rbx') + ANumber(22))) | |
68 ops.append(ASymbol('rcx')) | |
69 output.append(AInstruction('add', ops)) | |
70 self.assertSequenceEqual(output, a.output) | |
71 | |
72 def testParse5(self): | |
73 # An instruction must be optional: | |
74 asmline = 'lab1:' | |
75 a = libasm.Assembler() | |
76 a.parse_line(asmline) | |
77 output = [] | |
78 output.append(ALabel('lab1')) | |
79 self.assertSequenceEqual(output, a.output) | |
80 | |
81 def testX86(self): | |
82 # TODO | |
83 pass | |
50 | 84 |
51 if __name__ == '__main__': | 85 if __name__ == '__main__': |
52 unittest.main() | 86 unittest.main() |
53 | 87 |