diff options
author | Ayke van Laethem <aykevanlaethem@gmail.com> | 2019-08-18 15:40:39 +0000 |
---|---|---|
committer | Ayke van Laethem <aykevanlaethem@gmail.com> | 2019-08-18 15:40:39 +0000 |
commit | 465f4e2c94aaf044beb4ecb3529ed8c2ed04fe73 (patch) | |
tree | cdcb22f63e1e2c8b2da189e3438ad276f73d3408 | |
parent | 19a71f6bdf2dddb10764939e7f0ec2b98dba76c9 (diff) | |
download | llvm-465f4e2c94aaf044beb4ecb3529ed8c2ed04fe73.tar.gz |
[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
-rw-r--r-- | llvm/bindings/go/llvm/irreader.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/bindings/go/llvm/irreader.go b/llvm/bindings/go/llvm/irreader.go new file mode 100644 index 000000000000..71064497a583 --- /dev/null +++ b/llvm/bindings/go/llvm/irreader.go @@ -0,0 +1,37 @@ +//===- irreader.go - Bindings for irreader --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines bindings for the irreader component. +// +//===----------------------------------------------------------------------===// + +package llvm + +/* +#include "llvm-c/IRReader.h" +#include <stdlib.h> +*/ +import "C" + +import ( + "errors" + "unsafe" +) + +// ParseIR parses the textual IR given in the memory buffer and returns a new +// LLVM module in this context. +func (c *Context) ParseIR(buf MemoryBuffer) (Module, error) { + var m Module + var errmsg *C.char + if C.LLVMParseIRInContext(c.C, buf.C, &m.C, &errmsg) != 0 { + err := errors.New(C.GoString(errmsg)) + C.free(unsafe.Pointer(errmsg)) + return Module{}, err + } + return m, nil +} |