1 #define __STDC_LIMIT_MACROS
5 #include "llvm/Module.h"
6 #include "llvm/ModuleProvider.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"
21 std::auto_ptr
<Module
> foobar(const char *boo
) {
23 std::auto_ptr
<Module
> M(ParseAssemblyString(boo
, 0, &Err
));
25 cerr
<< ": " << Err
.getMessage() << "\n";
33 std::ostream *Out = new std::ofstream("/Users/lypanov/llvmrb/foo.lli.bc", std::ios::out |
34 std::ios::trunc | std::ios::binary);
36 cerr << ": error opening " << "!\n";
39 WriteBitcodeToFile(M.get(), *Out);
42 ModuleProvider *MP = 0;
43 if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN("/Users/lypanov/llvmrb/foo.lli.bc", &ErrorMsg)) {
44 MP = getBitcodeModuleProvider(Buffer, &ErrorMsg);
52 const char* bah2(const char *boo
) {
53 static ExecutionEngine
*EE
= 0;
55 std::auto_ptr
<Module
> M
= foobar(boo
);
58 EE
= ExecutionEngine::create(M
.get());
61 Function
*Fn
= M
->getFunction("foo");
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();