diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index f9717cc5f55..a48ea7e7457 100644 --- a/include/llvm-c/Core.h +++ b/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/lib/IR/Core.cpp b/lib/IR/Core.cpp index 7d52386b061..16af7332d3c 100644 --- a/lib/IR/Core.cpp +++ b/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) {