[LLVM-C] Add LLVM{IsConstantString,GetAsString,GetElementAsConstant}.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214676 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Peter Zotov 2014-08-03 23:54:16 +00:00
parent 7bf958fe15
commit 5f3f0620f6
2 changed files with 37 additions and 0 deletions

View File

@ -1569,6 +1569,20 @@ LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
LLVMBool DontNullTerminate);
/**
* Returns true if the specified constant is an array of i8.
*
* @see ConstantDataSequential::getAsString()
*/
LLVMBool LLVMIsConstantString(LLVMValueRef c);
/**
* Get the given constant data sequential as a string.
*
* @see ConstantDataSequential::getAsString()
*/
const char *LLVMGetAsString(LLVMValueRef c, size_t* out);
/**
* Create an anonymous ConstantStruct with the specified values.
*
@ -1606,6 +1620,13 @@ LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
LLVMValueRef *ConstantVals,
unsigned Count);
/**
* Get an element at specified index as a constant.
*
* @see ConstantDataSequential::getElementAsConstant()
*/
LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef c, unsigned idx);
/**
* Create a ConstantVector from values.
*

View File

@ -790,11 +790,27 @@ LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length,
DontNullTerminate);
}
LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef c, unsigned idx) {
return wrap(static_cast<ConstantDataSequential*>(unwrap(c))->getElementAsConstant(idx));
}
LLVMBool LLVMIsConstantString(LLVMValueRef c) {
return static_cast<ConstantDataSequential*>(unwrap(c))->isString();
}
const char *LLVMGetAsString(LLVMValueRef c, size_t* Length) {
StringRef str = static_cast<ConstantDataSequential*>(unwrap(c))->getAsString();
*Length = str.size();
return str.data();
}
LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
LLVMValueRef *ConstantVals, unsigned Length) {
ArrayRef<Constant*> V(unwrap<Constant>(ConstantVals, Length), Length);
return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V));
}
LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
LLVMBool Packed) {
return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count,