new world
[rubydium.git] / Project / Mumble.cpp
blob2dd78ddddb421a4283869956d30dcb0f3719ca6d
1 #define __STDC_LIMIT_MACROS
3 #include "Mumble.h"
5 #include "llvm/Module.h"
6 #include "llvm/ModuleProvider.h"
7 #include "llvm/Type.h"
8 #include "llvm/Assembly/Parser.h"
9 #include "llvm/Bitcode/ReaderWriter.h"
10 #include "llvm/CodeGen/LinkAllCodegenComponents.h"
11 #include "llvm/ExecutionEngine/JIT.h"
12 #include "llvm/ExecutionEngine/GenericValue.h"
13 #include "llvm/Support/ManagedStatic.h"
14 #include "llvm/Support/MemoryBuffer.h"
15 #include "llvm/System/Process.h"
16 #include <fstream>
17 #include <iostream>
19 using namespace llvm;
21 std::auto_ptr<Module> foobar(const char *boo) {
22 ParseError Err;
23 std::auto_ptr<Module> M(ParseAssemblyString(boo, 0, &Err));
24 if (M.get() == 0) {
25 cerr << ": " << Err.getMessage() << "\n";
27 return M;
33 std::ostream *Out = new std::ofstream("/Users/lypanov/llvmrb/foo.lli.bc", std::ios::out |
34 std::ios::trunc | std::ios::binary);
35 if (!Out->good()) {
36 cerr << ": error opening " << "!\n";
37 return 0;
39 WriteBitcodeToFile(M.get(), *Out);
41 std::string ErrorMsg;
42 ModuleProvider *MP = 0;
43 if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN("/Users/lypanov/llvmrb/foo.lli.bc", &ErrorMsg)) {
44 MP = getBitcodeModuleProvider(Buffer, &ErrorMsg);
45 if (!MP) {
46 delete Buffer;
52 const char* bah2(const char *boo) {
53 static ExecutionEngine *EE = 0;
55 std::auto_ptr<Module> M = foobar(boo);
57 if (!EE) {
58 EE = ExecutionEngine::create(M.get());
61 Function *Fn = M->getFunction("foo");
62 if (!Fn) {
63 std::cerr << "'foo' function not found in module.\n";
66 std::vector<GenericValue> args(1);
67 args[0].IntVal = APInt(64, 5);
69 GenericValue Result = EE->runFunction(Fn, args);
70 return Result.IntVal.toString(10, false).c_str();