irreader.go raw

   1  //go:build !purego
   2  
   3  //===- irreader.go - Bindings for irreader --------------------------------===//
   4  //
   5  // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
   6  // See https://llvm.org/LICENSE.txt for license information.
   7  // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
   8  //
   9  //===----------------------------------------------------------------------===//
  10  //
  11  // This file defines bindings for the irreader component.
  12  //
  13  //===----------------------------------------------------------------------===//
  14  
  15  package llvm
  16  
  17  /*
  18  #include "llvm-c/Core.h"
  19  #include "llvm-c/IRReader.h"
  20  #include <stdlib.h>
  21  */
  22  import "C"
  23  
  24  import (
  25  	"errors"
  26  )
  27  
  28  // ParseIR parses the textual IR given in the memory buffer and returns a new
  29  // LLVM module in this context.
  30  func (c *Context) ParseIR(buf MemoryBuffer) (Module, error) {
  31  	var m Module
  32  	var errmsg *C.char
  33  	if C.LLVMParseIRInContext(c.C, buf.C, &m.C, &errmsg) != 0 {
  34  		err := errors.New(C.GoString(errmsg))
  35  		C.LLVMDisposeMessage(errmsg)
  36  		return Module{}, err
  37  	}
  38  	return m, nil
  39  }
  40