| 2028 | } |
| 2029 | |
| 2030 | void BfIRCodeGen::HandleNextCmd() |
| 2031 | { |
| 2032 | if (mFailed) |
| 2033 | return; |
| 2034 | |
| 2035 | int curId = mCmdCount; |
| 2036 | |
| 2037 | BfIRCmd cmd = (BfIRCmd)mStream->Read(); |
| 2038 | mCmdCount++; |
| 2039 | |
| 2040 | switch (cmd) |
| 2041 | { |
| 2042 | case BfIRCmd_Module_Start: |
| 2043 | { |
| 2044 | CMD_PARAM(String, moduleName); |
| 2045 | CMD_PARAM(int, ptrSize); |
| 2046 | CMD_PARAM(bool, isOptimized); |
| 2047 | |
| 2048 | BF_ASSERT(mLLVMModule == NULL); |
| 2049 | mModuleName = moduleName; |
| 2050 | mPtrSize = ptrSize; |
| 2051 | mIsOptimized = isOptimized; |
| 2052 | mLLVMModule = new llvm::Module(moduleName.c_str(), *mLLVMContext); |
| 2053 | mIRBuilder = new llvm::IRBuilder<>(*mLLVMContext); |
| 2054 | |
| 2055 | //OutputDebugStrF("-------- Starting Module %s --------\n", moduleName.c_str()); |
| 2056 | } |
| 2057 | break; |
| 2058 | case BfIRCmd_Module_SetTargetTriple: |
| 2059 | { |
| 2060 | CMD_PARAM(String, targetTriple); |
| 2061 | CMD_PARAM(String, targetCPU); |
| 2062 | |
| 2063 | mTargetTriple.Set(targetTriple); |
| 2064 | mTargetCPU = targetCPU; |
| 2065 | |
| 2066 | if (targetTriple.IsEmpty()) |
| 2067 | mLLVMModule->setTargetTriple(llvm::sys::getDefaultTargetTriple()); |
| 2068 | else |
| 2069 | mLLVMModule->setTargetTriple(targetTriple.c_str()); |
| 2070 | |
| 2071 | InitTarget(); |
| 2072 | } |
| 2073 | break; |
| 2074 | case BfIRCmd_Module_AddModuleFlag: |
| 2075 | { |
| 2076 | CMD_PARAM(String, flag); |
| 2077 | CMD_PARAM(int, val); |
| 2078 | mLLVMModule->addModuleFlag(llvm::Module::Warning, flag.c_str(), val); |
| 2079 | |
| 2080 | if (flag == "CodeView") |
| 2081 | mIsCodeView = true; |
| 2082 | } |
| 2083 | break; |
| 2084 | case BfIRCmd_WriteIR: |
| 2085 | { |
| 2086 | CMD_PARAM(String, fileName); |
| 2087 | std::error_code ec; |
no test coverage detected