Changed the asm-analysis to only generate stack-sizes for PROCs, and not non-PROCs or external PROCs

This just about works, but it allocates the usual 512 bytes for all external PROCs being called, rather than using the actual stack_size for those external PROCs (this causes popcorn to overflow the stack if left with the default 512 bytes)
This commit is contained in:
Neil Brown 2009-04-02 20:04:21 +00:00
parent dbc1b461a4
commit ca332a0925
3 changed files with 28 additions and 11 deletions

View File

@ -453,8 +453,10 @@ postCAnalyse :: String -> ((Handle, Handle), String) -> PassM ()
postCAnalyse fn ((outHandle, _), _)
= do asm <- liftIO $ readFile fn
names <- needStackSizes
progress "Analysing assembly"
output <- analyseAsm asm
output <- analyseAsm (Just $ map A.nameName names) asm
liftIO $ hPutStr outHandle output

View File

@ -186,8 +186,8 @@ addCalls unknownSize
return $ localStack + maximum (0 : calledStacks)
-- | Analyse assembler and return C source defining sizes.
analyseAsm :: String -> PassM String
analyseAsm asm
analyseAsm :: Maybe [String] -> String -> PassM String
analyseAsm mprocs asm
= do let stream = parseAsm asm
veryDebug $ pshow stream
cs <- getCompState
@ -196,7 +196,11 @@ analyseAsm asm
debug $ concat [printf " %-40s %5d %5d %s\n"
func (fiStack fi) (fiTotalStack fi)
(concat $ intersperse " " $ Set.toList $ fiCalls fi)
| (func, fi) <- Map.toList info]
| (func, fi) <- Map.toList $ filterNames info]
let lines = ["const int " ++ func ++ "_stack_size = " ++ show (fiTotalStack fi) ++ ";\n"
| (func, fi) <- Map.toList info]
| (func, fi) <- Map.toList $ filterNames info]
return $ concat lines
where
filterNames = case mprocs of
Nothing -> id
Just m -> (`Map.intersection` (Map.fromList (zip m (repeat ()))))

View File

@ -34,6 +34,7 @@ module GenerateC
, genName
, genRightB
, genStatic
, needStackSizes
, justOnly
, withIf
) where
@ -159,6 +160,20 @@ cgenOps = GenOps {
generateC :: (Handle, Handle) -> String -> A.AST -> PassM ()
generateC = generate cgenOps
needStackSizes :: (CSMR m, Die m) => m [A.Name]
needStackSizes
= do cs <- getCompState
main <- if csHasMain cs
then tlpInterface >>* fst >>* singleton
else return []
return $ nub $ (Set.toList $ csParProcs cs `Set.difference`
Set.fromList (map (A.Name emptyMeta . fst) (csExternals cs)))
++ [A.Name emptyMeta n
| A.NameDef {A.ndName = n
,A.ndSpecType=A.Proc _ (_,A.Recursive) _ _
} <- Map.elems $ csNames cs]
++ main
cgenTopLevel :: String -> A.AST -> CGen ()
cgenTopLevel headerName s
= do tell ["#define occam_INT_size ", show cIntSize,"\n"]
@ -180,13 +195,9 @@ cgenTopLevel headerName s
sequence_ [tell ["#include \"", usedFile, ".tock.h\"\n"]
| usedFile <- Set.toList $ csUsedFiles cs]
nss <- needStackSizes
sequence_ [tell ["extern int "] >> genName n >> tell ["_stack_size;\n"]
| n <- (Set.toList $ csParProcs cs `Set.difference`
Set.fromList (map (A.Name emptyMeta . fst) (csExternals cs)))
++ [A.Name emptyMeta n | A.NameDef
{A.ndName = n
,A.ndSpecType=A.Proc _ (_,A.Recursive) _ _
} <- Map.elems $ csNames cs]]
| n <- nss]
when (csHasMain cs) $ do
(tlpName, tlpChans) <- tlpInterface