Split Fugu .h and .c generation
authorDavid Cock <david.cock@inf.ethz.ch>
Tue, 1 Sep 2015 15:07:12 +0000 (17:07 +0200)
committerDavid Cock <david.cock@inf.ethz.ch>
Tue, 1 Sep 2015 15:07:12 +0000 (17:07 +0200)
Doing them in one step leads to a race in a parallel make, with Fugu being
run twice, and clobbering its previous output.

Signed-off-by: David Cock <david.cock@inf.ethz.ch>

errors/Hakefile
hake/RuleDefs.hs
tools/fugu/Main.lhs

index 6b6d503..e2c40ee 100644 (file)
@@ -10,4 +10,5 @@
 -- 
 --------------------------------------------------------------------------
 
-[ fuguFile (options arch) "errno" | arch <- allArchitectures ]
+[ fuguHFile (options arch) "errno" | arch <- allArchitectures ] ++
+[ fuguCFile (options arch) "errno" | arch <- allArchitectures ]
index c9d4acc..34e1f85 100644 (file)
@@ -703,19 +703,28 @@ flounderRules opts args csrcs =
 --
 -- Build a Fugu library
 --
-fuguFile :: Options -> String -> HRule
-fuguFile opts file =
+fuguCFile :: Options -> String -> HRule
+fuguCFile opts file =
     let arch = optArch opts
         cfile = file ++ ".c"
-        hfile = "/include/errors/" ++ file ++ ".h"
     in
-      Rules [ Rule [In InstallTree "tools" "/bin/fugu",
-                    In SrcTree "src" (file++".fugu"),
-                    Out arch hfile,
-                    Out arch cfile ],
+      Rules [ Rule [ In InstallTree "tools" "/bin/fugu",
+                     In SrcTree "src" (file++".fugu"),
+                     Str "-c",
+                     Out arch cfile ],
               compileGeneratedCFile opts cfile
          ]
 
+fuguHFile :: Options -> String -> HRule
+fuguHFile opts file =
+    let arch = optArch opts
+        hfile = "/include/errors/" ++ file ++ ".h"
+    in
+      Rule [ In InstallTree "tools" "/bin/fugu",
+             In SrcTree "src" (file++".fugu"),
+             Str "-h",
+             Out arch hfile ]
+
 --
 -- Build a Pleco library
 --
index cf27ad1..736ab39 100644 (file)
 > import FuguBackend
 > import Parser
 
+> parseError :: Show a => a -> IO ()
+> parseError err = do
+>   hPutStrLn stderr "parse error at: "
+>   hPutStrLn stderr (show err)
+>   exitWith (ExitFailure 1)
 
 > main :: IO ()
 > main = do
->        argv <- System.Environment.getArgs
->        case argv of
->          [ inF, hdrF, codeF ] -> do
->                         input <- Parser.parse inF
->                         case input of
->                           Left err -> do
->                                       hPutStrLn stderr "parse error at: "
->                                       hPutStrLn stderr (show err) 
->                                       exitWith (ExitFailure 1)
->                           Right ast -> do
->                                        let macro = map toUpper (takeBaseName hdrF) ++ "_BARRELFISH__"
->                                        let gen = mkStdGen 1 
->                                        let code = compile (backendCode gen ast)
->                                        let header_ = compile (backendHeader gen ast)
->                                        let header = header_ { prototypes = prototypes code 
->                                                                            `Map.union` 
->                                                                            prototypes header_ }
->                                        fileH <- openFile hdrF WriteMode
->                                        fileC <- openFile codeF WriteMode
->                                        let pre = "#ifndef " ++ macro ++ "\n" ++
->                                                  "#define " ++ macro ++ "\n"
->                                        let post = "\n#endif // " ++ macro
->                                        hPutStr fileH pre
->                                        hPutStr fileH $ show $ header
->                                        hPutStrLn fileH post
->                                        hClose fileH
-
->                                        hPutStr fileC "#include <errors/errno.h>\n"
->                                        hPutStr fileC "#include <assert.h>\n"
->                                        hPutStrLn fileC $ show $ code { prototypes= Map.empty,
->                                                                      functions = Map.filterWithKey (\n _ -> n /= "err_no" && 
->                                                                                                         n /= "err_is_fail") $ 
->                                                                                                         functions code }
->                                        hClose fileC
->          otherwise -> do
->                  hPutStrLn stderr "Usage: fugu input.fugu output.h output.c"
->                  exitWith (ExitFailure 1)
+>   argv <- System.Environment.getArgs
+>   case argv of
+>       [ inF, "-h", hdrF ] -> do
+>           input <- Parser.parse inF
+>           case input of
+>               Left err -> parseError err
+>               Right ast -> do
+>                   let macro = "__" ++
+>                               map toUpper (takeBaseName inF) ++
+>                               "_BARRELFISH__"
+>                   let gen = mkStdGen 1
+>                   let code = compile (backendCode gen ast)
+>                   let header_ = compile (backendHeader gen ast)
+>                   let header = header_ { prototypes = prototypes code
+>                                                       `Map.union`
+>                                                       prototypes header_ }
+>                   fileH <- openFile hdrF WriteMode
+>                   let pre = "#ifndef " ++ macro ++ "\n" ++
+>                             "#define " ++ macro ++ "\n"
+>                   let post = "\n#endif // " ++ macro
+>                   hPutStr fileH pre
+>                   hPutStr fileH $ show $ header
+>                   hPutStrLn fileH post
+>                   hClose fileH
+>       [ inF, "-c", codeF ] -> do
+>           input <- Parser.parse inF
+>           case input of
+>               Left err -> parseError err
+>               Right ast -> do
+>                   let gen = mkStdGen 1
+>                   let code = compile (backendCode gen ast)
+>                   fileC <- openFile codeF WriteMode
+>                   hPutStr fileC "#include <errors/errno.h>\n"
+>                   hPutStr fileC "#include <assert.h>\n"
+>                   hPutStrLn fileC $ show $
+>                       code { prototypes = Map.empty,
+>                              functions = Map.filterWithKey
+>                                               (\n _ -> n /= "err_no" &&
+>                                                        n /= "err_is_fail") $
+>                                               functions code }
+>                   hClose fileC
+>       otherwise -> do
+>           hPutStrLn stderr
+>               "Usage: fugu input.fugu (-h output.h | -c output.c)"
+>           exitWith (ExitFailure 1)