Skip to content

Commit 465f4e2

Browse files
committed
[bindings/go] Add ParseIR
This commit adds a single method to the Context object to parse a textual IR file. This is useful for reading input IR in unit tests. Differential Revision: https://reviews.llvm.org/D66379 llvm-svn: 369210
1 parent 19a71f6 commit 465f4e2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

llvm/bindings/go/llvm/irreader.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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/IRReader.h"
17+
#include <stdlib.h>
18+
*/
19+
import "C"
20+
21+
import (
22+
"errors"
23+
"unsafe"
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.free(unsafe.Pointer(errmsg))
34+
return Module{}, err
35+
}
36+
return m, nil
37+
}

0 commit comments

Comments
 (0)