From: ken Date: Mon, 23 Jul 2001 23:08:04 +0000 (+0000) Subject: [project @ 2001-07-23 23:08:04 by ken] X-Git-Tag: Approximately_9120_patches~1463 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=fb40b8b17e29bf1933ac27eb64ae95c0833b3727 [project @ 2001-07-23 23:08:04 by ken] Rearranged the usage help message to move --no-compile to the bottom. More importantly-- Fixed: hsc2hs was translating #def inline ... function(...) { ... } into (assuming defined(__GNUC__)) [in the _hsc.h file:] extern inline ... function(...) [in the _hsc.c file:] inline ... function(...) while it should really be translated into [in the _hsc.h file:] extern inline ... function(...) [in the _hsc.c file:] ... function(...) (without the "inline" in the _hsc.c file). Quoting the gcc documentation for "inline": > If you specify both `inline' and `extern' in the function > definition, then the definition is used only for inlining. In no case > is the function compiled on its own, not even if you refer to its > address explicitly. Such an address becomes an external reference, as > if you had only declared the function, and had not defined it. > > This combination of `inline' and `extern' has almost the effect of a > macro. The way to use it is to put a function definition in a header > file with these keywords, and put another copy of the definition > (lacking `inline' and `extern') in a library file. The definition in > the header file will cause most calls to the function to be inlined. > If any uses of the function remain, they will refer to the single copy > in the library. --- diff --git a/ghc/utils/hsc2hs/Main.hs b/ghc/utils/hsc2hs/Main.hs index 4827905..97f7224 100644 --- a/ghc/utils/hsc2hs/Main.hs +++ b/ghc/utils/hsc2hs/Main.hs @@ -1,5 +1,5 @@ ------------------------------------------------------------------------ --- $Id: Main.hs,v 1.30 2001/04/02 16:10:05 rrt Exp $ +-- $Id: Main.hs,v 1.31 2001/07/23 23:08:04 ken Exp $ -- -- Program for converting .hsc files to .hs files, by converting the -- file into a C program which is run to generate the Haskell source. @@ -52,12 +52,12 @@ options = [ Option "I" [] (ReqArg (CompFlag . ("-I"++)) "DIR") "passed to the C compiler", Option "L" ["lflag"] (ReqArg LinkFlag "FLAG") "flag to pass to the linker", - Option "" ["no-compile"] (NoArg NoCompile) "stop after writing *_hsc_make.c", Option "i" ["include"] (ReqArg include "FILE") "as if placed in the source", Option "D" ["define"] (ReqArg define "NAME[=VALUE]") "as if placed in the source", Option "o" ["output"] (ReqArg Output "FILE") "name of main output file", Option "" ["help"] (NoArg Help) "display this help and exit", - Option "" ["version"] (NoArg Version) "output version information and exit"] + Option "" ["version"] (NoArg Version) "output version information and exit", + Option "" ["no-compile"] (NoArg NoCompile) "stop after writing *_hsc_make.c", main :: IO () main = do @@ -433,7 +433,7 @@ output flags name toks = do progName = outDir++outBase++"_hsc_make" ++ progNameSuffix outHName = outDir++outBase++"_hsc.h" outCName = outDir++outBase++"_hsc.c" - + let execProgName | null outDir = "./"++progName | otherwise = progName @@ -649,19 +649,20 @@ outTokenC (pos, key, arg) = "def" -> case arg of 's':'t':'r':'u':'c':'t':' ':_ -> "" 't':'y':'p':'e':'d':'e':'f':' ':_ -> "" - 'i':'n':'l':'i':'n':'e':' ':_ -> - outCLine pos++ - "#ifndef __GNUC__\n\ - \extern\n\ - \#endif\n"++ - header++ - "\n#ifndef __GNUC__\n\ - \;\n\ - \#else\n"++ - body++ - "\n#endif\n" + 'i':'n':'l':'i':'n':'e':' ':arg' -> + case span (\c -> c /= '{' && c /= '=') arg' of + (header, body) -> + outCLine pos++ + "#ifndef __GNUC__\n\ + \extern inline\n\ + \#endif\n"++ + header++ + "\n#ifndef __GNUC__\n\ + \;\n\ + \#else\n"++ + body++ + "\n#endif\n" _ -> outCLine pos++arg++"\n" - where (header, body) = span (\c -> c /= '{' && c /= '=') arg _ | conditional key -> outCLine pos++"#"++key++" "++arg++"\n" _ -> ""