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