Added Module.id property (getter+setter).

Updated test/asm.py to use unittest.
This commit is contained in:
Siu Kwan Lam 2012-07-20 20:15:21 -07:00
commit 9bbeee519b
6 changed files with 57 additions and 12 deletions

View file

@ -3,15 +3,27 @@
from llvm import *
from llvm.core import *
# create a module
m = Module.new('module1')
m.add_global_variable(Type.int(), 'i')
import unittest
# write it's assembly representation to a file
asm = str(m)
print(asm, file=file("/tmp/testasm.ll", "w"))
class TestAsm(unittest.TestCase):
def test_asm(self):
# create a module
m = Module.new('module1')
m.add_global_variable(Type.int(), 'i')
# read it back into a module
m2 = Module.from_assembly(file("/tmp/testasm.ll"))
print(m2)
# write it's assembly representation to a file
asm = str(m)
with open("/tmp/testasm.ll", "w") as fout:
fout.write(asm)
# read it back into a module
with open("/tmp/testasm.ll") as fin:
m2 = Module.from_assembly(fin)
# The default `m.id` is '<string>'.
m2.id = m.id # Copy the name from `m`
self.assertEqual(str(m2).strip(), asm.strip())
if __name__ == '__main__':
unittest.main()