| 78 | } |
| 79 | |
| 80 | bool aot_compile ( vector<pair<string, string>> &aot_files, bool dryRun, bool cross_platform ) { |
| 81 | // call daslib/aot_cpp `aot()` from C++ |
| 82 | auto access = get_file_access((char*)(projectFile.empty() ? nullptr : projectFile.c_str())); |
| 83 | ModuleGroup dummyGroup; |
| 84 | CodeOfPolicies stubPolicies; |
| 85 | stubPolicies.version_2_syntax = true; |
| 86 | stubPolicies.aot_module = true; |
| 87 | string aotCppPath = getDasRoot() + "/daslib/aot_cpp.das"; |
| 88 | auto program = compileDaScript(aotCppPath, access, tout, dummyGroup, stubPolicies); |
| 89 | if ( !program || program->failed() ) { |
| 90 | tout << "failed to compile daslib/aot_cpp.das\n"; |
| 91 | if ( program ) for ( auto & err : program->errors ) { |
| 92 | tout << reportError(err.at, err.what, err.extra, err.fixme, err.cerr); |
| 93 | } |
| 94 | return false; |
| 95 | } |
| 96 | auto pctx = SimulateWithErrReport(program, tout); |
| 97 | if ( !pctx ) return false; |
| 98 | bool isUnique = false; |
| 99 | auto aotFn = pctx->findFunction("aot", isUnique); |
| 100 | if ( !aotFn ) { |
| 101 | tout << "daslib aot() not found\n"; |
| 102 | return false; |
| 103 | } |
| 104 | CodeOfPolicies cop = getPolicies(); |
| 105 | cop.aot = false; |
| 106 | cop.aot_lib = isAotLib; |
| 107 | cop.ignore_shared_modules = false; |
| 108 | bool compiled = true; |
| 109 | for (const auto &[in, out] : aot_files) { |
| 110 | // Use `or` here, to return `true` if at least one file compiled successfully. |
| 111 | string inputStr = in; |
| 112 | vec4f args[4]; |
| 113 | args[0] = cast<char*>::from((char*)inputStr.c_str()); |
| 114 | args[1] = cast<bool>::from(paranoid_validation); |
| 115 | args[2] = cast<bool>::from(cross_platform); |
| 116 | args[3] = cast<CodeOfPolicies*>::from(&cop); |
| 117 | pctx->restart(); |
| 118 | vec4f ret = pctx->evalWithCatch(aotFn, args); |
| 119 | if ( auto ex = pctx->getException() ) { |
| 120 | tout << "aot exception: " << ex << " at " << pctx->exceptionAt.describe() << "\n"; |
| 121 | return false; |
| 122 | } |
| 123 | const char * resultStr = cast<char*>::to(ret); |
| 124 | if ( dryRun ) { |
| 125 | tout << "dry run success, no changes will be written\n"; |
| 126 | } else if ( !resultStr || !resultStr[0] ) { |
| 127 | tout << "aot returned empty result for " << in << "\n"; |
| 128 | compiled = false; |
| 129 | } else { |
| 130 | bool is_ok = saveToFile(tout, out, resultStr, quiet); |
| 131 | if (!is_ok && !quiet) { |
| 132 | tout << "Failed to compile `" << out << "` in aot.\n"; |
| 133 | } |
| 134 | compiled &= is_ok; |
| 135 | } |
| 136 | } |
| 137 | return compiled; |
no test coverage detected