llvm.org GIT mirror llvm / c6099db
[llvm-c] Expose IRReader interface Original patch by Chris Wailes git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194137 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Zotov 6 years ago
2 changed file(s) with 72 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 /*===-- llvm-c/IRReader.h - IR Reader C Interface -----------------*- C -*-===*\
1 |* *|
2 |* The LLVM Compiler Infrastructure *|
3 |* *|
4 |* This file is distributed under the University of Illinois Open Source *|
5 |* License. See LICENSE.TXT for details. *|
6 |* *|
7 |*===----------------------------------------------------------------------===*|
8 |* *|
9 |* This file defines the C interface to the IR Reader. *|
10 |* *|
11 \*===----------------------------------------------------------------------===*/
12
13 #ifndef LLVM_C_IRREADER_H
14 #define LLVM_C_IRREADER_H
15
16 #include "llvm-c/Core.h"
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /**
23 * Read LLVM IR from a memory buffer and convert it into an in-memory Module
24 * object. Returns 0 on success.
25 * Optionally returns a human-readable description of any errors that
26 * occured during parsing IR. OutMessage must be disposed with
27 * LLVMDisposeMessage.
28 *
29 * @see llvm::ParseIR()
30 */
31 LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
32 LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
33 char **OutMessage);
34
35 #ifdef __cplusplus
36 }
37 #endif
38
39 #endif
1010 #include "llvm/ADT/OwningPtr.h"
1111 #include "llvm/Assembly/Parser.h"
1212 #include "llvm/Bitcode/ReaderWriter.h"
13 #include "llvm/IR/LLVMContext.h"
14 #include "llvm/IR/Module.h"
1315 #include "llvm/Support/MemoryBuffer.h"
1416 #include "llvm/Support/SourceMgr.h"
1517 #include "llvm/Support/system_error.h"
1618 #include "llvm/Support/Timer.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include "llvm-c/Core.h"
21 #include "llvm-c/IRReader.h"
1722
1823 using namespace llvm;
1924
8691
8792 return ParseIR(File.take(), Err, Context);
8893 }
94
95 //===----------------------------------------------------------------------===//
96 // C API.
97 //===----------------------------------------------------------------------===//
98
99 LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
100 LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
101 char **OutMessage) {
102 SMDiagnostic Diag;
103
104 *OutM = wrap(ParseIR(unwrap(MemBuf), Diag, *unwrap(ContextRef)));
105
106 if(!*OutM) {
107 if (OutMessage) {
108 std::string buf;
109 raw_string_ostream os(buf);
110
111 Diag.print(NULL, os, false);
112 os.flush();
113
114 *OutMessage = strdup(buf.c_str());
115 }
116 return 1;
117 }
118
119 return 0;
120 }