Index: include/llvm-c/Core.h =================================================================== --- include/llvm-c/Core.h +++ include/llvm-c/Core.h @@ -481,6 +481,21 @@ void LLVMDisposeModule(LLVMModuleRef M); /** + * Obtain the identifier of a module. The result must be discarded with + * LLVMDisposeMessage. + * + * @see Module::getModuleIdentifier() + */ +char *LLVMGetModuleIdentifier(LLVMModuleRef M); + +/** + * Set the identifier of a module. + * + * @see Module::setModuleIdentifier() + */ +void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *ID); + +/** * Obtain the data layout for a module. * * @see Module::getDataLayoutStr() Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -157,6 +157,15 @@ delete unwrap(M); } +char *LLVMGetModuleIdentifier(LLVMModuleRef M) { + return strdup(unwrap(M)->getModuleIdentifier().c_str()); +} + +void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *ID) { + unwrap(M)->setModuleIdentifier(ID); +} + + /*--.. Data layout .........................................................--*/ const char *LLVMGetDataLayoutStr(LLVMModuleRef M) { return unwrap(M)->getDataLayoutStr().c_str(); Index: tools/llvm-c-test/echo.cpp =================================================================== --- tools/llvm-c-test/echo.cpp +++ tools/llvm-c-test/echo.cpp @@ -213,6 +213,13 @@ } LLVMValueRef clone_constant(LLVMValueRef Cst, LLVMModuleRef M) { + const char *TmpName = "Hello, test module"; + const char *OldName = LLVMGetModuleIdentifier(M); + LLVMSetModuleIdentifier(M, TmpName); + if (strcmp(TmpName, LLVMGetModuleIdentifier(M)) != 0) + report_fatal_error("LLVM{Set,Get}ModuleIdentifier failed"); + LLVMSetModuleIdentifier(M, OldName); + if (!LLVMIsAConstant(Cst)) report_fatal_error("Expected a constant");