add the assembly test
This commit is contained in:
parent
b8dd256e11
commit
8af02c5a7e
3 changed files with 46 additions and 76 deletions
|
|
@ -25,6 +25,52 @@ import llvm.ee as le
|
|||
|
||||
tests = []
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestAsm(unittest.TestCase):
|
||||
def test_asm(self):
|
||||
# create a module
|
||||
m = Module.new('module1')
|
||||
m.add_global_variable(Type.int(), 'i')
|
||||
|
||||
# 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())
|
||||
|
||||
|
||||
def test_bitcode(self):
|
||||
# create a module
|
||||
m = Module.new('module1')
|
||||
m.add_global_variable(Type.int(), 'i')
|
||||
|
||||
# write it's assembly representation to a file
|
||||
asm = str(m)
|
||||
|
||||
with open("/tmp/testasm.bc", "wb") as fout:
|
||||
m.to_bitcode(fout)
|
||||
|
||||
# read it back into a module
|
||||
with open("/tmp/testasm.bc", "rb") as fin:
|
||||
m2 = Module.from_bitcode(fin)
|
||||
# The default `m.id` is '<string>'.
|
||||
m2.id = m.id # Copy the name from `m`
|
||||
|
||||
self.assertEqual(str(m2).strip(), asm.strip())
|
||||
|
||||
tests.append(TestAsm)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestOperands(unittest.TestCase):
|
||||
# implement a test function
|
||||
test_module = """
|
||||
|
|
|
|||
49
test/asm.py
49
test/asm.py
|
|
@ -1,49 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from llvm import *
|
||||
from llvm.core import *
|
||||
|
||||
import unittest
|
||||
|
||||
class TestAsm(unittest.TestCase):
|
||||
def test_asm(self):
|
||||
# create a module
|
||||
m = Module.new('module1')
|
||||
m.add_global_variable(Type.int(), 'i')
|
||||
|
||||
# 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())
|
||||
|
||||
|
||||
def test_bitcode(self):
|
||||
# create a module
|
||||
m = Module.new('module1')
|
||||
m.add_global_variable(Type.int(), 'i')
|
||||
|
||||
# write it's assembly representation to a file
|
||||
asm = str(m)
|
||||
|
||||
with open("/tmp/testasm.bc", "wb") as fout:
|
||||
m.to_bitcode(fout)
|
||||
|
||||
# read it back into a module
|
||||
with open("/tmp/testasm.bc", "rb") as fin:
|
||||
m2 = Module.from_bitcode(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()
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from llvm.core import *
|
||||
|
||||
import unittest
|
||||
|
||||
class TestIssue10(unittest.TestCase):
|
||||
def test_issue10(self):
|
||||
m = Module.new('a')
|
||||
ti = Type.int()
|
||||
tf = Type.function(ti, [ti, ti])
|
||||
|
||||
f = m.add_function(tf, "func1")
|
||||
|
||||
bb = f.append_basic_block('entry')
|
||||
|
||||
b = Builder.new(bb)
|
||||
|
||||
# There are no instructions in bb. Positioning of the
|
||||
# builder at beginning (or end) should succeed (trivially).
|
||||
|
||||
b.position_at_end(bb)
|
||||
b.position_at_beginning(bb)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue