llvm.org GIT mirror llvm / a2c4f94
Revert 224782: "Finish removing DestroySource." Filip Pizlo pointed out that this changes the C API. It's too late in the release process to figure out how we want to handle this. Reverting the patch is essentially a way of buying time: we don't change the API at the source level for now, we're not trying to fix it with a last-minute patch with a risk of unintended effects, and we preserve our options for fixing this in 3.6.1. This is not ideal, but I think it's the best compromise at this stage. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_36@230431 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 4 years ago
8 changed file(s) with 41 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
1919 import "C"
2020 import "errors"
2121
22 func LinkModules(Dest, Src Module) error {
22 type LinkerMode C.LLVMLinkerMode
23
24 const (
25 LinkerDestroySource = C.LLVMLinkerDestroySource
26 LinkerPreserveSource = C.LLVMLinkerPreserveSource
27 )
28
29 func LinkModules(Dest, Src Module, Mode LinkerMode) error {
2330 var cmsg *C.char
24 failed := C.LLVMLinkModules(Dest.C, Src.C, 0, &cmsg)
31 failed := C.LLVMLinkModules(Dest.C, Src.C, C.LLVMLinkerMode(Mode), &cmsg)
2532 if failed != 0 {
2633 err := errors.New(C.GoString(cmsg))
2734 C.LLVMDisposeMessage(cmsg)
2222
2323 void llvm_raise(value Prototype, char *Message);
2424
25 /* llmodule -> llmodule -> unit */
26 CAMLprim value llvm_link_modules(LLVMModuleRef Dst, LLVMModuleRef Src) {
25 /* llmodule -> llmodule -> Mode.t -> unit */
26 CAMLprim value llvm_link_modules(LLVMModuleRef Dst, LLVMModuleRef Src, value Mode) {
2727 char* Message;
2828
29 if (LLVMLinkModules(Dst, Src, 0, &Message))
29 if (LLVMLinkModules(Dst, Src, Int_val(Mode), &Message))
3030 llvm_raise(*caml_named_value("Llvm_linker.Error"), Message);
3131
3232 return Val_unit;
1010
1111 let () = Callback.register_exception "Llvm_linker.Error" (Error "")
1212
13 external link_modules : Llvm.llmodule -> Llvm.llmodule -> unit
13 module Mode = struct
14 type t =
15 | DestroySource
16 | PreserveSource
17 end
18
19 external link_modules : Llvm.llmodule -> Llvm.llmodule -> Mode.t -> unit
1420 = "llvm_link_modules"
1313
1414 exception Error of string
1515
16 (** Linking mode. *)
17 module Mode : sig
18 type t =
19 | DestroySource
20 | PreserveSource
21 end
22
1623 (** [link_modules dst src mode] links [src] into [dst], raising [Error]
1724 if the linking fails. *)
18 val link_modules : Llvm.llmodule -> Llvm.llmodule -> unit
25 val link_modules : Llvm.llmodule -> Llvm.llmodule -> Mode.t -> unit
382382
383383 It was fairly broken and was removed.
384384
385 The mode is currently still available in the C API for source
386 compatibility, but it doesn't have any effect.
387
385388
386389 Garbage Collection
387390 ------------------
1919 extern "C" {
2020 #endif
2121
22
23 /* Note: LLVMLinkerPreserveSource has no effect. */
24 typedef enum {
25 LLVMLinkerDestroySource = 0, /* Allow source module to be destroyed. */
26 LLVMLinkerPreserveSource = 1 /* Preserve the source module. */
27 } LLVMLinkerMode;
28
29
2230 /* Links the source module into the destination module, taking ownership
2331 * of the source module away from the caller. Optionally returns a
2432 * human-readable description of any errors that occurred in linking.
2533 * OutMessage must be disposed with LLVMDisposeMessage. The return value
2634 * is true if an error occurred, false otherwise. */
2735 LLVMBool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src,
28 unsigned Unused, char **OutMessage);
36 LLVMLinkerMode Mode, char **OutMessage);
2937
3038 #ifdef __cplusplus
3139 }
17481748 //===----------------------------------------------------------------------===//
17491749
17501750 LLVMBool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src,
1751 unsigned Unused, char **OutMessages) {
1751 LLVMLinkerMode Mode, char **OutMessages) {
17521752 Module *D = unwrap(Dest);
17531753 std::string Message;
17541754 raw_string_ostream Stream(Message);
4444
4545 let m1 = make_module "one"
4646 and m2 = make_module "two" in
47 link_modules m1 m2;
47 link_modules m1 m2 Mode.DestroySource;
4848 dispose_module m1;
4949
5050 let m1 = make_module "one"