[PATCH] D66379: [bindings/go] Add ParseIR
Ayke via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 17 09:13:25 PDT 2019
aykevl created this revision.
aykevl added reviewers: whitequark, pcc.
Herald added a project: LLVM.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D66379
Files:
llvm/bindings/go/llvm/irreader.go
Index: llvm/bindings/go/llvm/irreader.go
===================================================================
--- /dev/null
+++ 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
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66379.215743.patch
Type: text/x-patch
Size: 1226 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190817/1f942386/attachment.bin>
More information about the llvm-commits
mailing list