| 306 | |
| 307 | std::vector<unsigned char> out; |
| 308 | const char* GetLLVMIR(unsigned& length) |
| 309 | { |
| 310 | if(F->back().empty() || !F->back().back().isTerminator()) |
| 311 | Builder.CreateRetVoid(); |
| 312 | |
| 313 | /*F->getBasicBlockList().push_back(globalExit); |
| 314 | Builder.SetInsertPoint(globalExit); |
| 315 | Builder.CreateRet(ConstantInt::get(getGlobalContext(), APInt(32, ~0ull, true)));*/ |
| 316 | |
| 317 | if(enableOptimization) |
| 318 | { |
| 319 | if(!F->getEntryBlock().empty()) |
| 320 | OurFPM->run(*F); |
| 321 | OurPM->run(*TheModule); |
| 322 | if(!F->getEntryBlock().empty()) |
| 323 | OurFPM->run(*F); |
| 324 | } |
| 325 | |
| 326 | DUMP(TheModule); |
| 327 | |
| 328 | // unsigned start = clock(); |
| 329 | |
| 330 | verifyFunction(*F); |
| 331 | verifyModule(*TheModule); |
| 332 | |
| 333 | // unsigned verified = clock() - start; |
| 334 | // start = clock(); |
| 335 | |
| 336 | out.clear(); |
| 337 | BitstreamWriter bw = BitstreamWriter(out); |
| 338 | WriteBitcodeToStream(TheModule, bw); |
| 339 | out.push_back(0); |
| 340 | length = (unsigned)out.size(); |
| 341 | |
| 342 | //printf("%d\n", out.size()); |
| 343 | |
| 344 | /*if(!F->getEntryBlock().empty()) |
| 345 | { |
| 346 | void *FPtr = TheExecutionEngine->getPointerToFunction(F); |
| 347 | unsigned compiled = clock() - start; |
| 348 | start = clock(); |
| 349 | int (*FP)() = (int (*)())(intptr_t)FPtr; |
| 350 | printf("Evaluated to %d (verification %d; compilation %d; execution %d)\n", FP(), verified, compiled, clock() - start); |
| 351 | for(std::vector<void*>::iterator c = memBlocks.begin(), e = memBlocks.end(); c != e; c++) |
| 352 | free(*c); |
| 353 | memBlocks.clear(); |
| 354 | }*/ |
| 355 | |
| 356 | return (char*)&out[0]; |
| 357 | } |
| 358 | llvm::Value *V; |
| 359 | |
| 360 | |