Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
numba
GitHub Repository: numba/llvmlite
Path: blob/main/ffi/assembly.cpp
1154 views
1
#include "llvm/AsmParser/Parser.h"
2
#include "llvm/IR/LLVMContext.h"
3
#include "llvm/IR/Module.h"
4
#include "llvm/Support/SourceMgr.h"
5
#include "llvm/Support/raw_ostream.h"
6
7
#include "core.h"
8
#include "llvm-c/Core.h"
9
10
#include <cstdio>
11
#include <string>
12
13
extern "C" {
14
15
API_EXPORT(LLVMModuleRef)
16
LLVMPY_ParseAssembly(LLVMContextRef context, const char *ir,
17
const char **outmsg) {
18
using namespace llvm;
19
20
SMDiagnostic error;
21
22
Module *m = parseAssemblyString(ir, error, *unwrap(context)).release();
23
if (!m) {
24
// Error occurred
25
std::string osbuf;
26
raw_string_ostream os(osbuf);
27
error.print("", os);
28
os.flush();
29
*outmsg = LLVMPY_CreateString(os.str().c_str());
30
return NULL;
31
}
32
return wrap(m);
33
}
34
35
} // end extern "C"
36
37