Support MetaDataString, and correctly represent MetaData Values in _make_value
This commit is contained in:
parent
7f69beb258
commit
e2d8079b93
5 changed files with 31 additions and 3 deletions
|
|
@ -610,6 +610,7 @@ _wrap_objlist2obj(LLVMMetaDataGet, LLVMModuleRef, LLVMValueRef, LLVMValueRef)
|
||||||
_wrap_objstrobj2none(LLVMAddNamedMetadataOperand, LLVMModuleRef, LLVMValueRef)
|
_wrap_objstrobj2none(LLVMAddNamedMetadataOperand, LLVMModuleRef, LLVMValueRef)
|
||||||
_wrap_objint2obj(LLVMMetaDataGetOperand, LLVMValueRef, LLVMValueRef)
|
_wrap_objint2obj(LLVMMetaDataGetOperand, LLVMValueRef, LLVMValueRef)
|
||||||
_wrap_obj2obj(LLVMMetaDataGetNumOperands, LLVMValueRef, int)
|
_wrap_obj2obj(LLVMMetaDataGetNumOperands, LLVMValueRef, int)
|
||||||
|
_wrap_objstr2obj(LLVMMetaDataStringGet, LLVMModuleRef, LLVMValueRef)
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_wLLVMGetNamedMetadataOperands(PyObject *self, PyObject *args)
|
_wLLVMGetNamedMetadataOperands(PyObject *self, PyObject *args)
|
||||||
|
|
@ -1687,6 +1688,7 @@ static PyMethodDef core_methods[] = {
|
||||||
_method( LLVMAddNamedMetadataOperand )
|
_method( LLVMAddNamedMetadataOperand )
|
||||||
_method( LLVMMetaDataGetOperand )
|
_method( LLVMMetaDataGetOperand )
|
||||||
_method( LLVMMetaDataGetNumOperands )
|
_method( LLVMMetaDataGetNumOperands )
|
||||||
|
_method( LLVMMetaDataStringGet )
|
||||||
|
|
||||||
/* Instructions */
|
/* Instructions */
|
||||||
_method( LLVMGetInstructionParent )
|
_method( LLVMGetInstructionParent )
|
||||||
|
|
|
||||||
13
llvm/core.py
13
llvm/core.py
|
|
@ -1478,6 +1478,17 @@ class MetaData(Value):
|
||||||
def _get_operand(self, i):
|
def _get_operand(self, i):
|
||||||
return _make_value(_core.LLVMMetaDataGetOperand(self.ptr, i))
|
return _make_value(_core.LLVMMetaDataGetOperand(self.ptr, i))
|
||||||
|
|
||||||
|
class MetaDataString(Value):
|
||||||
|
@staticmethod
|
||||||
|
def get(module, s):
|
||||||
|
ptr = _core.LLVMMetaDataStringGet(module.ptr, s)
|
||||||
|
return MetaDataString(ptr)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def string(self):
|
||||||
|
'''Same as MDString::getString'''
|
||||||
|
return self.name
|
||||||
|
|
||||||
#===----------------------------------------------------------------------===
|
#===----------------------------------------------------------------------===
|
||||||
# Instruction
|
# Instruction
|
||||||
#===----------------------------------------------------------------------===
|
#===----------------------------------------------------------------------===
|
||||||
|
|
@ -1648,6 +1659,8 @@ __class_for_valueid = {
|
||||||
VALUE_CONSTANT_STRUCT : ConstantStruct,
|
VALUE_CONSTANT_STRUCT : ConstantStruct,
|
||||||
VALUE_CONSTANT_VECTOR : ConstantVector,
|
VALUE_CONSTANT_VECTOR : ConstantVector,
|
||||||
VALUE_CONSTANT_POINTER_NULL : ConstantPointerNull,
|
VALUE_CONSTANT_POINTER_NULL : ConstantPointerNull,
|
||||||
|
VALUE_MD_NODE : MetaData,
|
||||||
|
VALUE_MD_STRING : MetaDataString,
|
||||||
VALUE_INSTRUCTION + OPCODE_PHI : PHINode,
|
VALUE_INSTRUCTION + OPCODE_PHI : PHINode,
|
||||||
VALUE_INSTRUCTION + OPCODE_CALL : CallOrInvokeInstruction,
|
VALUE_INSTRUCTION + OPCODE_CALL : CallOrInvokeInstruction,
|
||||||
VALUE_INSTRUCTION + OPCODE_INVOKE : CallOrInvokeInstruction,
|
VALUE_INSTRUCTION + OPCODE_INVOKE : CallOrInvokeInstruction,
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,13 @@ unsigned LLVMMetaDataGetNumOperands(LLVMValueRef mdref)
|
||||||
return llvm::unwrap<llvm::MDNode>(mdref)->getNumOperands();
|
return llvm::unwrap<llvm::MDNode>(mdref)->getNumOperands();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMMetaDataStringGet(LLVMModuleRef modref, const char *s)
|
||||||
|
{
|
||||||
|
LLVMContext & context = unwrap(modref)->getContext();
|
||||||
|
MDString * const mdstring = MDString::get(context, s);
|
||||||
|
return wrap(mdstring);
|
||||||
|
}
|
||||||
|
|
||||||
const char *LLVMGetConstExprOpcodeName(LLVMValueRef inst)
|
const char *LLVMGetConstExprOpcodeName(LLVMValueRef inst)
|
||||||
{
|
{
|
||||||
return llvm::unwrap<llvm::ConstantExpr>(inst)->getOpcodeName();
|
return llvm::unwrap<llvm::ConstantExpr>(inst)->getOpcodeName();
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,11 @@ LLVMValueRef LLVMMetaDataGetOperand(LLVMValueRef mdref, unsigned index);
|
||||||
*/
|
*/
|
||||||
unsigned LLVMMetaDataGetNumOperands(LLVMValueRef mdref);
|
unsigned LLVMMetaDataGetNumOperands(LLVMValueRef mdref);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wraps MDString::get()
|
||||||
|
*/
|
||||||
|
LLVMValueRef LLVMMetaDataStringGet(LLVMModuleRef modref, const char *s);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wraps ConstantExpr::getOpcodeName()
|
* Wraps ConstantExpr::getOpcodeName()
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ else:
|
||||||
|
|
||||||
from llvm import __version__
|
from llvm import __version__
|
||||||
from llvm.core import (Module, Type, GlobalVariable, Function, Builder,
|
from llvm.core import (Module, Type, GlobalVariable, Function, Builder,
|
||||||
Constant, MetaData)
|
Constant, MetaData, MetaDataString)
|
||||||
import llvm.passes as lp
|
import llvm.passes as lp
|
||||||
import llvm.ee as le
|
import llvm.ee as le
|
||||||
|
|
||||||
|
|
@ -395,12 +395,13 @@ class TestMetaData(unittest.TestCase):
|
||||||
def test_metadata(self):
|
def test_metadata(self):
|
||||||
m = Module.new('a')
|
m = Module.new('a')
|
||||||
t = Type.int()
|
t = Type.int()
|
||||||
metadata = MetaData.get(m, [Constant.int(t, 100)])
|
metadata = MetaData.get(m, [Constant.int(t, 100), MetaDataString.get(m, 'abcdef')])
|
||||||
MetaData.add_named_operand(m, 'foo', metadata)
|
MetaData.add_named_operand(m, 'foo', metadata)
|
||||||
self.assertEqual(MetaData.get_named_operands(m, 'foo'), [metadata])
|
self.assertEqual(MetaData.get_named_operands(m, 'foo'), [metadata])
|
||||||
self.assertEqual(MetaData.get_named_operands(m, 'bar'), [])
|
self.assertEqual(MetaData.get_named_operands(m, 'bar'), [])
|
||||||
self.assertEqual(len(metadata.operands), 1)
|
self.assertEqual(len(metadata.operands), 2)
|
||||||
self.assertEqual(metadata.operands[0].z_ext_value, 100)
|
self.assertEqual(metadata.operands[0].z_ext_value, 100)
|
||||||
|
self.assertEqual(metadata.operands[1].string, 'abcdef')
|
||||||
|
|
||||||
tests.append(TestMetaData)
|
tests.append(TestMetaData)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue