Hi -

We are trying to use the GHC parser and renamer within a program that we
are writing (a program to take a Haskell program written in multiple
modules, and return a program that is a single module) and.  We were
wondering if you can think of something that we might be missing.  It
compiles fine (when we execute "make all" at the command line), but when
we run the executable it gets through the parser fine, and creates the
uniqueSupply for the renamer, but it doesn't get through the renamer, we
get an errors that say (Main.hs is the file that is being parsed and
renamed):

        Main.hs:1:
                Could not find interface file for 'Prelude'
                in the directories ./*.hi

        Main.hs:3:
                Bad interface file::  ./ParseAndRenameFile.hi
                ./ParseAndRenameFile.hi:1  Interface file version error; Expected 0
found version 408

        Fail: Compilation had errors

We assume that these are because the renamer needs to look at .hi files,
and that it either can't find them (Prelude.hi) or it has the wrong
version number (ParseAndRenameFile.hi).  How do we tell the renamer where
to look for the interface files, and fix the version error?
I've included the three files (Makefile, Main.hs, and
ParseAndRenameFile.hs) at the bottom of this email.
Thanks in advance for you any thoughts you might have,

Kate

===========================================================
Makefile:

HC      = ghc-4.08

INTERFACE_FILES =
.:compiler/absCSyn:compiler/basicTypes:compiler/codeGen:compiler/coreSyn:compiler/cprAnalysis:compiler/deSugar:compiler/hsSyn:compiler/javaGen:compiler/main:compiler/nativeGen:compiler/parser:compiler/prelude:compiler/profiling:compiler/rename:compil
er/simplCore:compiler/simplStg:compiler/specialise:compiler/stgSyn:compiler/stranal:compiler/typecheck:compiler/types:compiler/usageSP:compiler/utils:/home/lumberjacks/deforest/ghc-4.08/fptools-binaries/lib/i386-unknown-linux/imports/lang/

HC_OPTS = -cpp -i$(INTERFACE_FILES) $(EXTRA_HC_OPTS) -fglasgow-exts

SRCS = Main.hs ParseAndRenameFile.hs
OBJS = Main.o  ParseAndRenameFile.o 

.SUFFIXES : .o .hs .hi .lhs .hc .s

all: $(OBJS)
        $(HC) -lHSlang -lNewGHC
-L/usr/users/deforest/ghc-4.08/fptools-newgcc-build/lib -o PARF $(HC_OPTS)
$(OBJS) 

# Standard suffix rules
.o.hi:
        @:

.lhs.o:
        $(HC) -c $< $(HC_OPTS)

.hs.o:
        $(HC) -c $< $(HC_OPTS)

depend :
        $(HC) -M $(HC_OPTS) $(SRCS)


# DO NOT DELETE: Beginning of Haskell dependencies
Main.o : Main.hs
Main.o : ./ParseAndRenameFile.hi
ParseAndRenameFile.o : ParseAndRenameFile.hs
ParseAndRenameFile.o : compiler/basicTypes/UniqSupply.hi
ParseAndRenameFile.o : compiler/rename/Rename.hi
ParseAndRenameFile.o : compiler/utils/FastString.hi
ParseAndRenameFile.o : compiler/hsSyn/HsSyn.hi
ParseAndRenameFile.o : compiler/basicTypes/BasicTypes.hi
ParseAndRenameFile.o : compiler/parser/RdrHsSyn.hi
ParseAndRenameFile.o : compiler/utils/FastString.hi
ParseAndRenameFile.o : compiler/utils/StringBuffer.hi
ParseAndRenameFile.o : compiler/parser/Parser.hi
ParseAndRenameFile.o : compiler/parser/Lex.hi
ParseAndRenameFile.o : compiler/basicTypes/SrcLoc.hi
ParseAndRenameFile.o : compiler/rename/RnMonad.hi
ParseAndRenameFile.o : compiler/main/MkIface.hi
ParseAndRenameFile.o : compiler/typecheck/TcModule.hi
ParseAndRenameFile.o : compiler/basicTypes/Module.hi
ParseAndRenameFile.o : compiler/main/CmdLineOpts.hi
ParseAndRenameFile.o : compiler/main/ErrUtils.hi
ParseAndRenameFile.o : compiler/utils/Outputable.hi
# DO NOT DELETE: End of Haskell dependencies


===========================================================



Main.hs:

module Main where

import ParseAndRenameFile

main :: IO ()
main = parseAndRename "Main.hs" 

===========================================================


ParseAndRenameFile.hs:

module ParseAndRenameFile where

import UniqSupply       ( mkSplitUniqSupply )
import Rename           ( renameModule )
import FastString
--
import IO                       ( hPutStr, stderr )
import HsSyn
import BasicTypes               ( NewOrData(..) )
import RdrHsSyn         ( RdrNameHsModule )
import FastString               ( mkFastCharString, unpackFS )
import StringBuffer     ( hGetStringBuffer )
import Parser                   ( parse )
import Lex                      ( PState(..), P, ParseResult(..) )
import SrcLoc                   ( mkSrcLoc )
import RnMonad          ( InterfaceDetails(..) )
import MkIface          ( startIface, ifaceDecls, endIface )
import TcModule         ( TcResults(..), typecheckModule )
import Module                   ( ModuleName, moduleNameUserString )
import CmdLineOpts
import ErrUtils         ( ghcExit )
import Outputable


parseAndRename filename 
    = do {(name, parsed) <- parseFile filename; 
                  rn_uniqs       <- mkSplitUniqSupply 'r';
                  maybe          <- renameModule rn_uniqs parsed;
                  putStr "done \n"
                }

--parseFile is adapted from parseModule in  compiler/main/Main.lhs
parseFile :: String -> IO (ModuleName, RdrNameHsModule)
parseFile filename = do
    {buf <- hGetStringBuffer True{-expand tabs-} filename;
     case parse buf PState{ bol = 0#, 
                            atbol = 1#,
                            context = [], 
                            glasgow_exts = glaexts,
                            loc = mkSrcLoc (mkFastString filename) 1 } of

         PFailed err -> do
                 printErrs err
                 ghcExit 1
                 return (error "parseModule") -- just to get the types right

         POk _ m@(HsModule mod _ _ _ _ _ _) -> 
                 return (mod, m)
     }
   where
         glaexts | opt_GlasgowExts = 1#
                 | otherwise       = 0#

===========================================================

Thanks again!


_______________________________________________
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to