irreader.go raw
1 //===- irreader.go - Bindings for irreader --------------------------------===//
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 irreader component.
10 //
11 //===----------------------------------------------------------------------===//
12
13 package llvm
14
15 /*
16 #include "llvm-c/Core.h"
17 #include "llvm-c/IRReader.h"
18 #include <stdlib.h>
19 */
20 import "C"
21
22 import (
23 "errors"
24 )
25
26 // ParseIR parses the textual IR given in the memory buffer and returns a new
27 // LLVM module in this context.
28 func (c *Context) ParseIR(buf MemoryBuffer) (Module, error) {
29 var m Module
30 var errmsg *C.char
31 if C.LLVMParseIRInContext(c.C, buf.C, &m.C, &errmsg) != 0 {
32 err := errors.New(C.GoString(errmsg))
33 C.LLVMDisposeMessage(errmsg)
34 return Module{}, err
35 }
36 return m, nil
37 }
38