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