Mercurial > lcfOS
comparison test/testasm.py @ 337:b00219172a42
Added cool lm3s811 qemu project
author | Windel Bouwman |
---|---|
date | Thu, 20 Feb 2014 20:04:52 +0100 |
parents | 582a1aaa3983 |
children | 4d204f6f7d4e |
comparison
equal
deleted
inserted
replaced
336:d1ecc493384e | 337:b00219172a42 |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 import unittest, cProfile | 3 import unittest, cProfile |
4 from ppci import CompilerError | 4 from ppci import CompilerError |
5 from ppci.asmnodes import AInstruction, ABinop, AUnop, ASymbol, ALabel, ANumber | 5 from ppci.asmnodes import AInstruction, ABinop, AUnop, ASymbol, ALabel, ANumber |
6 from ppci.assembler import tokenize, Assembler | 6 from ppci.assembler import tokenize, Assembler, asmParser, Lexer |
7 from ppci.objectfile import ObjectFile | 7 from ppci.objectfile import ObjectFile |
8 from ppci.linker import Linker | 8 from ppci.linker import Linker |
9 import outstream | 9 import outstream |
10 from target import Label | 10 from target import Label |
11 | 11 |
38 class AssemblerParsingTestCase(unittest.TestCase): | 38 class AssemblerParsingTestCase(unittest.TestCase): |
39 """ | 39 """ |
40 Tests the assembler parts | 40 Tests the assembler parts |
41 """ | 41 """ |
42 def setUp(self): | 42 def setUp(self): |
43 self.a = Assembler() | 43 self.parser = asmParser |
44 self.stack = [] | |
45 | |
46 def emit(self, x): | |
47 self.stack.append(x) | |
48 | |
49 def parse_line(self, line): | |
50 self.parser.parse(Lexer(line), self.emit) | |
44 | 51 |
45 def testParse(self): | 52 def testParse(self): |
46 asmline = 'lab1: mov rax, rbx' | 53 asmline = 'lab1: mov rax, rbx' |
47 self.a.parse_line(asmline) | 54 self.parse_line(asmline) |
48 | 55 |
49 def expectTree(self, asmline, stack): | 56 def expectTree(self, asmline, stack): |
50 self.a.parse_line(asmline) | 57 self.parse_line(asmline) |
51 self.assertSequenceEqual(stack, self.a.stack) | 58 self.assertSequenceEqual(stack, self.stack) |
52 | 59 |
53 def testParse2(self): | 60 def testParse2(self): |
54 asmline = 'a: mov rax, [rbx + 2]' | 61 asmline = 'a: mov rax, [rbx + 2]' |
55 output = [] | 62 output = [] |
56 output.append(ALabel('a')) | 63 output.append(ALabel('a')) |
80 output.append(ALabel('lab1')) | 87 output.append(ALabel('lab1')) |
81 self.expectTree(asmline, output) | 88 self.expectTree(asmline, output) |
82 | 89 |
83 def testParse6(self): | 90 def testParse6(self): |
84 # A line can be empty | 91 # A line can be empty |
85 self.a.parse_line('') | 92 self.parse_line('') |
86 | |
87 | |
88 class AssemblerOtherTestCase(unittest.TestCase): | |
89 def testWithoutTarget(self): | |
90 a = Assembler() | |
91 with self.assertRaises(CompilerError): | |
92 a.assemble_line('') | |
93 | 93 |
94 | 94 |
95 class OustreamTestCase(unittest.TestCase): | 95 class OustreamTestCase(unittest.TestCase): |
96 def test1(self): | 96 def test1(self): |
97 obj = ObjectFile() | 97 obj = ObjectFile() |