moduleLanguage.HERMIT.Plugin(-- * The HERMIT PluginHermitPass,hermitPlugin)whereimportGhcPluginsimportData.ListimportSystem.IOimportData.Char(isDigit)importData.Default-- | Given a list of 'CommandLineOption's, produce the 'ModGuts' to 'ModGuts' function required to build a plugin.typeHermitPass=[CommandLineOption]->ModGuts->CoreMModGutsdataOptions=Options{pass::Int}instanceDefaultOptionswheredef=Options{pass=0}parse::[String]->Options->Optionsparse(('-':'p':n):rest)o|allisDigitn=parserest$o{pass=readn}parse(_:rest)o=parseresto-- unknown optionparse[]o=o-- | Build a hermit plugin. This mainly handles the per-module options.hermitPlugin::HermitPass->PluginhermitPluginhp=defaultPlugin{installCoreToDos=install}whereinstall::[CommandLineOption]->[CoreToDo]->CoreM[CoreToDo]installoptstodos=doreinitializeGlobals-- This is a bit of a hack; otherwise we lose what we've not seenliftIO$hSetBufferingstdoutNoBufferingdynFlags<-getDynFlagslet(m_opts,h_opts)=partition(isInfixOf":")optshermit_opts=parseh_optsdefmyPass=CoreDoPluginPass"HERMIT"$modFilterdynFlagshpm_opts-- at front, for nowallPasses=insertAt(passhermit_opts)myPasstodosreturnallPasses-- | Determine whether to act on this module, choose plugin pass.modFilter::DynFlags->HermitPass->HermitPassmodFilterdynFlagshpoptsguts|nullmodOpts&&not(nullopts)=returnguts-- don't process this module|otherwise=hpmodOptsgutswheremodOpts=filterOptsdynFlagsoptsguts-- | Filter options to those pertaining to this module, stripping module prefix.filterOpts::DynFlags->[CommandLineOption]->ModGuts->[CommandLineOption]filterOptsdynFlagsoptsguts=[droplennm|nm<-opts,modName`isPrefixOf`nm]wheremodName=showPprdynFlags$mg_modulegutslen=lengthmodName+1-- for the coloninsertAt::Int->a->[a]->[a]insertAtnxxs=pre++(x:suf)where(pre,suf)=splitAtnxs