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