| 34 | } |
| 35 | |
| 36 | bool compile ( const string & fn, const string & cppFn, bool dryRun ) { |
| 37 | auto access = get_file_access((char*)(projectFile.empty() ? nullptr : projectFile.c_str())); |
| 38 | ModuleGroup dummyGroup; |
| 39 | CodeOfPolicies policies; |
| 40 | policies.aot = false; |
| 41 | policies.aot_module = true; |
| 42 | policies.fail_on_lack_of_aot_export = true; |
| 43 | if ( auto program = compileDaScript(fn,access,tout,dummyGroup,false,policies) ) { |
| 44 | if ( program->failed() ) { |
| 45 | tout << "failed to compile\n"; |
| 46 | for ( auto & err : program->errors ) { |
| 47 | tout << reportError(err.at, err.what, err.extra, err.fixme, err.cerr); |
| 48 | } |
| 49 | return false; |
| 50 | } else { |
| 51 | smart_ptr<Context> pctx ( get_context(program->getContextStackSize()) ); |
| 52 | if ( !program->simulate(*pctx, tout) ) { |
| 53 | tout << "failed to simulate\n"; |
| 54 | for ( auto & err : program->errors ) { |
| 55 | tout << reportError(err.at, err.what, err.extra, err.fixme, err.cerr); |
| 56 | } |
| 57 | return false; |
| 58 | } |
| 59 | // AOT time |
| 60 | TextWriter tw; |
| 61 | bool noAotOption = program->options.getBoolOption("no_aot",false); |
| 62 | bool noAotModule = false; |
| 63 | // header |
| 64 | tw << "#include \"daScript/misc/platform.h\"\n\n"; |
| 65 | |
| 66 | tw << "#include \"daScript/simulate/simulate.h\"\n"; |
| 67 | tw << "#include \"daScript/simulate/aot.h\"\n"; |
| 68 | tw << "#include \"daScript/simulate/aot_library.h\"\n"; |
| 69 | tw << "\n"; |
| 70 | // lets comment on required modules |
| 71 | program->library.foreach([&](Module * mod){ |
| 72 | if ( mod->name=="" ) { |
| 73 | // nothing, its main program module. i.e :: |
| 74 | } else { |
| 75 | if ( mod->name=="$" ) { |
| 76 | tw << " // require builtin\n"; |
| 77 | } else { |
| 78 | tw << " // require " << mod->name << "\n"; |
| 79 | } |
| 80 | if ( mod->aotRequire(tw)==ModuleAotType::no_aot ) { |
| 81 | tw << " // AOT disabled due to this module\n"; |
| 82 | noAotModule = true; |
| 83 | } |
| 84 | } |
| 85 | return true; |
| 86 | },"*"); |
| 87 | if (dryRun) { |
| 88 | tout << "dry run success, no changes will be written\n"; |
| 89 | return true; |
| 90 | } |
| 91 | if (noAotOption) { |
| 92 | TextWriter noTw; |
| 93 | if (!noAotModule) |
no test coverage detected