[PATCH] D18736: [llvm-c] Improve IR Introspection: Add LLVM{Get, Set}ModuleIdentifier

Nicole Mazzuca via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 2 21:49:14 PDT 2016


ubsan created this revision.
ubsan added a reviewer: whitequark.
ubsan added a subscriber: llvm-commits.

Also, tests and stuff

http://reviews.llvm.org/D18736

Files:
  include/llvm-c/Core.h
  lib/IR/Core.cpp
  tools/llvm-c-test/echo.cpp

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");
 
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: 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()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18736.52490.patch
Type: text/x-patch
Size: 1886 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160403/eefd788f/attachment.bin>


More information about the llvm-commits mailing list