diff --git a/Main.hs b/Main.hs index d02270a..1aef811 100644 --- a/Main.hs +++ b/Main.hs @@ -102,6 +102,21 @@ getOpts argv = (_,_,errs) -> error (concat errs ++ usageInfo header options) where header = "Usage: tock [OPTION...] SOURCEFILE" +writeOccamWrapper :: Handle -> IO () +writeOccamWrapper h = do + write "#INCLUDE \"cifccsp.inc\"\n" + write "#PRAGMA EXTERNAL \"PROC C.tock.main.init (INT raddr, CHAN BYTE in?, out!, err!) = 0\"\n" + write "#PRAGMA EXTERNAL \"PROC C.tock.main.free (VAL INT raddr) = 0\"\n" + write "PROC kroc.main (CHAN BYTE in?, out!, err!)\n" + write " INT addr:\n" + write " SEQ\n" + write " C.tock.main.init (addr, in?, out!, err!)\n" + write " cifccsp.startprocess (addr)\n" + write " C.tock.main.free (addr)\n" + write ":\n" + where + write = hPutStr h + main :: IO () main = do argv <- getArgs @@ -138,7 +153,10 @@ main = do postCAnalyse (tempPath ++ ".s") tempHandlePost liftIO $ hClose tempHandlePost exec $ cCommand tempPathPost (tempPathPost ++ ".o") - exec $ krocLinkCommand (tempPath ++ ".o") (tempPathPost ++ ".o") destBin + (tempPathOcc, tempHandleOcc) <- liftIO $ openTempFile "." "tock-temp.occ" + liftIO $ writeOccamWrapper tempHandleOcc + liftIO $ hClose tempHandleOcc + exec $ krocLinkCommand tempPathOcc [(tempPath ++ ".o"),(tempPathPost ++ ".o")] destBin BackendCPPCSP -> exec $ cxxCommand tempPath destBin diff --git a/Makefile.am b/Makefile.am index 4b93a41..3a1de77 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,12 +24,13 @@ TOCK_CXXFLAGS = -O2 -g -Wall -ggdb3 -I. CompilerCommands.hs: Makefile echo -e 'module CompilerCommands where\n' > CompilerCommands.hs echo -e '--This file is auto-generated by Makefile.am\n' >> CompilerCommands.hs + echo -e 'import Data.List\n' >> CompilerCommands.hs echo -e 'cCommand :: String -> String -> String\n' >> CompilerCommands.hs echo -e 'cCommand inp out = "$(CC) $(TOCK_CFLAGS) -x c -c -o " ++ out ++ " " ++ inp\n' >> CompilerCommands.hs echo -e 'cAsmCommand :: String -> String -> String\n' >> CompilerCommands.hs echo -e 'cAsmCommand inp out = "$(CC) $(TOCK_CFLAGS) -x c -S -o " ++ out ++ " " ++ inp\n' >> CompilerCommands.hs - echo -e 'krocLinkCommand :: String -> String -> String -> String\n' - echo -e 'krocLinkCommand fileA fileB out = "kroc -o " ++ out ++ " kroc-wrapper.occ " ++ fileA ++ " " ++ fileB ++ " -lcif"\n' >> CompilerCommands.hs + echo -e 'krocLinkCommand :: String -> [String] -> String -> String\n' + echo -e 'krocLinkCommand wrapper files out = "kroc -o " ++ out ++ " " ++ wrapper ++ " " ++ (concat (intersperse " " files)) ++ " -lcif"\n' >> CompilerCommands.hs echo -e 'cxxCommand :: String -> String -> String\n' >> CompilerCommands.hs echo -e 'cxxCommand inp out = "$(CXX) $(TOCK_CXXFLAGS) -x c++ -o " ++ out ++ " " ++ inp\n' >> CompilerCommands.hs diff --git a/kroc-wrapper.occ b/kroc-wrapper.occ deleted file mode 100644 index 044c782..0000000 --- a/kroc-wrapper.occ +++ /dev/null @@ -1,28 +0,0 @@ --- KRoC wrapper to run Tock-generated CIF program --- Copyright (C) 2007 University of Kent --- --- This library is free software; you can redistribute it and/or modify it --- under the terms of the GNU Lesser General Public License as published by --- the Free Software Foundation, either version 2 of the License, or (at --- your option) any later version. --- --- This library is distributed in the hope that it will be useful, but --- WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser --- General Public License for more details. --- --- You should have received a copy of the GNU Lesser General Public License --- along with this library. If not, see . - -#INCLUDE "cifccsp.inc" - -#PRAGMA EXTERNAL "PROC C.tock.main.init (INT raddr, CHAN BYTE in?, out!, err!) = 0" -#PRAGMA EXTERNAL "PROC C.tock.main.free (VAL INT raddr) = 0" - -PROC kroc.main (CHAN BYTE in?, out!, err!) - INT addr: - SEQ - C.tock.main.init (addr, in?, out!, err!) - cifccsp.startprocess (addr) - C.tock.main.free (addr) -: