Add methods to set volatile inst.
This commit is contained in:
parent
c7afaf98db
commit
9d068fd582
3 changed files with 70 additions and 4 deletions
55
test/volatile.py
Normal file
55
test/volatile.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
from llvm.core import *
|
||||
import unittest
|
||||
|
||||
class TestVolatile(unittest.TestCase):
|
||||
def test_volatile(self):
|
||||
mod = Module.new('mod')
|
||||
functype = Type.function(Type.void(), [])
|
||||
func = mod.add_function(functype, name='foo')
|
||||
bb = func.append_basic_block('entry')
|
||||
bldr = Builder.new(bb)
|
||||
ptr = bldr.alloca(Type.int())
|
||||
|
||||
# test load inst
|
||||
val = bldr.load(ptr)
|
||||
self.assertFalse(val.is_volatile, "default must be non-volatile")
|
||||
val.set_volatile(True)
|
||||
self.assertTrue(val.is_volatile, "fail to set volatile")
|
||||
val.set_volatile(False)
|
||||
self.assertFalse(val.is_volatile, "fail to unset volatile")
|
||||
|
||||
# test store inst
|
||||
store_inst = bldr.store(val, ptr)
|
||||
self.assertFalse(store_inst.is_volatile, "default must be non-volatile")
|
||||
store_inst.set_volatile(True)
|
||||
self.assertTrue(store_inst.is_volatile, "fail to set volatile")
|
||||
store_inst.set_volatile(False)
|
||||
self.assertFalse(store_inst.is_volatile, "fail to unset volatile")
|
||||
|
||||
def test_volatile_another(self):
|
||||
mod = Module.new('mod')
|
||||
functype = Type.function(Type.void(), [])
|
||||
func = mod.add_function(functype, name='foo')
|
||||
bb = func.append_basic_block('entry')
|
||||
bldr = Builder.new(bb)
|
||||
ptr = bldr.alloca(Type.int())
|
||||
|
||||
# test load inst
|
||||
val = bldr.load(ptr, volatile=True)
|
||||
self.assertTrue(val.is_volatile, "volatile kwarg does not work")
|
||||
val.set_volatile(False)
|
||||
self.assertFalse(val.is_volatile, "fail to unset volatile")
|
||||
val.set_volatile(True)
|
||||
self.assertTrue(val.is_volatile, "fail to set volatile")
|
||||
|
||||
# test store inst
|
||||
store_inst = bldr.store(val, ptr, volatile=True)
|
||||
self.assertTrue(store_inst.is_volatile, "volatile kwarg does not work")
|
||||
store_inst.set_volatile(False)
|
||||
self.assertFalse(store_inst.is_volatile, "fail to unset volatile")
|
||||
store_inst.set_volatile(True)
|
||||
self.assertTrue(store_inst.is_volatile, "fail to set volatile")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue