def test_metadata(self): m = Module.new("a") t = Type.int() metadata = MetaData.get(m, [Constant.int(t, 100), MetaDataString.get(m, "abcdef"), None]) MetaData.add_named_operand(m, "foo", metadata) self.assertEqual(MetaData.get_named_operands(m, "foo"), [metadata]) self.assertEqual(MetaData.get_named_operands(m, "bar"), []) self.assertEqual(len(metadata.operands), 3) self.assertEqual(metadata.operands[0].z_ext_value, 100) self.assertEqual(metadata.operands[1].string, "abcdef") self.assertTrue(metadata.operands[2] is None)
def test_metadata(self): m = Module.new('a') t = Type.int() metadata = MetaData.get( m, [Constant.int(t, 100), MetaDataString.get(m, 'abcdef'), None]) MetaData.add_named_operand(m, 'foo', metadata) self.assertEqual(MetaData.get_named_operands(m, 'foo'), [metadata]) self.assertEqual(MetaData.get_named_operands(m, 'bar'), []) self.assertEqual(len(metadata.operands), 3) self.assertEqual(metadata.operands[0].z_ext_value, 100) self.assertEqual(metadata.operands[1].string, 'abcdef') self.assertTrue(metadata.operands[2] is None)
def test_named_md(self): m = Module.new("test_named_md") nmd = m.get_or_insert_named_metadata("something") md = MetaData.get(m, [Constant.int(Type.int(), 0xBEEF)]) nmd.add(md) self.assertTrue(str(nmd).startswith("!something")) ir = str(m) self.assertTrue("!something" in ir)
def test_named_md(self): m = Module.new('test_named_md') nmd = m.get_or_insert_named_metadata('something') md = MetaData.get(m, [Constant.int(Type.int(), 0xbeef)]) nmd.add(md) self.assertTrue(str(nmd).startswith('!something')) ir = str(m) self.assertTrue('!something' in ir)
def set_cuda_kernel(lfunc): from llvm.core import MetaData, MetaDataString, Constant, Type m = lfunc.module ops = lfunc, MetaDataString.get(m, "kernel"), Constant.int(Type.int(), 1) md = MetaData.get(m, ops) nmd = m.get_or_insert_named_metadata('nvvm.annotations') nmd.add(md)