| 744 | } // anonymous namespace |
| 745 | |
| 746 | Result interpretLLVMIR(std::unique_ptr<llvm::Module> mod, llvm::CodeGenOpt::Level optLevel, |
| 747 | std::vector<llvm::GenericValue> args, llvm::Function* funcToRun, |
| 748 | llvm::GenericValue* ret) { |
| 749 | assert(mod); |
| 750 | |
| 751 | Result res; |
| 752 | |
| 753 | if (funcToRun == nullptr) { |
| 754 | funcToRun = mod->getFunction("main"); |
| 755 | |
| 756 | if (funcToRun == nullptr) { |
| 757 | res.addEntry("EUKN", "Failed to find main function in module", |
| 758 | {{"Module Name", mod->getModuleIdentifier()}}); |
| 759 | return res; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | std::string errMsg; |
| 764 | auto EE = createEE(std::move(mod), optLevel, errMsg); |
| 765 | EE->finalizeObject(); |
| 766 | EE->runStaticConstructorsDestructors(false); |
| 767 | |
| 768 | if (!EE) { |
| 769 | res.addEntry("EINT", "Failed to create an LLVM ExecutionEngine", {{"Error", errMsg}}); |
| 770 | return res; |
| 771 | } |
| 772 | |
| 773 | auto returnValue = EE->runFunction(funcToRun, args); |
| 774 | |
| 775 | EE->runStaticConstructorsDestructors(true); |
| 776 | |
| 777 | if (ret != nullptr) { *ret = returnValue; } |
| 778 | |
| 779 | return res; |
| 780 | } |
| 781 | |
| 782 | Result interpretLLVMIRAsMain(std::unique_ptr<llvm::Module> mod, llvm::CodeGenOpt::Level optLevel, |
| 783 | std::vector<std::string> args, llvm::Function* funcToRun, int* ret) { |