compiler/passes/normalize.cpp
/************************************* | **************************************
*                                                                             *
* Insert the module initFn in to every module in allModules.  The current     *
* implementation pulls the entire module in to the prototypical initFn and    *
* then lets the rest of normalize sort things out.                            *
* Also stash away the module deinitFn, if the user has written one.           *
*                                                                             *
************************************** | *************************************/
|
Insert the module initFn in to every module in allModules.  The current
implementation pulls the entire module in to the prototypical initFn and
then lets the rest of normalize sort things out.
Also stash away the module deinitFn, if the user has written one.


| Insert the module initFn in to every module in allModules . The current implementation pulls the entire module in to the prototypical initFn and then lets the rest of normalize sort things out . Also stash away the module deinitFn if the user has written one .
static void insertModuleInit() {
  forv_Vec(ModuleSymbol, mod, allModules) {
    SET_LINENO(mod);
    mod->initFn          = new FnSymbol(astr("chpl__init_", mod->name));
    mod->initFn->retType = dtVoid;
    mod->initFn->addFlag(FLAG_MODULE_INIT);
    mod->initFn->addFlag(FLAG_INSERT_LINE_FILE_INFO);
     move module-level statements into module's init function
    for_alist(stmt, mod->block->body) {
      if (stmt->isModuleDefinition() == false) {
        if (FnSymbol* deinitFn = toModuleDeinitFn(mod, stmt)) {
          mod->deinitFn = deinitFn;  the rest is in handleModuleDeinitFn()
        } else {
          mod->initFn->insertAtTail(stmt->remove());
        }
      }
    }
    mod->block->insertAtHead(new DefExpr(mod->initFn));
    handleModuleDeinitFn(mod);
     If the module has the EXPORT_INIT flag then
     propagate it to the module's init function
    if (mod->hasFlag(FLAG_EXPORT_INIT) == true ||
        (fLibraryCompile == true && mod->modTag == MOD_USER)) {
      mod->initFn->addFlag(FLAG_EXPORT);
      mod->initFn->addFlag(FLAG_LOCAL_ARGS);
    }
  }
  USR_STOP();
}
static void insertModuleInit ( ) { forv_Vec ( ModuleSymbol , mod , allModules ) { SET_LINENO ( mod ) ; mod -> initFn = new FnSymbol ( astr ( " " , mod -> name ) ) ; mod -> initFn -> retType = dtVoid ; mod -> initFn -> addFlag ( FLAG_MODULE_INIT ) ; mod -> initFn -> addFlag ( FLAG_INSERT_LINE_FILE_INFO ) ; for_alist ( stmt , mod -> block -> body ) { if ( stmt -> isModuleDefinition ( ) == false ) { if ( FnSymbol * deinitFn = toModuleDeinitFn ( mod , stmt ) ) { mod -> deinitFn = deinitFn ; } else { mod -> initFn -> insertAtTail ( stmt -> remove ( ) ) ; } } } mod -> block -> insertAtHead ( new DefExpr ( mod -> initFn ) ) ; handleModuleDeinitFn ( mod ) ; if ( mod -> hasFlag ( FLAG_EXPORT_INIT ) == true || ( fLibraryCompile == true && mod -> modTag == MOD_USER ) ) { mod -> initFn -> addFlag ( FLAG_EXPORT ) ; mod -> initFn -> addFlag ( FLAG_LOCAL_ARGS ) ; } } USR_STOP ( ) ; }
|
Insert the module initFn in to every module in allModules.
| Insert the module initFn in to every module in allModules .
// Insert an init function into every module // // move module-level statements into module's init function // // the rest is in handleModuleDeinitFn() // // If the module has the EXPORT_INIT flag then // propagate it to the module's init function //