• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//===- support.go - Bindings for support ----------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines bindings for the support component.
11//
12//===----------------------------------------------------------------------===//
13
14package llvm
15
16/*
17#include "llvm-c/Support.h"
18#include "SupportBindings.h"
19#include <stdlib.h>
20*/
21import "C"
22
23import (
24	"errors"
25	"unsafe"
26)
27
28// Loads a dynamic library such that it may be used as an LLVM plugin.
29// See llvm::sys::DynamicLibrary::LoadLibraryPermanently.
30func LoadLibraryPermanently(lib string) error {
31	var errstr *C.char
32	libstr := C.CString(lib)
33	defer C.free(unsafe.Pointer(libstr))
34	C.LLVMLoadLibraryPermanently2(libstr, &errstr)
35	if errstr != nil {
36		err := errors.New(C.GoString(errstr))
37		C.free(unsafe.Pointer(errstr))
38		return err
39	}
40	return nil
41}
42
43// Parse the given arguments using the LLVM command line parser.
44// See llvm::cl::ParseCommandLineOptions.
45func ParseCommandLineOptions(args []string, overview string) {
46	argstrs := make([]*C.char, len(args))
47	for i, arg := range args {
48		argstrs[i] = C.CString(arg)
49		defer C.free(unsafe.Pointer(argstrs[i]))
50	}
51	overviewstr := C.CString(overview)
52	defer C.free(unsafe.Pointer(overviewstr))
53	C.LLVMParseCommandLineOptions(C.int(len(args)), &argstrs[0], overviewstr)
54}
55