[llvm] r256065 - Deprecate a few C APIs.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 18 15:46:42 PST 2015


Author: rafael
Date: Fri Dec 18 17:46:42 2015
New Revision: 256065

URL: http://llvm.org/viewvc/llvm-project?rev=256065&view=rev
Log:
Deprecate a few C APIs.

This deprecates:
* LLVMParseBitcode
* LLVMParseBitcodeInContext
* LLVMGetBitcodeModuleInContext
* LLVMGetBitcodeModule

They are replaced with the functions with a 2 suffix which do not record
a diagnostic.

Modified:
    llvm/trunk/bindings/go/llvm/bitreader.go
    llvm/trunk/bindings/ocaml/bitreader/bitreader_ocaml.c
    llvm/trunk/bindings/python/llvm/bit_reader.py
    llvm/trunk/docs/ReleaseNotes.rst
    llvm/trunk/include/llvm-c/BitReader.h
    llvm/trunk/lib/Bitcode/Reader/BitReader.cpp
    llvm/trunk/test/Bindings/llvm-c/invalid-bitcode.test
    llvm/trunk/tools/llvm-c-test/llvm-c-test.h
    llvm/trunk/tools/llvm-c-test/main.c
    llvm/trunk/tools/llvm-c-test/module.c

Modified: llvm/trunk/bindings/go/llvm/bitreader.go
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/go/llvm/bitreader.go?rev=256065&r1=256064&r2=256065&view=diff
==============================================================================
--- llvm/trunk/bindings/go/llvm/bitreader.go (original)
+++ llvm/trunk/bindings/go/llvm/bitreader.go Fri Dec 18 17:46:42 2015
@@ -41,7 +41,7 @@ func ParseBitcodeFile(name string) (Modu
 	defer C.LLVMDisposeMemoryBuffer(buf)
 
 	var m Module
-	if C.LLVMParseBitcode(buf, &m.C, &errmsg) == 0 {
+	if C.LLVMParseBitcode2(buf, &m.C) == 0 {
 		return m, nil
 	}
 

Modified: llvm/trunk/bindings/ocaml/bitreader/bitreader_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/bitreader/bitreader_ocaml.c?rev=256065&r1=256064&r2=256065&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/bitreader/bitreader_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/bitreader/bitreader_ocaml.c Fri Dec 18 17:46:42 2015
@@ -23,10 +23,9 @@ void llvm_raise(value Prototype, char *M
 /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
 CAMLprim LLVMModuleRef llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
   LLVMModuleRef M;
-  char *Message;
 
-  if (LLVMGetBitcodeModuleInContext(C, MemBuf, &M, &Message))
-    llvm_raise(*caml_named_value("Llvm_bitreader.Error"), Message);
+  if (LLVMGetBitcodeModuleInContext2(C, MemBuf, &M))
+    llvm_raise(*caml_named_value("Llvm_bitreader.Error"), "");
 
   return M;
 }
@@ -34,10 +33,9 @@ CAMLprim LLVMModuleRef llvm_get_module(L
 /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
 CAMLprim LLVMModuleRef llvm_parse_bitcode(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
   LLVMModuleRef M;
-  char *Message;
 
-  if (LLVMParseBitcodeInContext(C, MemBuf, &M, &Message))
-    llvm_raise(*caml_named_value("Llvm_bitreader.Error"), Message);
+  if (LLVMParseBitcodeInContext2(C, MemBuf, &M))
+    llvm_raise(*caml_named_value("Llvm_bitreader.Error"), "");
 
   return M;
 }

Modified: llvm/trunk/bindings/python/llvm/bit_reader.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/python/llvm/bit_reader.py?rev=256065&r1=256064&r2=256065&view=diff
==============================================================================
--- llvm/trunk/bindings/python/llvm/bit_reader.py (original)
+++ llvm/trunk/bindings/python/llvm/bit_reader.py Fri Dec 18 17:46:42 2015
@@ -16,16 +16,15 @@ lib = get_library()
 def parse_bitcode(mem_buffer):
     """Input is .core.MemoryBuffer"""
     module = c_object_p()
-    out = c_char_p(None)
-    result = lib.LLVMParseBitcode(mem_buffer, byref(module), byref(out))
+    result = lib.LLVMParseBitcode2(mem_buffer, byref(module))
     if result:
-        raise RuntimeError('LLVM Error: %s' % out.value)
+        raise RuntimeError('LLVM Error')
     m = Module(module)
     m.take_ownership(mem_buffer)
     return m
 
 def register_library(library):
-    library.LLVMParseBitcode.argtypes = [MemoryBuffer, POINTER(c_object_p), POINTER(c_char_p)]
-    library.LLVMParseBitcode.restype = bool
+    library.LLVMParseBitcode2.argtypes = [MemoryBuffer, POINTER(c_object_p)]
+    library.LLVMParseBitcode2.restype = bool
 
 register_library(lib)

Modified: llvm/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ReleaseNotes.rst?rev=256065&r1=256064&r2=256065&view=diff
==============================================================================
--- llvm/trunk/docs/ReleaseNotes.rst (original)
+++ llvm/trunk/docs/ReleaseNotes.rst Fri Dec 18 17:46:42 2015
@@ -49,6 +49,12 @@ Non-comprehensive list of changes in thi
    * Destroys the source instead of only damaging it.
    * Does not record a message. Use the diagnostic handler instead.
 
+* The C API functions LLVMParseBitcode, LLVMParseBitcodeInContext,
+  LLVMGetBitcodeModuleInContext and LLVMGetBitcodeModule have been deprecated.
+  They will be removed in 3.9. Please migrate to the versions with a 2 suffix.
+  Unlike the old ones the new ones do not record a diagnostic message. Use
+  the diagnostic handler instead.
+
 * The deprecated C APIs LLVMGetBitcodeModuleProviderInContext and
   LLVMGetBitcodeModuleProvider have been removed.
 

Modified: llvm/trunk/include/llvm-c/BitReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/BitReader.h?rev=256065&r1=256064&r2=256065&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/BitReader.h (original)
+++ llvm/trunk/include/llvm-c/BitReader.h Fri Dec 18 17:46:42 2015
@@ -34,24 +34,46 @@ extern "C" {
 
 /* Builds a module from the bitcode in the specified memory buffer, returning a
    reference to the module via the OutModule parameter. Returns 0 on success.
-   Optionally returns a human-readable error message via OutMessage. */
+   Optionally returns a human-readable error message via OutMessage.
+
+   This is deprecated. Use LLVMParseBitcode2. */
 LLVMBool LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutModule,
                           char **OutMessage);
 
+/* Builds a module from the bitcode in the specified memory buffer, returning a
+   reference to the module via the OutModule parameter. Returns 0 on success. */
+LLVMBool LLVMParseBitcode2(LLVMMemoryBufferRef MemBuf,
+                           LLVMModuleRef *OutModule);
+
+/* This is deprecated. Use LLVMParseBitcodeInContext2. */
 LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
                                    LLVMMemoryBufferRef MemBuf,
                                    LLVMModuleRef *OutModule, char **OutMessage);
 
+LLVMBool LLVMParseBitcodeInContext2(LLVMContextRef ContextRef,
+                                    LLVMMemoryBufferRef MemBuf,
+                                    LLVMModuleRef *OutModule);
+
 /** Reads a module from the specified path, returning via the OutMP parameter
     a module provider which performs lazy deserialization. Returns 0 on success.
-    Optionally returns a human-readable error message via OutMessage. */
+    Optionally returns a human-readable error message via OutMessage.
+    This is deprecated. Use LLVMGetBitcodeModuleInContext2. */
 LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
                                        LLVMMemoryBufferRef MemBuf,
                                        LLVMModuleRef *OutM, char **OutMessage);
 
+/** Reads a module from the specified path, returning via the OutMP parameter a
+ * module provider which performs lazy deserialization. Returns 0 on success. */
+LLVMBool LLVMGetBitcodeModuleInContext2(LLVMContextRef ContextRef,
+                                        LLVMMemoryBufferRef MemBuf,
+                                        LLVMModuleRef *OutM);
+
+/* This is deprecated. Use LLVMGetBitcodeModule2. */
 LLVMBool LLVMGetBitcodeModule(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
                               char **OutMessage);
 
+LLVMBool LLVMGetBitcodeModule2(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM);
+
 /**
  * @}
  */

Modified: llvm/trunk/lib/Bitcode/Reader/BitReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitReader.cpp?rev=256065&r1=256064&r2=256065&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitReader.cpp Fri Dec 18 17:46:42 2015
@@ -29,6 +29,12 @@ LLVMBool LLVMParseBitcode(LLVMMemoryBuff
                                    OutMessage);
 }
 
+LLVMBool LLVMParseBitcode2(LLVMMemoryBufferRef MemBuf,
+                           LLVMModuleRef *OutModule) {
+  return LLVMParseBitcodeInContext2(wrap(&getGlobalContext()), MemBuf,
+                                    OutModule);
+}
+
 static void diagnosticHandler(const DiagnosticInfo &DI, void *C) {
   auto *Message = reinterpret_cast<std::string *>(C);
   raw_string_ostream Stream(*Message);
@@ -64,6 +70,22 @@ LLVMBool LLVMParseBitcodeInContext(LLVMC
   return 0;
 }
 
+LLVMBool LLVMParseBitcodeInContext2(LLVMContextRef ContextRef,
+                                    LLVMMemoryBufferRef MemBuf,
+                                    LLVMModuleRef *OutModule) {
+  MemoryBufferRef Buf = unwrap(MemBuf)->getMemBufferRef();
+  LLVMContext &Ctx = *unwrap(ContextRef);
+
+  ErrorOr<std::unique_ptr<Module>> ModuleOrErr = parseBitcodeFile(Buf, Ctx);
+  if (ModuleOrErr.getError()) {
+    *OutModule = wrap((Module *)nullptr);
+    return 1;
+  }
+
+  *OutModule = wrap(ModuleOrErr.get().release());
+  return 0;
+}
+
 /* Reads a module from the specified path, returning via the OutModule parameter
    a module provider which performs lazy deserialization. Returns 0 on success.
    Optionally returns a human-readable error message via OutMessage. */
@@ -96,8 +118,32 @@ LLVMBool LLVMGetBitcodeModuleInContext(L
   return 0;
 }
 
+LLVMBool LLVMGetBitcodeModuleInContext2(LLVMContextRef ContextRef,
+                                        LLVMMemoryBufferRef MemBuf,
+                                        LLVMModuleRef *OutM) {
+  LLVMContext &Ctx = *unwrap(ContextRef);
+  std::unique_ptr<MemoryBuffer> Owner(unwrap(MemBuf));
+
+  ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
+      getLazyBitcodeModule(std::move(Owner), Ctx);
+  Owner.release();
+
+  if (ModuleOrErr.getError()) {
+    *OutM = wrap((Module *)nullptr);
+    return 1;
+  }
+
+  *OutM = wrap(ModuleOrErr.get().release());
+  return 0;
+}
+
 LLVMBool LLVMGetBitcodeModule(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
                               char **OutMessage) {
   return LLVMGetBitcodeModuleInContext(LLVMGetGlobalContext(), MemBuf, OutM,
                                        OutMessage);
 }
+
+LLVMBool LLVMGetBitcodeModule2(LLVMMemoryBufferRef MemBuf,
+                               LLVMModuleRef *OutM) {
+  return LLVMGetBitcodeModuleInContext2(LLVMGetGlobalContext(), MemBuf, OutM);
+}

Modified: llvm/trunk/test/Bindings/llvm-c/invalid-bitcode.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/llvm-c/invalid-bitcode.test?rev=256065&r1=256064&r2=256065&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/llvm-c/invalid-bitcode.test (original)
+++ llvm/trunk/test/Bindings/llvm-c/invalid-bitcode.test Fri Dec 18 17:46:42 2015
@@ -2,3 +2,9 @@
 ; RUN: not llvm-c-test --lazy-module-dump < %S/Inputs/invalid.ll.bc 2>&1 | FileCheck %s
 
 CHECK: Error parsing bitcode: Unknown attribute kind (52)
+
+
+; RUN: not llvm-c-test --new-module-dump < %S/Inputs/invalid.ll.bc 2>&1 | FileCheck --check-prefix=NEW %s
+; RUN: not llvm-c-test --lazy-new-module-dump < %S/Inputs/invalid.ll.bc 2>&1 | FileCheck --check-prefix=NEW %s
+
+NEW: Error with new bitcode parser: Unknown attribute kind (52)

Modified: llvm/trunk/tools/llvm-c-test/llvm-c-test.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-c-test/llvm-c-test.h?rev=256065&r1=256064&r2=256065&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-c-test/llvm-c-test.h (original)
+++ llvm/trunk/tools/llvm-c-test/llvm-c-test.h Fri Dec 18 17:46:42 2015
@@ -19,7 +19,7 @@
 void tokenize_stdin(void (*cb)(char **tokens, int ntokens));
 
 // module.c
-int module_dump(bool Lazy);
+int module_dump(bool Lazy, bool New);
 int module_list_functions(void);
 int module_list_globals(void);
 

Modified: llvm/trunk/tools/llvm-c-test/main.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-c-test/main.c?rev=256065&r1=256064&r2=256065&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-c-test/main.c (original)
+++ llvm/trunk/tools/llvm-c-test/main.c Fri Dec 18 17:46:42 2015
@@ -26,6 +26,11 @@ static void print_usage(void) {
   fprintf(stderr, "  * --lazy-module-dump\n");
   fprintf(stderr,
           "    Lazily read bytecode from stdin - print disassembly\n\n");
+  fprintf(stderr, "  * --new-module-dump\n");
+  fprintf(stderr, "    Read bytecode from stdin - print disassembly\n\n");
+  fprintf(stderr, "  * --lazy-new-module-dump\n");
+  fprintf(stderr,
+          "    Lazily read bytecode from stdin - print disassembly\n\n");
   fprintf(stderr, "  * --module-list-functions\n");
   fprintf(stderr,
           "    Read bytecode from stdin - list summary of functions\n\n");
@@ -52,10 +57,14 @@ int main(int argc, char **argv) {
 
   LLVMInitializeCore(pr);
 
-  if (argc == 2 && !strcmp(argv[1], "--lazy-module-dump")) {
-    return module_dump(true);
+  if (argc == 2 && !strcmp(argv[1], "--lazy-new-module-dump")) {
+    return module_dump(true, true);
+  } else if (argc == 2 && !strcmp(argv[1], "--new-module-dump")) {
+    return module_dump(false, true);
+  } else if (argc == 2 && !strcmp(argv[1], "--lazy-module-dump")) {
+    return module_dump(true, false);
   } else if (argc == 2 && !strcmp(argv[1], "--module-dump")) {
-    return module_dump(false);
+    return module_dump(false, false);
   } else if (argc == 2 && !strcmp(argv[1], "--module-list-functions")) {
     return module_list_functions();
   } else if (argc == 2 && !strcmp(argv[1], "--module-list-globals")) {

Modified: llvm/trunk/tools/llvm-c-test/module.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-c-test/module.c?rev=256065&r1=256064&r2=256065&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-c-test/module.c (original)
+++ llvm/trunk/tools/llvm-c-test/module.c Fri Dec 18 17:46:42 2015
@@ -19,7 +19,14 @@
 #include <stdlib.h>
 #include <string.h>
 
-static LLVMModuleRef load_module(bool Lazy) {
+static void diagnosticHandler(LLVMDiagnosticInfoRef DI, void *C) {
+  char *CErr = LLVMGetDiagInfoDescription(DI);
+  fprintf(stderr, "Error with new bitcode parser: %s\n", CErr);
+  LLVMDisposeMessage(CErr);
+  exit(1);
+}
+
+static LLVMModuleRef load_module(bool Lazy, bool New) {
   LLVMMemoryBufferRef MB;
   LLVMModuleRef M;
   char *msg = NULL;
@@ -30,10 +37,19 @@ static LLVMModuleRef load_module(bool La
   }
 
   LLVMBool Ret;
-  if (Lazy)
-    Ret = LLVMGetBitcodeModule(MB, &M, &msg);
-  else
-    Ret = LLVMParseBitcode(MB, &M, &msg);
+  if (New) {
+    LLVMContextRef C = LLVMGetGlobalContext();
+    LLVMContextSetDiagnosticHandler(C, diagnosticHandler, NULL);
+    if (Lazy)
+      Ret = LLVMGetBitcodeModule2(MB, &M);
+    else
+      Ret = LLVMParseBitcode2(MB, &M);
+  } else {
+    if (Lazy)
+      Ret = LLVMGetBitcodeModule(MB, &M, &msg);
+    else
+      Ret = LLVMParseBitcode(MB, &M, &msg);
+  }
 
   if (Ret) {
     fprintf(stderr, "Error parsing bitcode: %s\n", msg);
@@ -47,8 +63,8 @@ static LLVMModuleRef load_module(bool La
   return M;
 }
 
-int module_dump(bool Lazy) {
-  LLVMModuleRef M = load_module(Lazy);
+int module_dump(bool Lazy, bool New) {
+  LLVMModuleRef M = load_module(Lazy, New);
 
   char *irstr = LLVMPrintModuleToString(M);
   puts(irstr);
@@ -60,7 +76,7 @@ int module_dump(bool Lazy) {
 }
 
 int module_list_functions(void) {
-  LLVMModuleRef M = load_module(false);
+  LLVMModuleRef M = load_module(false, false);
   LLVMValueRef f;
 
   f = LLVMGetFirstFunction(M);
@@ -101,7 +117,7 @@ int module_list_functions(void) {
 }
 
 int module_list_globals(void) {
-  LLVMModuleRef M = load_module(false);
+  LLVMModuleRef M = load_module(false, false);
   LLVMValueRef g;
 
   g = LLVMGetFirstGlobal(M);




More information about the llvm-commits mailing list