Changeset 679

Show
Ignore:
Timestamp:
10/07/08 09:35:46 (2 months ago)
Author:
weyrick
Message:

adapt the generator to use the irRuntime interface

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/rphp/README

    r611 r679  
    11 
    22Roadsend PHP 
     3------------ 
     4 
     5This source tree is a C++ rewrite of the original Roadsend PHP written in Bigloo scheme. 
     6 
     7To compile, it requires a recent C++ compiler, Boost, and LLVM. For more information, see 
     8http://code.roadsend.com/pcc/ 
     9 
  • trunk/rphp/cmake/modules/FindLLVM.cmake

    r676 r679  
    4747  exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --ldflags   OUTPUT_VARIABLE LLVM_LDFLAGS ) 
    4848  #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 ) 
    5050  #MESSAGE(STATUS "LLVM core libs: " ${LLVM_LIBS_CORE}) 
    5151 
  • trunk/rphp/compiler/CMakeLists.txt

    r675 r679  
    6767    pStandAloneTargets.cpp 
    6868    pModule.cpp 
    69     pIRTypes.cpp 
     69    pIRHelper.cpp 
    7070) 
    7171 
  • trunk/rphp/compiler/pDriver.cpp

    r672 r679  
    2626#include <llvm/ModuleProvider.h> 
    2727#include <llvm/Support/MemoryBuffer.h> 
    28 #include <llvm/ModuleProvider.h> 
    2928#include <llvm/ExecutionEngine/JIT.h> 
    3029#include <llvm/ExecutionEngine/Interpreter.h> 
     
    8786bool pDriver::executeBC(string fileName) { 
    8887 
    89     // Now we create the JIT. 
    9088    string errMsg; 
    9189    llvm::MemoryBuffer* mb = llvm::MemoryBuffer::getFile(fileName.c_str(), &errMsg); 
  • trunk/rphp/compiler/pGenSupport.cpp

    r672 r679  
    1919 
    2020#include <llvm/Module.h> 
     21#include <llvm/ModuleProvider.h> 
     22#include <llvm/Support/MemoryBuffer.h> 
    2123#include <llvm/Bitcode/ReaderWriter.h> 
     24 
     25#include <iostream> 
    2226#include <fstream> 
    2327 
     
    5155 
    5256 
     57llvm::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 
     84llvm::Module* pGenSupport::getRuntimeIR() { 
     85 
     86    // TODO: ouch! 
     87    return readBitcode("/home/weyrick/workspace/rphp/runtime-ir/irRuntime.ir"); 
     88 
     89} 
     90 
     91 
    5392} // namespace 
    5493 
  • trunk/rphp/compiler/pGenSupport.h

    r672 r679  
    3434    static std::string mangleModuleName(std::string moduleName); 
    3535    static bool writeBitcode(llvm::Module* m, std::string outFile); 
     36    static llvm::Module* readBitcode(std::string fileName); 
     37    static llvm::Module* getRuntimeIR(); 
    3638 
    3739}; 
  • trunk/rphp/compiler/pGenerator.cpp

    r674 r679  
    2727#include <llvm/Instructions.h> 
    2828 
     29#include <llvm/Linker.h> 
     30 
    2931#include "pGenerator.h" 
    3032#include "pCompileTarget.h" 
    31 #include "pIRTypes.h" 
     33#include "pIRHelper.h" 
    3234#include "pGenSupport.h" 
    3335 
     
    3537 
    3638namespace rphp { 
     39 
     40pGenerator::pGenerator(llvm::Module* m, pCompileTarget* t): llvmModule(m), target(t), IRHelper(0) { 
     41 
     42    loadAndLinkRuntimeIR(); 
     43    createEntryPoint(); 
     44 
     45} 
     46     
     47pGenerator::~pGenerator(void) { 
     48 
     49    delete IRHelper; 
     50 
     51} 
     52 
     53void 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} 
    3777 
    3878void pGenerator::createEntryPoint(void) { 
     
    4282 
    4383    // entry function 
    44     Function *initFun = Function::Create(IRTypes.moduleEntryFunType(), 
     84    Function *initFun = Function::Create(IRHelper->moduleEntryFunType(), 
    4585                                         Function::ExternalLinkage, 
    4686                                         entryFunctionName, 
     
    5999    Function *initFun = llvmModule->getFunction(entryFunctionName); 
    60100    initFun->getEntryBlock().getInstList().push_back(ReturnInst::Create()); 
     101    // DEBUG 
     102    verifyModule(*llvmModule); 
    61103} 
    62104 
    63105void pGenerator::visit_literalBString(AST::literalBString* n) { 
    64106 
    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( 
    70135    /*Type=*/stringLiteralType, 
    71136    /*isConstant=*/true, 
    72137    /*Linkage=*/GlobalValue::InternalLinkage, 
    73138    /*Initializer=*/0, // has initializer, specified below 
    74     /*Name=*/".pBString", 
     139    /*Name=*/".str", 
    75140    llvmModule); 
    76141 
    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); 
    78144    std::vector<Constant*> const_ptr_8_indices; 
    79145    Constant* const_int32_9 = Constant::getNullValue(IntegerType::get(32)); 
    80146    const_ptr_8_indices.push_back(const_int32_9); 
    81147    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  
    84150    // 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); 
    89166 
    90167} 
     
    92169void pGenerator::visit_literalInt(AST::literalInt* n) { 
    93170 
    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 
     188void 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, 
    97195    /*Linkage=*/GlobalValue::InternalLinkage, 
    98196    /*Initializer=*/0, // has initializer, specified below 
    99     /*Name=*/".pInt", 
     197    /*Name=*/".str", 
    100198    llvmModule); 
    101199 
    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); 
    118215 
    119216} 
     
    121218void pGenerator::visit_echoStmt(AST::echoStmt* n) { 
    122219 
    123     // codegen our rVal expression 
    124220    visit(n->getRVal()); 
    125     emitEchoLiteralString(); 
    126  
    127 } 
    128  
    129 // assumes literal is on top of stack 
    130 void pGenerator::emitEchoLiteralString(void) { 
    131  
    132221    Value* rVal = valueStack.back(); 
    133222    valueStack.pop(); 
    134223 
    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// } 
    149251 
    150252// 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//
    162264 
    163265// create a new pVar on the stack and assign a pBString to it 
    164266// return pVar* 
    165 llvm::Value* pGenerator::emitVarCreate_pBString(llvm::Value*) { 
    166  
    167     /* 
    168     Value* pVar_p = emitVarCreate(); 
    169     rphp_create_pVar_pBString 
    170     return pVar_p; 
    171      
    172     // call runtime to create pVar from char* 
    173     // TODO: inline this 
    174     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//
    183285 
    184286// create a new pVar on the stack and assign a pBString to it 
    185287// 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//
    215317 
    216318 
  • trunk/rphp/compiler/pGenerator.h

    r674 r679  
    2525#include <llvm/Support/IRBuilder.h> 
    2626#include "pASTVisitors.h" 
    27 #include "pIRTypes.h" 
     27#include "pIRHelper.h" 
    2828 
    2929namespace llvm { 
     
    3838class pGenerator: public AST::defaultVisitor { 
    3939 
    40     llvm::Module* llvmModule; 
    41     pCompileTarget* target; 
    42     pIRTypes IRTypes; 
     40private: 
     41    llvm::Module* llvmModule; // don't own 
     42    pCompileTarget* target; // don't own 
     43    pIRHelper* IRHelper; // own 
    4344 
    4445    std::string entryFunctionName; 
    4546 
    4647    llvm::IRBuilder currentBlock; 
    47     llvm::Value* runtimeEngine; 
     48    llvm::Value* runtimeEngine; // don't own 
    4849    std::queue<llvm::Value*> valueStack; 
    4950 
     51private: 
     52    void loadAndLinkRuntimeIR(void); 
    5053    void createEntryPoint(void); 
    5154 
    52     void emitEchoLiteralString(void); 
     55    //void emitEchoLiteralString(void); 
    5356 
    5457    // pVar 
     58    /* 
    5559    llvm::Value* emitVarCreate(void); 
    5660    llvm::Value* emitVarCreate_pBString(llvm::Value*); 
     
    5963    void emitVarConstruct(llvm::Value*); 
    6064    void emitVarDestruct(llvm::Value*); 
    61  
     65    */ 
     66     
    6267public: 
    6368 
    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); 
    6971 
    7072    void finalize(void); 
  • trunk/rphp/compiler/pIRHelper.cpp

    • Property svn:mergeinfo set
    r674 r679  
    1818*/ 
    1919 
     20#include <llvm/Module.h> 
    2021#include <llvm/DerivedTypes.h> 
    21 #include "pIRTypes.h" 
     22 
     23#include <iostream> 
     24#include <string> 
     25 
     26#include "pIRHelper.h" 
    2227 
    2328using namespace llvm; 
     
    2530namespace rphp { 
    2631 
    27 Type* pIRTypes::runtimeEngineType() { 
    28     return PointerType::get(Type::Int8Ty,0); 
     32Type* pIRHelper::runtimeEngineType() { 
     33    return PointerType::get(mod->getTypeByName("struct.rphp::pRuntimeEngine"), 0); 
    2934} 
    3035 
    31 Type* pIRTypes::pVarPointerType() { 
    32    
    33     return PointerType::get(pVarType(), 0); 
    34  
     36Type* pIRHelper::pVarPointerType() { 
     37    return PointerType::get(mod->getTypeByName("struct.rphp::pVar"), 0); 
    3538} 
    3639 
    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  
     40const Type* pIRHelper::pVarType() { 
     41    return mod->getTypeByName("struct.rphp::pVar"); 
    8242} 
    8343 
    8444// void (*)(pVar*) 
    85 FunctionType* pIRTypes::pVarBaseFunType() { 
     45FunctionType* pIRHelper::pVarBaseFunType() { 
    8646 
    8747    std::vector<const Type*>FuncTy_52_args; 
     
    9656} 
    9757 
    98 FunctionType* pIRTypes::moduleEntryFunType() { 
     58FunctionType* pIRHelper::moduleEntryFunType() { 
    9959 
    10060    if (moduleEntryFunTypeC) 
  • trunk/rphp/compiler/pIRHelper.h

    • Property svn:mergeinfo set
    r674 r679  
    1818*/ 
    1919 
    20 #ifndef RPHP_PIRTYPES_H_ 
    21 #define RPHP_PIRTYPES_H_ 
     20#ifndef RPHP_PIRHELPER_H_ 
     21#define RPHP_PIRHELPER_H_ 
    2222 
    2323namespace llvm { 
    2424    class FunctionType; 
    2525    class Type; 
     26    class Module; 
    2627} 
    2728 
    2829namespace rphp { 
    2930 
    30 class pIRTypes
     31class pIRHelper
    3132 
    3233    llvm::FunctionType* moduleEntryFunTypeC; 
     34    llvm::Module* mod; 
    3335 
    3436public: 
    3537 
    36     pIRTypes(void): moduleEntryFunTypeC(0) { } 
     38    pIRHelper(llvm::Module* m): moduleEntryFunTypeC(0), mod(m) { } 
    3739 
    3840    // pointer to the runtime engine 
     
    4345 
    4446    llvm::FunctionType* pVarBaseFunType(); 
    45     llvm::Type* pVarType(); 
     47    const llvm::Type* pVarType(); 
    4648    llvm::Type* pVarPointerType(); 
    4749 
     
    5153} // namespace 
    5254 
    53 #endif /* RPHP_PIRTYPES_H_ */ 
     55#endif /* RPHP_PIRHELPER_H_ */ 
  • trunk/rphp/compiler/pStandAloneTargets.cpp

    r670 r679  
    5252     // ** STARTUP ** 
    5353     // startup function type 
    54      FunctionType *runtimeStartupFuncType = FunctionType::get(IRTypes.runtimeEngineType(), std::vector<const Type*>(), false); 
     54     FunctionType *runtimeStartupFuncType = FunctionType::get(IRHelper->runtimeEngineType(), std::vector<const Type*>(), false); 
    5555     // startup function 
    5656     Function *runtimeStartupFunc = Function::Create(runtimeStartupFuncType, 
     
    6363     // ** entry function call ** 
    6464     std::vector<const Type*> printSig; 
    65      printSig.push_back(IRTypes.runtimeEngineType()); 
    66      Function *entryFunc = Function::Create(IRTypes.moduleEntryFunType(), 
     65     printSig.push_back(IRHelper->runtimeEngineType()); 
     66     Function *entryFunc = Function::Create(IRHelper->moduleEntryFunType(), 
    6767                                            Function::ExternalLinkage, 
    6868                                            pGenSupport::mangleModuleName(mainFile), 
     
    7575     //  ** SHUTDOWN ** 
    7676     // argument sig for shutdown function 
    77      std::vector<const Type*> engineSig(1, IRTypes.runtimeEngineType()); 
     77     std::vector<const Type*> engineSig(1, IRHelper->runtimeEngineType()); 
    7878     // shutdown function type 
    7979     FunctionType *runtimeDeleteFuncType = FunctionType::get(Type::VoidTy, engineSig, false); 
     
    132132    } 
    133133    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    // 
    135139    args.push_back("-lrphp-runtime"); 
    136140    args.push_back("-o"); 
  • trunk/rphp/compiler/pStandAloneTargets.h

    r665 r679  
    2121#define RPHP_PSTANDALONETARGETS_H_ 
    2222 
    23 #include "pIRTypes.h" 
     23#include "pIRHelper.h" 
    2424#include "pLinkTarget.h" 
     25#include "pGenSupport.h" 
    2526 
    2627namespace rphp { 
     
    3233protected: 
    3334    std::string mainFile; 
    34     pIRTypes IRTypes
     35    pIRHelper* IRHelper
    3536 
    3637    llvm::Module* createStubModule(void); 
    3738 
    3839public: 
    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    } 
    4047 
    4148    virtual void execute(void);