diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h index f9717cc5f551..a48ea7e74571 100644 --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -722,6 +722,14 @@ LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty); */ void LLVMDumpType(LLVMTypeRef Val); +/** + * Return a string representation of the type. Use + * LLVMDisposeMessage to free the string. + * + * @see llvm::Type::print() + */ +char *LLVMPrintTypeToString(LLVMTypeRef Val); + /** * @defgroup LLVMCCoreTypeInt Integer Types * diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 7d52386b061a..16af7332d3cc 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -224,6 +224,16 @@ void LLVMDumpType(LLVMTypeRef Ty) { return unwrap(Ty)->dump(); } +char *LLVMPrintTypeToString(LLVMTypeRef Ty) { + std::string buf; + raw_string_ostream os(buf); + + unwrap(Ty)->print(os); + os.flush(); + + return strdup(buf.c_str()); +} + /*--.. Operations on integer types .........................................--*/ LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C) {