@@ -503,40 +503,40 @@ def get_mode(orig_string):
503503 if not isinstance (string , str ):
504504 return string # it is hopefully already a mode...
505505
506+ if string in predefined_modes :
507+ return predefined_modes [string ]
508+
509+ if string not in ("Mode" , "DebugMode" , "DEBUG_MODE" , "NanGuardMode" ):
510+ raise ValueError (f"No predefined mode exist for string: { string } " )
511+
506512 global instantiated_default_mode
507513 # The default mode is cached. However, config.mode can change
508514 # If instantiated_default_mode has the right class, use it.
515+
509516 if orig_string is None and instantiated_default_mode :
510- if string in predefined_modes :
511- default_mode_class = predefined_modes [string ].__class__ .__name__
512- else :
513- default_mode_class = string
517+ # This includes a string in ("Mode", "DebugMode", "DEBUG_MODE", "NanGuardMode")
518+ default_mode_class = string
519+ # FIXME: This is flawed, we should use proper object comparison.
514520 if instantiated_default_mode .__class__ .__name__ == default_mode_class :
515521 return instantiated_default_mode
516522
517- if string in ("Mode" , "DebugMode" , "NanGuardMode" ):
518- if string == "DebugMode" :
519- # need to import later to break circular dependency.
520- from .debugmode import DebugMode
523+ if string in ("DebugMode" , "DEBUG_MODE" ):
524+ # need to import later to break circular dependency.
525+ from .debugmode import DebugMode
521526
522- # DebugMode use its own linker.
523- ret = DebugMode (optimizer = config .optimizer )
524- elif string == "NanGuardMode" :
525- # need to import later to break circular dependency.
526- from .nanguardmode import NanGuardMode
527+ # DebugMode use its own linker.
528+ ret = DebugMode (optimizer = config .optimizer )
529+ elif string == "NanGuardMode" :
530+ # need to import later to break circular dependency.
531+ from .nanguardmode import NanGuardMode
527532
528- # NanGuardMode use its own linker.
529- ret = NanGuardMode (True , True , True , optimizer = config .optimizer )
530- else :
531- # TODO: Can't we look up the name and invoke it rather than using eval here?
532- ret = eval (string + "(linker=config.linker, optimizer=config.optimizer)" )
533- elif string in predefined_modes :
534- ret = predefined_modes [string ]
533+ # NanGuardMode use its own linker.
534+ ret = NanGuardMode (True , True , True , optimizer = config .optimizer )
535535 else :
536- raise Exception ( f"No predefined mode exist for string: { string } " )
536+ ret = Mode ( linker = config . linker , optimizer = config . optimizer )
537537
538538 if orig_string is None :
539- # Build and cache the default mode
539+ # Build and cache the ~~ default~~ first requested mode
540540 if config .optimizer_excluding :
541541 ret = ret .excluding (* config .optimizer_excluding .split (":" ))
542542 if config .optimizer_including :
0 commit comments