Mercurial > lcfOS
comparison test/testir.py @ 394:988f3fb861e4
c3 code generator rewrite
author | Windel Bouwman |
---|---|
date | Thu, 22 May 2014 08:14:12 +0200 |
parents | 86b02c98a717 |
children | 5d03c10fe19d |
comparison
equal
deleted
inserted
replaced
393:6ae782a085e0 | 394:988f3fb861e4 |
---|---|
1 import unittest | 1 import unittest |
2 import os | |
3 import sys | 2 import sys |
4 import io | 3 import io |
5 import ppci | 4 import ppci |
6 from ppci import ir | 5 from ppci import ir |
7 from ppci import irutils | 6 from ppci import irutils |
8 from ppci.transform import ConstantFolder | 7 from ppci.transform import ConstantFolder |
9 | 8 |
10 | 9 |
11 class IrCodeTestCase(unittest.TestCase): | 10 class IrCodeTestCase(unittest.TestCase): |
12 def testAdd(self): | 11 def testAdd(self): |
13 v = ir.Add(ir.Const(1), ir.Const(2)) | 12 v = ir.Add(ir.Const(1), ir.Const(2), "add", ir.i32) |
14 | 13 |
15 | 14 |
16 class IrBuilderTestCase(unittest.TestCase): | 15 class IrBuilderTestCase(unittest.TestCase): |
17 def setUp(self): | 16 def setUp(self): |
18 self.b = irutils.Builder() | 17 self.b = irutils.Builder() |
19 self.m = ir.Module('test') | 18 self.m = ir.Module('test') |
20 self.b.setModule(self.m) | 19 self.b.setModule(self.m) |
21 | 20 |
22 def testBuilder(self): | 21 def testBuilder(self): |
23 f = self.b.newFunction('add') | 22 f = self.b.new_function('add') |
24 self.b.setFunction(f) | 23 self.b.setFunction(f) |
25 bb = self.b.newBlock() | 24 bb = self.b.newBlock() |
26 self.b.emit(ir.Jump(bb)) | 25 self.b.emit(ir.Jump(bb)) |
27 self.b.setBlock(bb) | 26 self.b.setBlock(bb) |
28 self.b.emit(ir.Exp(ir.Const(0))) | 27 self.b.emit(ir.Exp(ir.Const(0))) |
63 self.cf = ConstantFolder() | 62 self.cf = ConstantFolder() |
64 self.m = ir.Module('test') | 63 self.m = ir.Module('test') |
65 self.b.setModule(self.m) | 64 self.b.setModule(self.m) |
66 | 65 |
67 def testBuilder(self): | 66 def testBuilder(self): |
68 f = self.b.newFunction('test') | 67 f = self.b.new_function('test') |
69 self.b.setFunction(f) | 68 self.b.setFunction(f) |
70 bb = self.b.newBlock() | 69 bb = self.b.newBlock() |
71 self.b.emit(ir.Jump(bb)) | 70 self.b.emit(ir.Jump(bb)) |
72 self.b.setBlock(bb) | 71 self.b.setBlock(bb) |
73 v1 = ir.Const(5) | 72 v1 = ir.Const(5) |
74 v2 = ir.Const(7) | 73 v2 = ir.Const(7) |
75 v3 = ir.Add(v1, v2) | 74 v3 = ir.Add(v1, v2, "add", ir.i32) |
76 self.b.emit(ir.Jump(f.epiloog)) | 75 self.b.emit(ir.Jump(f.epiloog)) |
77 self.cf.run(self.m) | 76 self.cf.run(self.m) |
78 | 77 |
79 def testAdd0(self): | 78 def testAdd0(self): |
80 f = self.b.newFunction('test') | 79 f = self.b.new_function('test') |
81 self.b.setFunction(f) | 80 self.b.setFunction(f) |
82 self.b.setBlock(self.b.newBlock()) | 81 self.b.setBlock(self.b.newBlock()) |
83 v1 = ir.Const(0) | 82 v1 = ir.Const(12) |
84 v3 = ir.Add(v1, ir.Const(0)) | 83 v3 = ir.Add(v1, ir.Const(0), "add", ir.i32) |
85 | 84 |
86 | 85 |
87 class TestWriter(unittest.TestCase): | 86 class TestWriter(unittest.TestCase): |
88 def testWrite(self): | 87 def testWrite(self): |
89 writer = irutils.Writer() | 88 writer = irutils.Writer() |