Changeset 679
- Timestamp:
- 10/07/08 09:35:46 (2 months ago)
- Files:
-
- trunk/rphp/README (modified) (1 diff)
- trunk/rphp/cmake/modules/FindLLVM.cmake (modified) (1 diff)
- trunk/rphp/compiler/CMakeLists.txt (modified) (1 diff)
- trunk/rphp/compiler/pDriver.cpp (modified) (2 diffs)
- trunk/rphp/compiler/pGenSupport.cpp (modified) (2 diffs)
- trunk/rphp/compiler/pGenSupport.h (modified) (1 diff)
- trunk/rphp/compiler/pGenerator.cpp (modified) (6 diffs)
- trunk/rphp/compiler/pGenerator.h (modified) (3 diffs)
- trunk/rphp/compiler/pIRHelper.cpp (moved) (moved from trunk/rphp/compiler/pIRTypes.cpp) (3 diffs, 1 prop)
- trunk/rphp/compiler/pIRHelper.h (moved) (moved from trunk/rphp/compiler/pIRTypes.h) (3 diffs, 1 prop)
- trunk/rphp/compiler/pStandAloneTargets.cpp (modified) (4 diffs)
- trunk/rphp/compiler/pStandAloneTargets.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/rphp/README
r611 r679 1 1 2 2 Roadsend PHP 3 ------------ 4 5 This source tree is a C++ rewrite of the original Roadsend PHP written in Bigloo scheme. 6 7 To compile, it requires a recent C++ compiler, Boost, and LLVM. For more information, see 8 http://code.roadsend.com/pcc/ 9 trunk/rphp/cmake/modules/FindLLVM.cmake
r676 r679 47 47 exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --ldflags OUTPUT_VARIABLE LLVM_LDFLAGS ) 48 48 #MESSAGE(STATUS "LLVM LD flags: " ${LLVM_LDFLAGS}) 49 exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --libs core bitreader bitwriter OUTPUT_VARIABLE LLVM_LIBS_CORE )49 exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --libs core bitreader bitwriter linker OUTPUT_VARIABLE LLVM_LIBS_CORE ) 50 50 #MESSAGE(STATUS "LLVM core libs: " ${LLVM_LIBS_CORE}) 51 51 trunk/rphp/compiler/CMakeLists.txt
r675 r679 67 67 pStandAloneTargets.cpp 68 68 pModule.cpp 69 pIR Types.cpp69 pIRHelper.cpp 70 70 ) 71 71 trunk/rphp/compiler/pDriver.cpp
r672 r679 26 26 #include <llvm/ModuleProvider.h> 27 27 #include <llvm/Support/MemoryBuffer.h> 28 #include <llvm/ModuleProvider.h>29 28 #include <llvm/ExecutionEngine/JIT.h> 30 29 #include <llvm/ExecutionEngine/Interpreter.h> … … 87 86 bool pDriver::executeBC(string fileName) { 88 87 89 // Now we create the JIT.90 88 string errMsg; 91 89 llvm::MemoryBuffer* mb = llvm::MemoryBuffer::getFile(fileName.c_str(), &errMsg); trunk/rphp/compiler/pGenSupport.cpp
r672 r679 19 19 20 20 #include <llvm/Module.h> 21 #include <llvm/ModuleProvider.h> 22 #include <llvm/Support/MemoryBuffer.h> 21 23 #include <llvm/Bitcode/ReaderWriter.h> 24 25 #include <iostream> 22 26 #include <fstream> 23 27 … … 51 55 52 56 57 llvm::Module* pGenSupport::readBitcode(std::string fileName) { 58 59 std::string errMsg; 60 llvm::MemoryBuffer* mb = llvm::MemoryBuffer::getFile(fileName.c_str(), &errMsg); 61 if (errMsg.length()) { 62 // TODO: errors 63 std::cerr << "error loading runtime IR file [" << fileName << "]: " << errMsg << std::endl; 64 exit(1); 65 } 66 67 llvm::ModuleProvider* mp = llvm::getBitcodeModuleProvider(mb, &errMsg); 68 if (errMsg.length()) { 69 // TODO: errors 70 std::cerr << "error parsing bitcode file [" << fileName << "]: " << errMsg << std::endl; 71 exit(1); 72 } 73 74 llvm::Module* mod = mp->getModule(); 75 76 // caller takes control of module 77 mp->releaseModule(); 78 delete mp; 79 80 return mod; 81 82 } 83 84 llvm::Module* pGenSupport::getRuntimeIR() { 85 86 // TODO: ouch! 87 return readBitcode("/home/weyrick/workspace/rphp/runtime-ir/irRuntime.ir"); 88 89 } 90 91 53 92 } // namespace 54 93 trunk/rphp/compiler/pGenSupport.h
r672 r679 34 34 static std::string mangleModuleName(std::string moduleName); 35 35 static bool writeBitcode(llvm::Module* m, std::string outFile); 36 static llvm::Module* readBitcode(std::string fileName); 37 static llvm::Module* getRuntimeIR(); 36 38 37 39 }; trunk/rphp/compiler/pGenerator.cpp
r674 r679 27 27 #include <llvm/Instructions.h> 28 28 29 #include <llvm/Linker.h> 30 29 31 #include "pGenerator.h" 30 32 #include "pCompileTarget.h" 31 #include "pIR Types.h"33 #include "pIRHelper.h" 32 34 #include "pGenSupport.h" 33 35 … … 35 37 36 38 namespace rphp { 39 40 pGenerator::pGenerator(llvm::Module* m, pCompileTarget* t): llvmModule(m), target(t), IRHelper(0) { 41 42 loadAndLinkRuntimeIR(); 43 createEntryPoint(); 44 45 } 46 47 pGenerator::~pGenerator(void) { 48 49 delete IRHelper; 50 51 } 52 53 void pGenerator::loadAndLinkRuntimeIR(void) { 54 55 std::string errMsg; 56 Module* irMod = pGenSupport::getRuntimeIR(); 57 58 // Linker will take ownership of irMod 59 60 // here we link the irRuntime.ir with our clean module so it already includes 61 // definitions of types and functions we need for code generation 62 Linker l(llvmModule->getModuleIdentifier()+"_link", llvmModule); 63 l.LinkInModule(irMod, &errMsg); 64 if (errMsg.length()) { 65 // TODO: errors 66 std::cerr << "error linking in runtime ir: " << errMsg << std::endl; 67 exit(1); 68 } 69 70 // take ownership of module so it's not freed 71 l.releaseModule(); 72 73 // IRHelper knows how to pull types out of the composite module 74 IRHelper = new pIRHelper(llvmModule); 75 76 } 37 77 38 78 void pGenerator::createEntryPoint(void) { … … 42 82 43 83 // entry function 44 Function *initFun = Function::Create(IR Types.moduleEntryFunType(),84 Function *initFun = Function::Create(IRHelper->moduleEntryFunType(), 45 85 Function::ExternalLinkage, 46 86 entryFunctionName, … … 59 99 Function *initFun = llvmModule->getFunction(entryFunctionName); 60 100 initFun->getEntryBlock().getInstList().push_back(ReturnInst::Create()); 101 // DEBUG 102 verifyModule(*llvmModule); 61 103 } 62 104 63 105 void pGenerator::visit_literalBString(AST::literalBString* n) { 64 106 65 assert(n->getVal().size() > 0); 66 67 ArrayType* stringLiteralType = ArrayType::get(IntegerType::get(8), n->getVal().size()+1); 68 69 GlobalVariable* globalStr = new GlobalVariable( 107 // assert(n->getVal().size() > 0); 108 // 109 // ArrayType* stringLiteralType = ArrayType::get(IntegerType::get(8), n->getVal().size()+1); 110 // 111 // GlobalVariable* globalStr = new GlobalVariable( 112 // /*Type=*/stringLiteralType, 113 // /*isConstant=*/true, 114 // /*Linkage=*/GlobalValue::InternalLinkage, 115 // /*Initializer=*/0, // has initializer, specified below 116 // /*Name=*/".pBString", 117 // llvmModule); 118 // 119 // Constant* const_array_7 = ConstantArray::get(n->getVal().c_str(), true); 120 // std::vector<Constant*> const_ptr_8_indices; 121 // Constant* const_int32_9 = Constant::getNullValue(IntegerType::get(32)); 122 // const_ptr_8_indices.push_back(const_int32_9); 123 // const_ptr_8_indices.push_back(const_int32_9); 124 // Constant* litStringRef = ConstantExpr::getGetElementPtr(globalStr, &const_ptr_8_indices[0], const_ptr_8_indices.size() ); 125 // 126 // // Global Variable Definitions 127 // globalStr->setInitializer(const_array_7); 128 129 // turn it into a pVar and push 130 // valueStack.push(emitVarCreate_pBString(litStringRef)); 131 132 ArrayType* stringLiteralType = ArrayType::get(IntegerType::get(8), n->val.size()+1); 133 134 GlobalVariable* gvar_array__str = new GlobalVariable( 70 135 /*Type=*/stringLiteralType, 71 136 /*isConstant=*/true, 72 137 /*Linkage=*/GlobalValue::InternalLinkage, 73 138 /*Initializer=*/0, // has initializer, specified below 74 /*Name=*/". pBString",139 /*Name=*/".str", 75 140 llvmModule); 76 141 77 Constant* const_array_7 = ConstantArray::get(n->getVal().c_str(), true); 142 // Constant Definitions 143 Constant* const_array_7 = ConstantArray::get(n->val.c_str(), true); 78 144 std::vector<Constant*> const_ptr_8_indices; 79 145 Constant* const_int32_9 = Constant::getNullValue(IntegerType::get(32)); 80 146 const_ptr_8_indices.push_back(const_int32_9); 81 147 const_ptr_8_indices.push_back(const_int32_9); 82 Constant* litStringRef = ConstantExpr::getGetElementPtr(globalStr, &const_ptr_8_indices[0], const_ptr_8_indices.size() );83 148 Constant* strPtr = ConstantExpr::getGetElementPtr(gvar_array__str, &const_ptr_8_indices[0], const_ptr_8_indices.size() ); 149 84 150 // Global Variable Definitions 85 globalStr->setInitializer(const_array_7); 86 87 // turn it into a pVar and push 88 valueStack.push(emitVarCreate_pBString(litStringRef)); 151 gvar_array__str->setInitializer(const_array_7); 152 153 // allocate tmp pVar for return value 154 Value* pVarTmp = currentBlock.CreateAlloca(IRHelper->pVarType(), 0, "pVarTmp"); 155 Function* constructor = llvmModule->getFunction("_ZN4rphp4pVarC1Ev"); 156 assert(constructor != NULL); 157 currentBlock.CreateCall(constructor, pVarTmp); 158 159 // convert cstr to pbstring 160 Function* f = llvmModule->getFunction("rphp_make_pVar_from_cstr"); 161 assert(f != NULL); 162 currentBlock.CreateCall2(f, pVarTmp, strPtr); 163 164 // push to stack 165 valueStack.push(pVarTmp); 89 166 90 167 } … … 92 169 void pGenerator::visit_literalInt(AST::literalInt* n) { 93 170 94 GlobalVariable* globalInt = new GlobalVariable( 95 /*Type=*/IntegerType::get(32), 96 /*isConstant=*/false, 171 // GlobalVariable* globalInt = new GlobalVariable( 172 // /*Type=*/IntegerType::get(32), 173 // /*isConstant=*/false, 174 // /*Linkage=*/GlobalValue::InternalLinkage, 175 // /*Initializer=*/0, // has initializer, specified below 176 // /*Name=*/".pInt", 177 // llvmModule); 178 // 179 // // TODO: others bases besides 10 180 // ConstantInt* const_int32 = ConstantInt::get(APInt(32, n->getVal(), 10)); 181 // 182 // globalInt->setInitializer(const_int32); 183 // 184 // valueStack.push(emitVarCreate_pInt(globalInt)); 185 186 } 187 188 void pGenerator::visit_inlineHtml(AST::inlineHtml* n) { 189 190 ArrayType* stringLiteralType = ArrayType::get(IntegerType::get(8), n->val.size()+1); 191 192 GlobalVariable* gvar_array__str = new GlobalVariable( 193 /*Type=*/stringLiteralType, 194 /*isConstant=*/true, 97 195 /*Linkage=*/GlobalValue::InternalLinkage, 98 196 /*Initializer=*/0, // has initializer, specified below 99 /*Name=*/". pInt",197 /*Name=*/".str", 100 198 llvmModule); 101 199 102 // TODO: others bases besides 10 103 ConstantInt* const_int32 = ConstantInt::get(APInt(32, n->getVal(), 10)); 104 105 globalInt->setInitializer(const_int32); 106 107 valueStack.push(emitVarCreate_pInt(globalInt)); 108 109 } 110 111 void pGenerator::visit_inlineHtml(AST::inlineHtml* n) { 112 113 // generate the constant like a literalBString 114 visit_literalBString(static_cast<AST::literalBString*>(n)); 115 116 // print it like an echo. 117 emitEchoLiteralString(); 200 // Constant Definitions 201 Constant* const_array_7 = ConstantArray::get(n->val.c_str(), true); 202 std::vector<Constant*> const_ptr_8_indices; 203 Constant* const_int32_9 = Constant::getNullValue(IntegerType::get(32)); 204 const_ptr_8_indices.push_back(const_int32_9); 205 const_ptr_8_indices.push_back(const_int32_9); 206 Constant* strPtr = ConstantExpr::getGetElementPtr(gvar_array__str, &const_ptr_8_indices[0], const_ptr_8_indices.size() ); 207 208 // Global Variable Definitions 209 gvar_array__str->setInitializer(const_array_7); 210 211 Function *f = llvmModule->getFunction("rphp_print_cstr"); 212 assert(f != NULL); 213 214 currentBlock.CreateCall2(f, runtimeEngine, strPtr); 118 215 119 216 } … … 121 218 void pGenerator::visit_echoStmt(AST::echoStmt* n) { 122 219 123 // codegen our rVal expression124 220 visit(n->getRVal()); 125 emitEchoLiteralString();126 127 }128 129 // assumes literal is on top of stack130 void pGenerator::emitEchoLiteralString(void) {131 132 221 Value* rVal = valueStack.back(); 133 222 valueStack.pop(); 134 223 135 // argument sig for print function 136 std::vector<const Type*> printSig; 137 printSig.push_back(IRTypes.runtimeEngineType()); 138 printSig.push_back(IRTypes.pVarPointerType()); 139 140 // print function type 141 FunctionType *printFuncType = FunctionType::get(Type::VoidTy, printSig, false); 142 143 // print function 144 Constant *printFunc = llvmModule->getOrInsertFunction("rphp_print_pvar", printFuncType); 145 146 currentBlock.CreateCall2(printFunc, runtimeEngine, rVal); 147 148 } 224 Function *f = llvmModule->getFunction("rphp_print_pVar"); 225 assert(f != NULL); 226 227 currentBlock.CreateCall2(f, runtimeEngine, rVal); 228 229 } 230 231 // assumes literal is on top of stack 232 // void pGenerator::emitEchoLiteralString(void) { 233 // 234 // Value* rVal = valueStack.back(); 235 // valueStack.pop(); 236 // 237 // // argument sig for print function 238 // std::vector<const Type*> printSig; 239 // printSig.push_back(IRHelper->runtimeEngineType()); 240 // printSig.push_back(IRHelper->pVarPointerType()); 241 // 242 // // print function type 243 // FunctionType *printFuncType = FunctionType::get(Type::VoidTy, printSig, false); 244 // 245 // // print function 246 // //Constant *printFunc = llvmModule->getOrInsertFunction("rphp_print_pvar", printFuncType); 247 // 248 // //currentBlock.CreateCall2(printFunc, runtimeEngine, rVal); 249 // 250 // } 149 251 150 252 // allocate a pVar on the stack in the current block, return pVar* 151 llvm::Value* emitVarCreate() {152 153 /*154 AllocaInst* pVar_p = new AllocaInst(IRTypes.pVarType(), "pVarBString", currentBlock.getInsertBlock());155 pVar_p->setAlignment(4);156 emitVarConstruct(pVar_p);157 158 return pVar_p;159 */160 161 }253 // llvm::Value* emitVarCreate() { 254 // 255 // /* 256 // AllocaInst* pVar_p = new AllocaInst(IRHelper->pVarType(), "pVarBString", currentBlock.getInsertBlock()); 257 // pVar_p->setAlignment(4); 258 // emitVarConstruct(pVar_p); 259 // 260 // return pVar_p; 261 // */ 262 // 263 // } 162 264 163 265 // create a new pVar on the stack and assign a pBString to it 164 266 // return pVar* 165 llvm::Value* pGenerator::emitVarCreate_pBString(llvm::Value*) {166 167 /*168 Value* pVar_p = emitVarCreate();169 rphp_create_pVar_pBString170 return pVar_p;171 172 // call runtime to create pVar from char*173 // TODO: inline this174 std::vector<const Type*> fSig;175 printSig.push_back(IRTypes.charPointerType(), 0);176 FunctionType *fFuncType = FunctionType::get(IRTypes.pVarType(), fSig, false);177 Constant *Func = llvmModule->getOrInsertFunction("rphp_create_pVar_pBString", fFuncType);178 179 return currentBlock.CreateCall2(printFunc, runtimeEngine, rVal);180 */181 182 }267 // llvm::Value* pGenerator::emitVarCreate_pBString(llvm::Value*) { 268 // 269 // /* 270 // Value* pVar_p = emitVarCreate(); 271 // rphp_create_pVar_pBString 272 // return pVar_p; 273 // 274 // // call runtime to create pVar from char* 275 // // TODO: inline this 276 // std::vector<const Type*> fSig; 277 // printSig.push_back(IRHelper->charPointerType(), 0); 278 // FunctionType *fFuncType = FunctionType::get(IRHelper->pVarType(), fSig, false); 279 // Constant *Func = llvmModule->getOrInsertFunction("rphp_create_pVar_pBString", fFuncType); 280 // 281 // return currentBlock.CreateCall2(printFunc, runtimeEngine, rVal); 282 // */ 283 // 284 // } 183 285 184 286 // create a new pVar on the stack and assign a pBString to it 185 287 // return pVar* 186 llvm::Value* pGenerator::emitVarCreate_pInt(llvm::Value*) {187 188 189 }190 191 // call pVar::pVar(pVar*)192 void pGenerator::emitVarConstruct(llvm::Value* v) {193 194 Function* pVarConstructFun = Function::Create(195 /*Type=*/IRTypes.pVarBaseFunType(),196 /*Linkage=*/GlobalValue::LinkOnceLinkage ,197 /*Name=*/"_ZN4rphp4pVarC1Ev", llvmModule);198 199 currentBlock.CreateCall(pVarConstructFun, v);200 201 }202 203 204 // call pVar::~pVar(pVar*)205 void pGenerator::emitVarDestruct(llvm::Value* v) {206 207 Function* pVarDestructFun = Function::Create(208 /*Type=*/IRTypes.pVarBaseFunType(),209 /*Linkage=*/GlobalValue::LinkOnceLinkage ,210 /*Name=*/"_ZN4rphp4pVarD1Ev", llvmModule);211 212 currentBlock.CreateCall(pVarDestructFun, v);213 214 }288 // llvm::Value* pGenerator::emitVarCreate_pInt(llvm::Value*) { 289 // 290 // 291 // } 292 293 // // call pVar::pVar(pVar*) 294 // void pGenerator::emitVarConstruct(llvm::Value* v) { 295 // 296 // Function* pVarConstructFun = Function::Create( 297 // /*Type=*/IRHelper->pVarBaseFunType(), 298 // /*Linkage=*/GlobalValue::LinkOnceLinkage , 299 // /*Name=*/"_ZN4rphp4pVarC1Ev", llvmModule); 300 // 301 // currentBlock.CreateCall(pVarConstructFun, v); 302 // 303 // } 304 // 305 // 306 // // call pVar::~pVar(pVar*) 307 // void pGenerator::emitVarDestruct(llvm::Value* v) { 308 // 309 // Function* pVarDestructFun = Function::Create( 310 // /*Type=*/IRHelper->pVarBaseFunType(), 311 // /*Linkage=*/GlobalValue::LinkOnceLinkage , 312 // /*Name=*/"_ZN4rphp4pVarD1Ev", llvmModule); 313 // 314 // currentBlock.CreateCall(pVarDestructFun, v); 315 // 316 // } 215 317 216 318 trunk/rphp/compiler/pGenerator.h
r674 r679 25 25 #include <llvm/Support/IRBuilder.h> 26 26 #include "pASTVisitors.h" 27 #include "pIR Types.h"27 #include "pIRHelper.h" 28 28 29 29 namespace llvm { … … 38 38 class pGenerator: public AST::defaultVisitor { 39 39 40 llvm::Module* llvmModule; 41 pCompileTarget* target; 42 pIRTypes IRTypes; 40 private: 41 llvm::Module* llvmModule; // don't own 42 pCompileTarget* target; // don't own 43 pIRHelper* IRHelper; // own 43 44 44 45 std::string entryFunctionName; 45 46 46 47 llvm::IRBuilder currentBlock; 47 llvm::Value* runtimeEngine; 48 llvm::Value* runtimeEngine; // don't own 48 49 std::queue<llvm::Value*> valueStack; 49 50 51 private: 52 void loadAndLinkRuntimeIR(void); 50 53 void createEntryPoint(void); 51 54 52 void emitEchoLiteralString(void);55 //void emitEchoLiteralString(void); 53 56 54 57 // pVar 58 /* 55 59 llvm::Value* emitVarCreate(void); 56 60 llvm::Value* emitVarCreate_pBString(llvm::Value*); … … 59 63 void emitVarConstruct(llvm::Value*); 60 64 void emitVarDestruct(llvm::Value*); 61 65 */ 66 62 67 public: 63 68 64 pGenerator(llvm::Module* m, pCompileTarget* t): llvmModule(m), target(t) { 65 createEntryPoint(); 66 } 67 68 // destructor: we don't own any of our member objects 69 pGenerator(llvm::Module* m, pCompileTarget* t); 70 ~pGenerator(void); 69 71 70 72 void finalize(void); trunk/rphp/compiler/pIRHelper.cpp
- Property svn:mergeinfo set
r674 r679 18 18 */ 19 19 20 #include <llvm/Module.h> 20 21 #include <llvm/DerivedTypes.h> 21 #include "pIRTypes.h" 22 23 #include <iostream> 24 #include <string> 25 26 #include "pIRHelper.h" 22 27 23 28 using namespace llvm; … … 25 30 namespace rphp { 26 31 27 Type* pIR Types::runtimeEngineType() {28 return PointerType::get( Type::Int8Ty,0);32 Type* pIRHelper::runtimeEngineType() { 33 return PointerType::get(mod->getTypeByName("struct.rphp::pRuntimeEngine"), 0); 29 34 } 30 35 31 Type* pIRTypes::pVarPointerType() { 32 33 return PointerType::get(pVarType(), 0); 34 36 Type* pIRHelper::pVarPointerType() { 37 return PointerType::get(mod->getTypeByName("struct.rphp::pVar"), 0); 35 38 } 36 39 37 Type* pIRTypes::pVarType() { 38 39 std::vector<const Type*>StructTy_struct_boost__align__a4_fields; 40 ArrayType* ArrayTy_1 = ArrayType::get(IntegerType::get(32), 1); 41 42 StructTy_struct_boost__align__a4_fields.push_back(ArrayTy_1); 43 StructType* StructTy_struct_boost__align__a4 = StructType::get(StructTy_struct_boost__align__a4_fields, /*isPacked=*/true); 44 //mod->addTypeName("struct.boost::align::a4", StructTy_struct_boost__align__a4); 45 46 std::vector<const Type*>StructTy_struct_boost__aligned_storage_8u_4u__fields; 47 std::vector<const Type*>StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u__fields; 48 std::vector<const Type*>StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u___data_t_fields; 49 ArrayType* ArrayTy_2 = ArrayType::get(IntegerType::get(8), 8); 50 51 StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u___data_t_fields.push_back(ArrayTy_2); 52 StructType* StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u___data_t = StructType::get(StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u___data_t_fields, /*isPacked=*/false); 53 //mod->addTypeName("struct.boost::detail::aligned_storage::aligned_storage_imp<8u,4u>::data_t", StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u___data_t); 54 55 StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u__fields.push_back(StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u___data_t); 56 StructType* StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u_ = StructType::get(StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u__fields, /*isPacked=*/true); 57 //mod->addTypeName("struct.boost::detail::aligned_storage::aligned_storage_imp<8u,4u>", StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u_); 58 59 StructTy_struct_boost__aligned_storage_8u_4u__fields.push_back(StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u_); 60 StructType* StructTy_struct_boost__aligned_storage_8u_4u_ = StructType::get(StructTy_struct_boost__aligned_storage_8u_4u__fields, /*isPacked=*/true); 61 //mod->addTypeName("struct.boost::aligned_storage<8u,4u>", StructTy_struct_boost__aligned_storage_8u_4u_); 62 63 //mod->addTypeName("struct.boost::detail::aligned_storage::aligned_storage_imp<8u,4u>", StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u_); 64 //mod->addTypeName("struct.boost::detail::aligned_storage::aligned_storage_imp<8u,4u>::data_t", StructTy_struct_boost__detail__aligned_storage__aligned_storage_imp_8u_4u___data_t); 65 66 std::vector<const Type*> StructTy_struct_boost__shared_ptr_rphp__pVar__fields; 67 std::vector<const Type*> StructTy_struct_rphp__pVar_fields; 68 69 std::vector<const Type*> variant_fields; 70 variant_fields.push_back(IntegerType::get(32)); // which 71 variant_fields.push_back(StructTy_struct_boost__aligned_storage_8u_4u_); // data 72 73 StructType* variant_struct = StructType::get(variant_fields, /*isPacked=*/true); 74 //mod->addTypeName("struct.variant", variant_struct); 75 76 StructTy_struct_rphp__pVar_fields.push_back(variant_struct); 77 StructType* StructTy_struct_rphp__pVar = StructType::get(StructTy_struct_rphp__pVar_fields, /*isPacked=*/true); 78 //mod->addTypeName("struct.pVar", StructTy_struct_rphp__pVar); 79 80 return StructTy_struct_rphp__pVar; 81 40 const Type* pIRHelper::pVarType() { 41 return mod->getTypeByName("struct.rphp::pVar"); 82 42 } 83 43 84 44 // void (*)(pVar*) 85 FunctionType* pIR Types::pVarBaseFunType() {45 FunctionType* pIRHelper::pVarBaseFunType() { 86 46 87 47 std::vector<const Type*>FuncTy_52_args; … … 96 56 } 97 57 98 FunctionType* pIR Types::moduleEntryFunType() {58 FunctionType* pIRHelper::moduleEntryFunType() { 99 59 100 60 if (moduleEntryFunTypeC) trunk/rphp/compiler/pIRHelper.h
- Property svn:mergeinfo set
r674 r679 18 18 */ 19 19 20 #ifndef RPHP_PIR TYPES_H_21 #define RPHP_PIR TYPES_H_20 #ifndef RPHP_PIRHELPER_H_ 21 #define RPHP_PIRHELPER_H_ 22 22 23 23 namespace llvm { 24 24 class FunctionType; 25 25 class Type; 26 class Module; 26 27 } 27 28 28 29 namespace rphp { 29 30 30 class pIR Types{31 class pIRHelper { 31 32 32 33 llvm::FunctionType* moduleEntryFunTypeC; 34 llvm::Module* mod; 33 35 34 36 public: 35 37 36 pIR Types(void): moduleEntryFunTypeC(0) { }38 pIRHelper(llvm::Module* m): moduleEntryFunTypeC(0), mod(m) { } 37 39 38 40 // pointer to the runtime engine … … 43 45 44 46 llvm::FunctionType* pVarBaseFunType(); 45 llvm::Type* pVarType();47 const llvm::Type* pVarType(); 46 48 llvm::Type* pVarPointerType(); 47 49 … … 51 53 } // namespace 52 54 53 #endif /* RPHP_PIR TYPES_H_ */55 #endif /* RPHP_PIRHELPER_H_ */ trunk/rphp/compiler/pStandAloneTargets.cpp
r670 r679 52 52 // ** STARTUP ** 53 53 // startup function type 54 FunctionType *runtimeStartupFuncType = FunctionType::get(IR Types.runtimeEngineType(), std::vector<const Type*>(), false);54 FunctionType *runtimeStartupFuncType = FunctionType::get(IRHelper->runtimeEngineType(), std::vector<const Type*>(), false); 55 55 // startup function 56 56 Function *runtimeStartupFunc = Function::Create(runtimeStartupFuncType, … … 63 63 // ** entry function call ** 64 64 std::vector<const Type*> printSig; 65 printSig.push_back(IR Types.runtimeEngineType());66 Function *entryFunc = Function::Create(IR Types.moduleEntryFunType(),65 printSig.push_back(IRHelper->runtimeEngineType()); 66 Function *entryFunc = Function::Create(IRHelper->moduleEntryFunType(), 67 67 Function::ExternalLinkage, 68 68 pGenSupport::mangleModuleName(mainFile), … … 75 75 // ** SHUTDOWN ** 76 76 // argument sig for shutdown function 77 std::vector<const Type*> engineSig(1, IR Types.runtimeEngineType());77 std::vector<const Type*> engineSig(1, IRHelper->runtimeEngineType()); 78 78 // shutdown function type 79 79 FunctionType *runtimeDeleteFuncType = FunctionType::get(Type::VoidTy, engineSig, false); … … 132 132 } 133 133 args.push_back("-native"); 134 args.push_back("-O4"); 134 // TODO: opt flags -- full debug for now 135 args.push_back("-disable-opt"); 136 args.push_back("-verify-each"); 137 args.push_back("-v"); 138 // 135 139 args.push_back("-lrphp-runtime"); 136 140 args.push_back("-o"); trunk/rphp/compiler/pStandAloneTargets.h
r665 r679 21 21 #define RPHP_PSTANDALONETARGETS_H_ 22 22 23 #include "pIR Types.h"23 #include "pIRHelper.h" 24 24 #include "pLinkTarget.h" 25 #include "pGenSupport.h" 25 26 26 27 namespace rphp { … … 32 33 protected: 33 34 std::string mainFile; 34 pIR Types IRTypes;35 pIRHelper* IRHelper; 35 36 36 37 llvm::Module* createStubModule(void); 37 38 38 39 public: 39 pStandAloneTarget(const std::string& outName, const std::string& mainName): mainFile(mainName), pLinkTarget(outName) { } 40 pStandAloneTarget(const std::string& outName, const std::string& mainName): mainFile(mainName), pLinkTarget(outName) { 41 IRHelper = new pIRHelper(pGenSupport::getRuntimeIR()); 42 } 43 44 ~pStandAloneTarget(void) { 45 delete IRHelper; 46 } 40 47 41 48 virtual void execute(void);
