Hello,
I am bringing back that thread to life after a while.
I've spent some time on studding GHC source code related with that topic.
There are some conclusions I have made:
- In my first email, I thought that execution of function compileCoreToObj in my program produced some *.o file. I was wrong. That file was produced by earlier step, that is execution of compileToCoreModule function. compileCoreToObj has generated only *.hi file because exception has been raised.
- I have found a way to produce valid interface file
- I have discovered, why compileCoreToObj raises exceptions. It was because stubDir field in DynFlags structure has to be set for proper execution.
- Artifacts produced by compileCoreToObj for a non-executable module are: interface file and assembly output.
The last point is my main problem for now. I supposed that object file will be generated, as it is generated by GHC executed on haskell module.
Code used for my tests is as follows:
A.hs:
import GHC
import DynFlags
import GHC.Paths
import qualified Debug.Trace as T
import Panic
import HscMain
import HscTypes
import Name
import UniqFM
main = do
core <- getCore
getLine
compile HscAsm "foo" core
getCore = defaultErrorHandler defaultFatalMessager defaultFlushOut
$ runGhc (Just libdir) $ do
df <- getSessionDynFlags
setSessionDynFlags df
core <- compileToCoreModule "B.hs"
return core
compile target output_fn core = defaultErrorHandler defaultFatalMessager defaultFlushOut
$ runGhc (Just libdir) $ do
df <- getSessionDynFlags
setSessionDynFlags df { hscTarget = target , stubDir = Just "./stub" }
compileCoreToObj False core output_fn "bar"
module B (foo) where
foo :: a -> a
foo = id
bar :: Eq a => a -> a -> Bool
bar = (==)
getCore and compile are separated to make sure, no flags set by the first function were used by the second one.
getLine is used here to stop an execution of test for cleaning output directory form files generated by getCore.
Is there a way to get an object file as a result of compileCoreToObj?
Regards,
MWawrzos