aboutsummaryrefslogtreecommitdiffstats
path: root/bindings/go/llvm/linker.go
blob: 31e9ad24bf528c21004c985c242fc51bf78d38ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//===- linker.go - Bindings for linker ------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines bindings for the linker component.
//
//===----------------------------------------------------------------------===//

package llvm

/*
#include "llvm-c/Linker.h"
#include <stdlib.h>
*/
import "C"
import "errors"

type LinkerMode C.LLVMLinkerMode

const (
	LinkerDestroySource  = C.LLVMLinkerDestroySource
	LinkerPreserveSource = C.LLVMLinkerPreserveSource
)

func LinkModules(Dest, Src Module, Mode LinkerMode) error {
	var cmsg *C.char
	failed := C.LLVMLinkModules(Dest.C, Src.C, C.LLVMLinkerMode(Mode), &cmsg)
	if failed != 0 {
		err := errors.New(C.GoString(cmsg))
		C.LLVMDisposeMessage(cmsg)
		return err
	}
	return nil
}