Quickly added a command line option to allow you to specify flags to pass to the C/C++ compiler
This commit is contained in:
parent
cd36f383c9
commit
633a3dbbc5
14
Main.hs
14
Main.hs
|
@ -63,6 +63,7 @@ optionsNoWarnings =
|
|||
, Option [] ["help-warnings"] (NoArg optPrintWarningHelp)
|
||||
"print help about warning options"
|
||||
, Option ['k'] ["keep-temporaries"] (NoArg $ optKeepTemporaries) "keep temporary files"
|
||||
, Option ['f'] ["compiler-flags"] (ReqArg optCompilerFlags "FLAGS") "flags for C/C++ compiler"
|
||||
, Option [] ["run-indent"] (NoArg $ optRunIndent) "run indent on source before compilation (will full mode)"
|
||||
, Option [] ["frontend"] (ReqArg optFrontend "FRONTEND") "language frontend (options: occam, rain)"
|
||||
, Option [] ["mode"] (ReqArg optMode "MODE") "select mode (options: flowgraph, lex, parse, compile, post-c, full)"
|
||||
|
@ -111,6 +112,9 @@ optFrontend s ps
|
|||
_ -> dieIO (Nothing, "Unknown frontend: " ++ s)
|
||||
return $ ps { csFrontend = frontend }
|
||||
|
||||
optCompilerFlags :: String -> OptFunc
|
||||
optCompilerFlags flags ps = return $ ps { csCompilerFlags = flags }
|
||||
|
||||
optVerbose :: OptFunc
|
||||
optVerbose ps = return $ ps { csVerboseLevel = csVerboseLevel ps + 1 }
|
||||
|
||||
|
@ -252,19 +256,19 @@ compileFull inputFile moutputFile
|
|||
do sequence_ $ map noteFile [sFile, oFile, postCFile, postOFile, occFile]
|
||||
|
||||
-- Compile the C into assembly, and assembly into an object file
|
||||
exec $ cAsmCommand cFile sFile
|
||||
exec $ cCommand sFile oFile
|
||||
exec $ cAsmCommand cFile sFile (csCompilerFlags optsPS)
|
||||
exec $ cCommand sFile oFile (csCompilerFlags optsPS)
|
||||
-- Analyse the assembly for stack sizes, and output a
|
||||
-- "post" C file
|
||||
withOutputFile postCFile $ postCAnalyse sFile
|
||||
-- Compile this new "post" C file into an object file
|
||||
exec $ cCommand postCFile postOFile
|
||||
exec $ cCommand postCFile postOFile (csCompilerFlags optsPS)
|
||||
-- Link the object files into a binary
|
||||
exec $ cLinkCommand [oFile, postOFile] outputFile
|
||||
exec $ cLinkCommand [oFile, postOFile] outputFile (csCompilerFlags optsPS)
|
||||
|
||||
-- For C++, just compile the source file directly into a binary
|
||||
BackendCPPCSP ->
|
||||
exec $ cxxCommand cFile outputFile
|
||||
exec $ cxxCommand cFile outputFile (csCompilerFlags optsPS)
|
||||
|
||||
_ -> dieReport (Nothing, "Cannot use specified backend: "
|
||||
++ show (csBackend optsPS)
|
||||
|
|
|
@ -8,14 +8,18 @@ import Paths
|
|||
tockIncludeFlags :: String
|
||||
tockIncludeFlags = "-I" ++ pkgIncludeDir
|
||||
|
||||
cCommand :: String -> String -> String
|
||||
cCommand inp out = "@CC@ @TOCK_CFLAGS@ " ++ tockIncludeFlags ++ " -c -o " ++ out ++ " " ++ inp
|
||||
cCommand :: String -> String -> String -> String
|
||||
cCommand inp out extra = "@CC@ @TOCK_CFLAGS@ " ++ tockIncludeFlags ++ " -c -o " ++ out ++ " " ++ inp
|
||||
++ " " ++ extra
|
||||
|
||||
cAsmCommand :: String -> String -> String
|
||||
cAsmCommand inp out = "@CC@ @TOCK_CFLAGS@ -S -o " ++ out ++ " " ++ inp
|
||||
cAsmCommand :: String -> String -> String -> String
|
||||
cAsmCommand inp out extra = "@CC@ @TOCK_CFLAGS@ -S -o " ++ out ++ " " ++ inp ++
|
||||
" " ++ extra
|
||||
|
||||
cLinkCommand :: [String] -> String -> String
|
||||
cLinkCommand files out = "@CC@ @TOCK_CFLAGS@ -o " ++ out ++ " " ++ (concat (intersperse " " files)) ++ " @TOCK_CLDFLAGS@"
|
||||
cLinkCommand :: [String] -> String -> String -> String
|
||||
cLinkCommand files out extra = "@CC@ @TOCK_CFLAGS@ -o " ++ out ++ " " ++ (concat (intersperse " " files)) ++ " @TOCK_CLDFLAGS@"
|
||||
++ " " ++ extra
|
||||
|
||||
cxxCommand :: String -> String -> String
|
||||
cxxCommand inp out = "@CXX@ @TOCK_CXXFLAGS@ " ++ tockIncludeFlags ++ " -o " ++ out ++ " " ++ inp ++ " @TOCK_CXXLDFLAGS@"
|
||||
cxxCommand :: String -> String -> String -> String
|
||||
cxxCommand inp out extra = "@CXX@ @TOCK_CXXFLAGS@ " ++ tockIncludeFlags ++ " -o " ++ out ++ " " ++ inp ++ " @TOCK_CXXLDFLAGS@"
|
||||
++ " " ++ extra
|
||||
|
|
|
@ -98,6 +98,7 @@ data CompState = CompState {
|
|||
csMode :: CompMode,
|
||||
csBackend :: CompBackend,
|
||||
csFrontend :: CompFrontend,
|
||||
csCompilerFlags :: String,
|
||||
csSanityCheck :: Bool,
|
||||
csUsageChecking :: Bool,
|
||||
csVerboseLevel :: Int,
|
||||
|
@ -137,6 +138,7 @@ emptyState = CompState {
|
|||
csMode = ModeFull,
|
||||
csBackend = BackendC,
|
||||
csFrontend = FrontendOccam,
|
||||
csCompilerFlags = "",
|
||||
csSanityCheck = False,
|
||||
csUsageChecking = True,
|
||||
csVerboseLevel = 0,
|
||||
|
|
Loading…
Reference in New Issue
Block a user