--- | 'runIO' is wrapped around @Main.main@ by @TcModule@. It is also wrapped
--- around every @foreign export@ and @foreign import \"wrapper\"@ to mop up
--- any uncaught exceptions. Thus, the result of running
--- 'System.Exit.exitWith' in a foreign-exported function is the same as
--- in the main thread: it terminates the program.
+-- | 'runMainIO' is wrapped around 'Main.main' (or whatever main is
+-- called in the program). It catches otherwise uncaught exceptions,
+-- and also flushes stdout\/stderr before exiting.
+runMainIO :: IO a -> IO a
+runMainIO main = (do a <- main; cleanUp; return a) `catchException` topHandler
+
+-- | 'runIO' is wrapped around every @foreign export@ and @foreign
+-- import \"wrapper\"@ to mop up any uncaught exceptions. Thus, the
+-- result of running 'System.Exit.exitWith' in a foreign-exported
+-- function is the same as in the main thread: it terminates the
+-- program.