From 1343954c2f0f1fdd57f20f0a5fa03d5b5aecd6a4 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sat, 21 Mar 2009 18:25:09 +0000 Subject: [PATCH] Added an option to automatically run indent on C/C++ source before running GCC This option is very handy when debugging the C/C++ output of Tock when GCC gives a compiler error. --- Main.hs | 6 ++++++ cgtests.mk | 2 +- data/CompState.hs | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Main.hs b/Main.hs index e29868d..6d91e3c 100644 --- a/Main.hs +++ b/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 [] ["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, parse, compile, post-c, full)" , Option ['o'] ["output"] (ReqArg optOutput "FILE") "output file (default \"-\")" @@ -115,6 +116,9 @@ optVerbose ps = return $ ps { csVerboseLevel = csVerboseLevel ps + 1 } optKeepTemporaries :: OptFunc optKeepTemporaries ps = return $ ps { csKeepTemporaries = True } +optRunIndent :: OptFunc +optRunIndent ps = return $ ps { csRunIndent = True } + optOutput :: String -> OptFunc optOutput s ps = return $ ps { csOutputFile = s } @@ -235,6 +239,8 @@ compileFull inputFile moutputFile let cFile = outputFile ++ extension withOutputFile cFile $ compile ModeCompile inputFile noteFile cFile + when (csRunIndent optsPS) $ + exec $ "indent " ++ cFile case csBackend optsPS of BackendC -> diff --git a/cgtests.mk b/cgtests.mk index cb2b12d..d555e5e 100644 --- a/cgtests.mk +++ b/cgtests.mk @@ -12,7 +12,7 @@ checkout: svn co http://projects.cs.kent.ac.uk/projects/kroc/svn/kroc/trunk/tests/cgtests %: %.occ - ./tock -vk --backend=$(BACKEND) -o $@ $< + ./tock -vk --backend=$(BACKEND) --run-indent -o $@ $< run: $(tests) cd cgtests && ./run-tests diff --git a/data/CompState.hs b/data/CompState.hs index 7c78593..1d6234c 100644 --- a/data/CompState.hs +++ b/data/CompState.hs @@ -104,6 +104,7 @@ data CompState = CompState { csOutputFile :: String, csKeepTemporaries :: Bool, csEnabledWarnings :: Set WarningType, + csRunIndent :: Bool, csClassicOccamMobility :: Bool, -- Set by preprocessor @@ -147,6 +148,7 @@ emptyState = CompState { , WarnUnknownPreprocessorDirective , WarnUnusedVariable], -- TODO enable WarnUninitialisedVariable by default + csRunIndent = False, csClassicOccamMobility = False, csCurrentFile = "none",