void CModuleBuilder::StartModule( const CToken& startToken, const CToken& nameToken ) { StartModule( startToken ); if( isModuleExist() ) { module->NameToken = nameToken; } }
//-------------------------------------------------------------- static int Hook_StartModule(int id, char *modname, int arg_len, char *args, int *modres) { DPRINTF("Hook_StartModule() id=%d modname = %s\n", id, modname); if (isFakemod()) return FAKEMOD_ID; return StartModule(id, modname, arg_len, args, modres); }
void IncrementalParser::codeGenTransaction(Transaction* T) { // codegen the transaction assert(T->getCompilationOpts().CodeGeneration && "CodeGen turned off"); assert(T->getState() == Transaction::kCompleted && "Must be completed"); assert(hasCodeGenerator() && "No CodeGen"); // Could trigger derserialization of decls. Transaction* deserT = beginTransaction(CompilationOptions()); // Commit this transaction first - T might need symbols from it, so // trigger emission of weak symbols by providing use. ParseResultTransaction PRT = endTransaction(deserT); commitTransaction(PRT); deserT = PRT.getPointer(); // This llvm::Module is done; finalize it and pass it to the execution // engine. if (!T->isNestedTransaction() && hasCodeGenerator()) { // The initializers are emitted to the symbol "_GLOBAL__sub_I_" + filename. // Make that unique! deserT = beginTransaction(CompilationOptions()); // Reset the module builder to clean up global initializers, c'tors, d'tors getCodeGenerator()->HandleTranslationUnit(getCI()->getASTContext()); auto PRT = endTransaction(deserT); commitTransaction(PRT); deserT = PRT.getPointer(); std::unique_ptr<llvm::Module> M(getCodeGenerator()->ReleaseModule()); if (M) { m_Interpreter->addModule(M.get(), T->getCompilationOpts().OptLevel); T->setModule(std::move(M)); } if (T->getIssuedDiags() != Transaction::kNone) { // Module has been released from Codegen, reset the Diags now. DiagnosticsEngine& Diags = getCI()->getSema().getDiagnostics(); Diags.Reset(/*soft=*/true); Diags.getClient()->clear(); } // Create a new module. StartModule(); } }
main(int argc, char *argv[]) { char *pgm; int ok, help, debug, verbose, query; char *what = "*", whatbuf[256] = { '\0' }; char *world; char *server; char *logger; char *host; int id, nc; int i, nmod; char argbuf[256]; MODULE_HOST modlocs[MAX_AGENT]; pgm = argv[0]; ++argv; --argc; ok = 1; help = 0; debug = 0; verbose = 0; query = 0; world = NULL; logger = NULL; host = NULL; while (argc && *argv[0] == '-') { char *opt; opt = argv[0] + 1; ++argv; --argc; if (streq(opt, "help")) ++help; else if (substr(opt, "debug")) ++debug; else if (substr(opt, "verbose"))++verbose; else if (substr(opt, "earlab")) { world = "Earlab*Master"; } else if (substr(opt, "search")) { if (!argc || argv[0][0] == '-') { fprintf(stderr, "%s: missing argument to -%s\n", pgm, opt); ok = 0; } else { world = argv[0]; ++argv; --argc; } } else if (substr(opt, "logserver")) { if (!argc || argv[0][0] == '-') { fprintf(stderr, "%s: missing argument to -%s\n", pgm, opt); ok = 0; } else { logger = argv[0]; ++argv; --argc; } } else if (substr(opt, "module")) { if (!argc || argv[0][0] == '-') { fprintf(stderr, "%s: missing argument to -%s\n", pgm, opt); ok = 0; } else { if (!whatbuf[0]) strcpy(whatbuf, "{"); else strcat(whatbuf, ","); strcat(whatbuf, argv[0]); what = whatbuf; ++argv; --argc; } } else if (substr(opt, "host")) { if (!argc || argv[0][0] == '-') { fprintf(stderr, "%s: missing argument to -%s\n", pgm, opt); ok = 0; } else { host = argv[0]; ++argv; --argc; } } else { fprintf(stderr, "%s: ignoring argument -%s\n", pgm, opt) ; help = 1; ok = 0; } } if (!ok || help || (argc == 0 && !world)) { usage(pgm, help); exit(!help); } event_verbose(verbose); if (world) { server = SearchWorld(NULL, world); if (!server) { fprintf(stderr, "%s: couldn't find earlab master server\n", pgm); exit(1); } } else if (argc) { server = argv[0]; ++argv; --argc; } else { usage(pgm, help); exit(1); } if (argc) { if (!whatbuf[0]) what = argv[0]; else { strcat(whatbuf, ","); strcat(whatbuf, argv[0]); strcat(whatbuf, "}"); } ++argv; --argc; } else if (!whatbuf[0]) { usage(pgm, 0); exit(1); } argbuf[0] = '\0'; while (argc) { strcat(argbuf, argv[0]); ++argv; --argc; if (argc) strcat(argbuf, " "); } printf("Module search is \"%s\"\n", what); /* local initialization */ agent_init(); id = event_join(server, &nc); if (!id) { fprintf(stderr, "%s: couldn't join server \"%s\"\n", server); exit(4); } printf("%s: joined %s as client id %d (%d clients)\n", pgm, server, id, nc); event_register("earlab", "control", pgm); event_select_type(0, 0, ET_MAX); event_select_type(1, ET_AGENTD_MIN, ET_AGENTD_MAX); nmod = LocateModule(what, modlocs, MAX_AGENT); for (i = 0; i < nmod; ++i) { printf("%s: module \"%s\" available on host %s\n", pgm, modlocs[i].module, modlocs[i].host); } if (query) { event_leave(); exit(0); } if (host) for (i = 0; i < nmod; ++i) { if (strmatch(host, modlocs[i].host)) break; } else i = 0; if (nmod == 0 || i == nmod) { printf("%s: module \"%s\" not available on host %s\n", pgm, what, host?host:"*"); event_leave(); exit(1); } StartModule(modlocs[i].clientid, logger, modlocs[i].module, argbuf); event_leave(); exit(0); }
void IncrementalParser::commitTransaction(ParseResultTransaction& PRT, bool ClearDiagClient) { Transaction* T = PRT.getPointer(); if (!T) { if (PRT.getInt() != kSuccess) { // Nothing has been emitted to Codegen, reset the Diags. DiagnosticsEngine& Diags = getCI()->getSema().getDiagnostics(); Diags.Reset(/*soft=*/true); if (ClearDiagClient) Diags.getClient()->clear(); } return; } assert(T->isCompleted() && "Transaction not ended!?"); assert(T->getState() != Transaction::kCommitted && "Committing an already committed transaction."); assert((T->getIssuedDiags() == Transaction::kErrors || !T->empty()) && "Valid Transactions must not be empty;"); // If committing a nested transaction the active one should be its parent // from now on. if (T->isNestedTransaction()) m_Consumer->setTransaction(T->getParent()); // Check for errors... if (T->getIssuedDiags() == Transaction::kErrors) { // Make module visible to TransactionUnloader. bool MustStartNewModule = false; if (!T->isNestedTransaction() && hasCodeGenerator()) { MustStartNewModule = true; std::unique_ptr<llvm::Module> M(getCodeGenerator()->ReleaseModule()); if (M) { T->setModule(std::move(M)); } } // Module has been released from Codegen, reset the Diags now. DiagnosticsEngine& Diags = getCI()->getSema().getDiagnostics(); Diags.Reset(/*soft=*/true); if (ClearDiagClient) Diags.getClient()->clear(); PRT.setPointer(nullptr); PRT.setInt(kFailed); m_Interpreter->unload(*T); // Create a new module if necessary. if (MustStartNewModule) StartModule(); return; } if (T->hasNestedTransactions()) { Transaction* TopmostParent = T->getTopmostParent(); EParseResult PR = kSuccess; if (TopmostParent->getIssuedDiags() == Transaction::kErrors) PR = kFailed; else if (TopmostParent->getIssuedDiags() == Transaction::kWarnings) PR = kSuccessWithWarnings; for (Transaction::const_nested_iterator I = T->nested_begin(), E = T->nested_end(); I != E; ++I) if ((*I)->getState() != Transaction::kCommitted) { ParseResultTransaction PRT(*I, PR); commitTransaction(PRT); } } // If there was an error coming from the transformers. if (T->getIssuedDiags() == Transaction::kErrors) { m_Interpreter->unload(*T); return; } // Here we expect a template instantiation. We need to open the transaction // that we are currently work with. { Transaction* prevConsumerT = m_Consumer->getTransaction(); m_Consumer->setTransaction(T); Transaction* nestedT = beginTransaction(T->getCompilationOpts()); // Pull all template instantiations in that came from the consumers. getCI()->getSema().PerformPendingInstantiations(); ParseResultTransaction nestedPRT = endTransaction(nestedT); commitTransaction(nestedPRT); m_Consumer->setTransaction(prevConsumerT); } m_Consumer->HandleTranslationUnit(getCI()->getASTContext()); // The static initializers might run anything and can thus cause more // decls that need to end up in a transaction. But this one is done // with CodeGen... if (T->getCompilationOpts().CodeGeneration && hasCodeGenerator()) { Transaction* prevConsumerT = m_Consumer->getTransaction(); m_Consumer->setTransaction(T); codeGenTransaction(T); T->setState(Transaction::kCommitted); if (!T->getParent()) { if (m_Interpreter->executeTransaction(*T) >= Interpreter::kExeFirstError) { // Roll back on error in initializers. // T maybe pointing to freed memory after this call: // Interpreter::unload // IncrementalParser::deregisterTransaction // TransactionPool::releaseTransaction m_Interpreter->unload(*T); return; } } m_Consumer->setTransaction(prevConsumerT); } T->setState(Transaction::kCommitted); if (InterpreterCallbacks* callbacks = m_Interpreter->getCallbacks()) callbacks->TransactionCommitted(*T); }