comparison test/testir.py @ 309:68b01c8abf8a

Added start of ir read and write
author Windel Bouwman
date Fri, 13 Dec 2013 13:51:02 +0100
parents e609d5296ee9
children e30a77ae359b
comparison
equal deleted inserted replaced
308:2e7f55319858 309:68b01c8abf8a
1 import unittest 1 import unittest
2 import os 2 import os
3 import sys 3 import sys
4 import io
4 import ppci 5 import ppci
5 from ppci import ir 6 from ppci import ir
6 from ppci import irutils 7 from ppci import irutils
7 from ppci.transform import ConstantFolder 8 from ppci.transform import ConstantFolder
8 9
77 def testAdd0(self): 78 def testAdd0(self):
78 f = self.b.newFunction('test') 79 f = self.b.newFunction('test')
79 self.b.setFunction(f) 80 self.b.setFunction(f)
80 self.b.setBlock(self.b.newBlock()) 81 self.b.setBlock(self.b.newBlock())
81 v1 = ir.Const(0) 82 v1 = ir.Const(0)
82 v2 = ir.Const(0) 83 v3 = ir.Add(v1, ir.Const(0))
83 v3 = ir.Add(v1, v2) 84
85 class TestWriter(unittest.TestCase):
86 def testWrite(self):
87 writer = irutils.Writer()
88 module = ir.Module('mod1')
89 function = ir.Function('func1', module)
90 f = io.StringIO()
91 writer.write(module, f)
92 #print(f.getvalue())
93 f2 = io.StringIO(f.getvalue())
94 reader = irutils.Reader()
95 module2 = reader.read(f2)
96 f = io.StringIO()
97 writer.write(module2, f)
98 #print(f.getvalue())
84 99
85 100
86 101 class TestReader(unittest.TestCase):
102 def testAddExample(self):
103 reader = irutils.Reader()
104 with open('../examples/pi/add.pi') as f:
105 m = reader.read(f)
106 self.assertTrue(m)
107 #print(m)
108
87 109
88 if __name__ == '__main__': 110 if __name__ == '__main__':
89 unittest.main() 111 unittest.main()
90 sys.exit() 112 sys.exit()