[llvm-branch-commits] [llvm-branch] r369210 - [bindings/go] Add ParseIR
Ayke van Laethem via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Aug 18 08:40:39 PDT 2019
Author: aykevl
Date: Sun Aug 18 08:40:39 2019
New Revision: 369210
URL: http://llvm.org/viewvc/llvm-project?rev=369210&view=rev
Log:
[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
Added:
llvm/branches/release_80/bindings/go/llvm/irreader.go
Added: llvm/branches/release_80/bindings/go/llvm/irreader.go
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_80/bindings/go/llvm/irreader.go?rev=369210&view=auto
==============================================================================
--- llvm/branches/release_80/bindings/go/llvm/irreader.go (added)
+++ llvm/branches/release_80/bindings/go/llvm/irreader.go Sun Aug 18 08:40:39 2019
@@ -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
+}
More information about the llvm-branch-commits
mailing list