Changeset 623
- Timestamp:
- 08/05/08 11:13:19 (4 months ago)
- Files:
-
- trunk/rphp/compiler/CMakeLists.txt (modified) (1 diff)
- trunk/rphp/compiler/pDriver.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/rphp/compiler/CMakeLists.txt
r622 r623 3 3 4 4 # TODO: move this to a FindLLVM in cmake/modules 5 EXECUTE_PROCESS(COMMAND llvm-config --libs core jit bitreader bitwriter OUTPUT_VARIABLE LLVM_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE)5 EXECUTE_PROCESS(COMMAND llvm-config --libs core jit bitreader bitwriter linker interpreter OUTPUT_VARIABLE LLVM_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE) 6 6 EXECUTE_PROCESS(COMMAND llvm-config --includedir OUTPUT_VARIABLE LLVM_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE) 7 7 EXECUTE_PROCESS(COMMAND llvm-config --cppflags OUTPUT_VARIABLE LLVM_CPP_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE) trunk/rphp/compiler/pDriver.cpp
r622 r623 35 35 #include "llvm/Constants.h" 36 36 #include "llvm/Instructions.h" 37 #include "llvm/Support/MemoryBuffer.h" 38 #include "llvm/ModuleProvider.h" 39 #include "llvm/ExecutionEngine/JIT.h" 40 #include "llvm/ExecutionEngine/Interpreter.h" 41 #include "llvm/ExecutionEngine/GenericValue.h" 37 42 38 43 #include "parser/rphp_debug_visitor.h" … … 52 57 cout << "executing file: " << fileName << endl; 53 58 // TODO: determine file type, then run executeBC or executePHP 54 59 executeBC(fileName); 55 60 } 56 61 … … 59 64 */ 60 65 void pDriver::executeBC(string fileName) { 66 61 67 cout << "executing compiled bytecode: " << fileName << endl; 68 69 // Now we create the JIT. 70 string* errMsg = new string(); 71 llvm::MemoryBuffer* mb = llvm::MemoryBuffer::getFile(fileName.c_str(), errMsg); 72 if (errMsg->length()) { 73 cerr << "error loading file: " << fileName << endl; 74 delete errMsg; 75 return; 76 } 77 llvm::ModuleProvider* MP = llvm::getBitcodeModuleProvider(mb, errMsg); 78 if (errMsg->length()) { 79 cerr << "error parsing bitcode file: " << fileName << endl; 80 delete errMsg; 81 return; 82 } 83 84 // MP now owns mb and will delete 85 // errMsg isn't needed. 86 delete errMsg; 87 88 llvm::ExecutionEngine* EE = llvm::ExecutionEngine::create(MP, false); 89 90 // EE now owns MP 91 92 llvm::Function* rphpMain = MP->getModule()->getFunction("rphp_main"); 93 if (!rphpMain) { 94 cerr << "error: rphp_main symbol not found" << endl; 95 MP->getModule()->dump(); 96 delete EE; 97 return; 98 } 99 100 // Call the rphp_main function with no arguments: 101 std::vector<llvm::GenericValue> noargs; 102 llvm::GenericValue gv = EE->runFunction(rphpMain, noargs); 103 104 cout << "module ran, return value is: " << gv.IntVal.toStringSigned(10) << endl; 105 106 delete EE; 107 62 108 } 63 109 … … 123 169 // By passing a module as the last parameter to the Function constructor, 124 170 // it automatically gets appended to the Module. 125 llvm::Function *F = llvm::Function::Create(FT, llvm::Function::ExternalLinkage, " main", M);171 llvm::Function *F = llvm::Function::Create(FT, llvm::Function::ExternalLinkage, "rphp_main", M); 126 172 127 173 // Add a basic block to the function... again, it automatically inserts
