llvm.org GIT mirror llvm / 8d184ad
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256065 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
10 changed file(s) with 129 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
4040 defer C.LLVMDisposeMemoryBuffer(buf)
4141
4242 var m Module
43 if C.LLVMParseBitcode(buf, &m.C, &errmsg) == 0 {
43 if C.LLVMParseBitcode2(buf, &m.C) == 0 {
4444 return m, nil
4545 }
4646
2222 /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
2323 CAMLprim LLVMModuleRef llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
2424 LLVMModuleRef M;
25 char *Message;
2625
27 if (LLVMGetBitcodeModuleInContext(C, MemBuf, &M, &Message))
28 llvm_raise(*caml_named_value("Llvm_bitreader.Error"), Message);
26 if (LLVMGetBitcodeModuleInContext2(C, MemBuf, &M))
27 llvm_raise(*caml_named_value("Llvm_bitreader.Error"), "");
2928
3029 return M;
3130 }
3332 /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
3433 CAMLprim LLVMModuleRef llvm_parse_bitcode(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
3534 LLVMModuleRef M;
36 char *Message;
3735
38 if (LLVMParseBitcodeInContext(C, MemBuf, &M, &Message))
39 llvm_raise(*caml_named_value("Llvm_bitreader.Error"), Message);
36 if (LLVMParseBitcodeInContext2(C, MemBuf, &M))
37 llvm_raise(*caml_named_value("Llvm_bitreader.Error"), "");
4038
4139 return M;
4240 }
1515 def parse_bitcode(mem_buffer):
1616 """Input is .core.MemoryBuffer"""
1717 module = c_object_p()
18 out = c_char_p(None)
19 result = lib.LLVMParseBitcode(mem_buffer, byref(module), byref(out))
18 result = lib.LLVMParseBitcode2(mem_buffer, byref(module))
2019 if result:
21 raise RuntimeError('LLVM Error: %s' % out.value)
20 raise RuntimeError('LLVM Error')
2221 m = Module(module)
2322 m.take_ownership(mem_buffer)
2423 return m
2524
2625 def register_library(library):
27 library.LLVMParseBitcode.argtypes = [MemoryBuffer, POINTER(c_object_p), POINTER(c_char_p)]
28 library.LLVMParseBitcode.restype = bool
26 library.LLVMParseBitcode2.argtypes = [MemoryBuffer, POINTER(c_object_p)]
27 library.LLVMParseBitcode2.restype = bool
2928
3029 register_library(lib)
4747 * Doesn't take an unused parameter.
4848 * Destroys the source instead of only damaging it.
4949 * Does not record a message. Use the diagnostic handler instead.
50
51 * The C API functions LLVMParseBitcode, LLVMParseBitcodeInContext,
52 LLVMGetBitcodeModuleInContext and LLVMGetBitcodeModule have been deprecated.
53 They will be removed in 3.9. Please migrate to the versions with a 2 suffix.
54 Unlike the old ones the new ones do not record a diagnostic message. Use
55 the diagnostic handler instead.
5056
5157 * The deprecated C APIs LLVMGetBitcodeModuleProviderInContext and
5258 LLVMGetBitcodeModuleProvider have been removed.
3333
3434 /* Builds a module from the bitcode in the specified memory buffer, returning a
3535 reference to the module via the OutModule parameter. Returns 0 on success.
36 Optionally returns a human-readable error message via OutMessage. */
36 Optionally returns a human-readable error message via OutMessage.
37
38 This is deprecated. Use LLVMParseBitcode2. */
3739 LLVMBool LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutModule,
3840 char **OutMessage);
3941
42 /* Builds a module from the bitcode in the specified memory buffer, returning a
43 reference to the module via the OutModule parameter. Returns 0 on success. */
44 LLVMBool LLVMParseBitcode2(LLVMMemoryBufferRef MemBuf,
45 LLVMModuleRef *OutModule);
46
47 /* This is deprecated. Use LLVMParseBitcodeInContext2. */
4048 LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
4149 LLVMMemoryBufferRef MemBuf,
4250 LLVMModuleRef *OutModule, char **OutMessage);
4351
52 LLVMBool LLVMParseBitcodeInContext2(LLVMContextRef ContextRef,
53 LLVMMemoryBufferRef MemBuf,
54 LLVMModuleRef *OutModule);
55
4456 /** Reads a module from the specified path, returning via the OutMP parameter
4557 a module provider which performs lazy deserialization. Returns 0 on success.
46 Optionally returns a human-readable error message via OutMessage. */
58 Optionally returns a human-readable error message via OutMessage.
59 This is deprecated. Use LLVMGetBitcodeModuleInContext2. */
4760 LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
4861 LLVMMemoryBufferRef MemBuf,
4962 LLVMModuleRef *OutM, char **OutMessage);
5063
64 /** Reads a module from the specified path, returning via the OutMP parameter a
65 * module provider which performs lazy deserialization. Returns 0 on success. */
66 LLVMBool LLVMGetBitcodeModuleInContext2(LLVMContextRef ContextRef,
67 LLVMMemoryBufferRef MemBuf,
68 LLVMModuleRef *OutM);
69
70 /* This is deprecated. Use LLVMGetBitcodeModule2. */
5171 LLVMBool LLVMGetBitcodeModule(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
5272 char **OutMessage);
73
74 LLVMBool LLVMGetBitcodeModule2(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM);
5375
5476 /**
5577 * @}
2828 OutMessage);
2929 }
3030
31 LLVMBool LLVMParseBitcode2(LLVMMemoryBufferRef MemBuf,
32 LLVMModuleRef *OutModule) {
33 return LLVMParseBitcodeInContext2(wrap(&getGlobalContext()), MemBuf,
34 OutModule);
35 }
36
3137 static void diagnosticHandler(const DiagnosticInfo &DI, void *C) {
3238 auto *Message = reinterpret_cast(C);
3339 raw_string_ostream Stream(*Message);
5561 if (ModuleOrErr.getError()) {
5662 if (OutMessage)
5763 *OutMessage = strdup(Message.c_str());
64 *OutModule = wrap((Module *)nullptr);
65 return 1;
66 }
67
68 *OutModule = wrap(ModuleOrErr.get().release());
69 return 0;
70 }
71
72 LLVMBool LLVMParseBitcodeInContext2(LLVMContextRef ContextRef,
73 LLVMMemoryBufferRef MemBuf,
74 LLVMModuleRef *OutModule) {
75 MemoryBufferRef Buf = unwrap(MemBuf)->getMemBufferRef();
76 LLVMContext &Ctx = *unwrap(ContextRef);
77
78 ErrorOr> ModuleOrErr = parseBitcodeFile(Buf, Ctx);
79 if (ModuleOrErr.getError()) {
5880 *OutModule = wrap((Module *)nullptr);
5981 return 1;
6082 }
95117 return 0;
96118 }
97119
120 LLVMBool LLVMGetBitcodeModuleInContext2(LLVMContextRef ContextRef,
121 LLVMMemoryBufferRef MemBuf,
122 LLVMModuleRef *OutM) {
123 LLVMContext &Ctx = *unwrap(ContextRef);
124 std::unique_ptr Owner(unwrap(MemBuf));
125
126 ErrorOr> ModuleOrErr =
127 getLazyBitcodeModule(std::move(Owner), Ctx);
128 Owner.release();
129
130 if (ModuleOrErr.getError()) {
131 *OutM = wrap((Module *)nullptr);
132 return 1;
133 }
134
135 *OutM = wrap(ModuleOrErr.get().release());
136 return 0;
137 }
138
98139 LLVMBool LLVMGetBitcodeModule(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
99140 char **OutMessage) {
100141 return LLVMGetBitcodeModuleInContext(LLVMGetGlobalContext(), MemBuf, OutM,
101142 OutMessage);
102143 }
144
145 LLVMBool LLVMGetBitcodeModule2(LLVMMemoryBufferRef MemBuf,
146 LLVMModuleRef *OutM) {
147 return LLVMGetBitcodeModuleInContext2(LLVMGetGlobalContext(), MemBuf, OutM);
148 }
11 ; RUN: not llvm-c-test --lazy-module-dump < %S/Inputs/invalid.ll.bc 2>&1 | FileCheck %s
22
33 CHECK: Error parsing bitcode: Unknown attribute kind (52)
4
5
6 ; RUN: not llvm-c-test --new-module-dump < %S/Inputs/invalid.ll.bc 2>&1 | FileCheck --check-prefix=NEW %s
7 ; RUN: not llvm-c-test --lazy-new-module-dump < %S/Inputs/invalid.ll.bc 2>&1 | FileCheck --check-prefix=NEW %s
8
9 NEW: Error with new bitcode parser: Unknown attribute kind (52)
1818 void tokenize_stdin(void (*cb)(char **tokens, int ntokens));
1919
2020 // module.c
21 int module_dump(bool Lazy);
21 int module_dump(bool Lazy, bool New);
2222 int module_list_functions(void);
2323 int module_list_globals(void);
2424
2525 fprintf(stderr, " * --lazy-module-dump\n");
2626 fprintf(stderr,
2727 " Lazily read bytecode from stdin - print disassembly\n\n");
28 fprintf(stderr, " * --new-module-dump\n");
29 fprintf(stderr, " Read bytecode from stdin - print disassembly\n\n");
30 fprintf(stderr, " * --lazy-new-module-dump\n");
31 fprintf(stderr,
32 " Lazily read bytecode from stdin - print disassembly\n\n");
2833 fprintf(stderr, " * --module-list-functions\n");
2934 fprintf(stderr,
3035 " Read bytecode from stdin - list summary of functions\n\n");
5156
5257 LLVMInitializeCore(pr);
5358
54 if (argc == 2 && !strcmp(argv[1], "--lazy-module-dump")) {
55 return module_dump(true);
59 if (argc == 2 && !strcmp(argv[1], "--lazy-new-module-dump")) {
60 return module_dump(true, true);
61 } else if (argc == 2 && !strcmp(argv[1], "--new-module-dump")) {
62 return module_dump(false, true);
63 } else if (argc == 2 && !strcmp(argv[1], "--lazy-module-dump")) {
64 return module_dump(true, false);
5665 } else if (argc == 2 && !strcmp(argv[1], "--module-dump")) {
57 return module_dump(false);
66 return module_dump(false, false);
5867 } else if (argc == 2 && !strcmp(argv[1], "--module-list-functions")) {
5968 return module_list_functions();
6069 } else if (argc == 2 && !strcmp(argv[1], "--module-list-globals")) {
1818 #include
1919 #include
2020
21 static LLVMModuleRef load_module(bool Lazy) {
21 static void diagnosticHandler(LLVMDiagnosticInfoRef DI, void *C) {
22 char *CErr = LLVMGetDiagInfoDescription(DI);
23 fprintf(stderr, "Error with new bitcode parser: %s\n", CErr);
24 LLVMDisposeMessage(CErr);
25 exit(1);
26 }
27
28 static LLVMModuleRef load_module(bool Lazy, bool New) {
2229 LLVMMemoryBufferRef MB;
2330 LLVMModuleRef M;
2431 char *msg = NULL;
2936 }
3037
3138 LLVMBool Ret;
32 if (Lazy)
33 Ret = LLVMGetBitcodeModule(MB, &M, &msg);
34 else
35 Ret = LLVMParseBitcode(MB, &M, &msg);
39 if (New) {
40 LLVMContextRef C = LLVMGetGlobalContext();
41 LLVMContextSetDiagnosticHandler(C, diagnosticHandler, NULL);
42 if (Lazy)
43 Ret = LLVMGetBitcodeModule2(MB, &M);
44 else
45 Ret = LLVMParseBitcode2(MB, &M);
46 } else {
47 if (Lazy)
48 Ret = LLVMGetBitcodeModule(MB, &M, &msg);
49 else
50 Ret = LLVMParseBitcode(MB, &M, &msg);
51 }
3652
3753 if (Ret) {
3854 fprintf(stderr, "Error parsing bitcode: %s\n", msg);
4662 return M;
4763 }
4864
49 int module_dump(bool Lazy) {
50 LLVMModuleRef M = load_module(Lazy);
65 int module_dump(bool Lazy, bool New) {
66 LLVMModuleRef M = load_module(Lazy, New);
5167
5268 char *irstr = LLVMPrintModuleToString(M);
5369 puts(irstr);
5975 }
6076
6177 int module_list_functions(void) {
62 LLVMModuleRef M = load_module(false);
78 LLVMModuleRef M = load_module(false, false);
6379 LLVMValueRef f;
6480
6581 f = LLVMGetFirstFunction(M);
100116 }
101117
102118 int module_list_globals(void) {
103 LLVMModuleRef M = load_module(false);
119 LLVMModuleRef M = load_module(false, false);
104120 LLVMValueRef g;
105121
106122 g = LLVMGetFirstGlobal(M);