From 6e66cf7521e4bca2d33e7f59617a6766dd7e8ce8 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Thu, 26 Mar 2009 22:49:38 +0000 Subject: [PATCH] Added a command-line option to change how much stack the unknown functions are given --- Main.hs | 5 +++++ backends/AnalyseAsm.hs | 12 +++++------- data/CompState.hs | 2 ++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Main.hs b/Main.hs index abb9f65..f970cc0 100644 --- a/Main.hs +++ b/Main.hs @@ -73,6 +73,8 @@ optionsNoWarnings = , Option [] ["sanity-check"] (ReqArg optSanityCheck "SETTING") "internal sanity check (options: on, off)" , Option [] ["occam2-mobility"] (ReqArg optClassicOccamMobility "SETTING") "occam2 implicit mobility (EXPERIMENTAL) (options: on, off)" , Option [] ["usage-checking"] (ReqArg optUsageChecking "SETTING") "usage checking (options: on, off)" + , Option [] ["unknown-stack-size"] (ReqArg optStackSize "BYTES") + "stack amount to allocate for unknown C functions" , Option ['v'] ["verbose"] (NoArg $ optVerbose) "be more verbose (use multiple times for more detail)" ] @@ -130,6 +132,9 @@ optKeepTemporaries ps = return $ ps { csKeepTemporaries = True } optRunIndent :: OptFunc optRunIndent ps = return $ ps { csRunIndent = True } +optStackSize :: String -> OptFunc +optStackSize s ps = return $ ps { csUnknownStackSize = read s } + optOutput :: String -> OptFunc optOutput s ps = return $ ps { csOutputFile = s } diff --git a/backends/AnalyseAsm.hs b/backends/AnalyseAsm.hs index e81a3d5..3eb6a0e 100644 --- a/backends/AnalyseAsm.hs +++ b/backends/AnalyseAsm.hs @@ -37,6 +37,7 @@ import qualified Data.Set as Set import Numeric (readDec) import Text.Printf +import CompState import Errors import Pass import PrettyShow @@ -148,10 +149,6 @@ collectInfo ais = collectInfo' ais "" modify $ Map.insert func fi' collectInfo' ais func' --- | Stack size for unknown functions. -unknownSize :: Int -unknownSize = 512 - -- | Additional stack size to give to all functions. -- This is necessary because CCSP does odd things with the provided stack -- size; it doesn't calculate the space that it needs for the arguments. @@ -159,8 +156,8 @@ baseStackSize :: Int baseStackSize = 32 -- | Add the stack sizes for called functions to their callers. -addCalls :: AAM () -addCalls +addCalls :: Int -> AAM () +addCalls unknownSize = do fmap <- get sequence_ $ map computeStack (Map.keys fmap) where @@ -193,7 +190,8 @@ analyseAsm :: String -> PassM String analyseAsm asm = do let stream = parseAsm asm veryDebug $ pshow stream - info <- execStateT (collectInfo stream >> addCalls) Map.empty + cs <- getCompState + info <- execStateT (collectInfo stream >> addCalls (csUnknownStackSize cs)) Map.empty debug $ "Analysed function information:" debug $ concat [printf " %-40s %5d %5d %s\n" func (fiStack fi) (fiTotalStack fi) diff --git a/data/CompState.hs b/data/CompState.hs index 85892c9..59e8be5 100644 --- a/data/CompState.hs +++ b/data/CompState.hs @@ -108,6 +108,7 @@ data CompState = CompState { csEnabledWarnings :: Set WarningType, csRunIndent :: Bool, csClassicOccamMobility :: Bool, + csUnknownStackSize :: Int, -- Set by preprocessor csCurrentFile :: String, @@ -155,6 +156,7 @@ emptyState = CompState { -- TODO enable WarnUninitialisedVariable by default csRunIndent = False, csClassicOccamMobility = False, + csUnknownStackSize = 512, csCurrentFile = "none", csUsedFiles = Set.empty,