Added a command-line option to change how much stack the unknown functions are given

This commit is contained in:
Neil Brown 2009-03-26 22:49:38 +00:00
parent eb99480484
commit 6e66cf7521
3 changed files with 12 additions and 7 deletions

View File

@ -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 }

View File

@ -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)

View File

@ -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,