Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "llvm/LLVMContext.h"
- #include "llvm/ExecutionEngine/GenericValue.h"
- #include "llvm/ExecutionEngine/ExecutionEngine.h"
- #include "llvm/Module.h"
- #include "llvm/ADT/StringRef.h"
- #include "llvm/Support/IRReader.h"
- #include "llvm/Support/MemoryBuffer.h"
- #include "llvm/Support/TargetSelect.h"
- @implementation AppDelegate
- - (void)
- applicationDidFinishLaunching: (NSNotification*) inNotification
- {
- llvm::InitializeNativeTarget();
- // Load the HelloWorld source…
- llvm::MemoryBuffer* progBuf = NULL;
- {
- NSURL* url = [[NSBundle mainBundle] URLForResource: @"HelloWorld" withExtension: @"llvm"];
- NSData* prog = [NSData dataWithContentsOfURL: url];
- if (prog == nil)
- {
- NSLog(@"Unable to open file '%@'", url.path);
- return;
- }
- llvm::StringRef sr((const char*) prog.bytes, prog.length);
- progBuf = llvm::MemoryBuffer::getMemBufferCopy(sr);
- }
- // Assemble it…
- llvm::LLVMContext& llvmCTX = llvm::getGlobalContext();
- llvm::SMDiagnostic smd;
- llvm::Module* mod = new llvm::Module("helloWorldModule", llvmCTX);
- llvm::ParseAssembly(progBuf, mod, smd, llvmCTX);
- NSLog(@"Parse: %d:%d %s\n%s", smd.getLineNo(), smd.getColumnNo(), smd.getMessage().c_str(), smd.getLineContents().c_str());
- llvm::Module::global_iterator giter = mod->getGlobalList().begin();
- for (; giter != mod->getGlobalList().end(); ++giter)
- {
- NSLog(@"Global!");
- }
- // Build an execution engine…
- llvm::EngineBuilder builder(mod);
- //builder.setEngineKind(llvm::EngineKind::Interpreter);
- llvm::ExecutionEngine* ee = builder.create();
- // ========= ee is always NULL :-(
- ee->runStaticConstructorsDestructors(false);
- llvm::Function* entryFunc = mod->getFunction("MyEntry");
- ee->getPointerToFunction(entryFunc);
- std::vector<llvm::GenericValue> args;
- ee->runFunction(entryFunc, args);
- ee->runStaticConstructorsDestructors(true);
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement