Added some quick hacks to make recursive PROCs work

This is along the lines of the Tock ticket.  cgtest90 (recursive FUNCTIONs) now passes, but cgtest91 (recursive PROCs) doesn't, because it uses barriers.
This commit is contained in:
Neil Brown 2009-03-24 00:14:14 +00:00
parent e08197bbef
commit e269efe388

View File

@ -39,6 +39,7 @@ module GenerateC
import Data.Char import Data.Char
import Data.Generics import Data.Generics
import Data.List import Data.List
import qualified Data.Map as Map
import Data.Maybe import Data.Maybe
import qualified Data.Set as Set import qualified Data.Set as Set
import Control.Monad.State import Control.Monad.State
@ -172,7 +173,11 @@ cgenTopLevel s
(listify (const True :: A.Specification -> Bool) s) (listify (const True :: A.Specification -> Bool) s)
sequence_ [tell ["extern int ", nameString n, "_stack_size;\n"] sequence_ [tell ["extern int ", nameString n, "_stack_size;\n"]
| n <- Set.toList $ csParProcs cs] | n <- (Set.toList $ csParProcs cs)
++ [A.Name emptyMeta n | A.NameDef
{A.ndName = n
,A.ndSpecType=A.Proc _ (_,A.Recursive) _ _
} <- Map.elems $ csNames cs]]
tell ["extern int "] tell ["extern int "]
genName tlpName genName tlpName
tell ["_stack_size;\n"] tell ["_stack_size;\n"]
@ -1553,9 +1558,10 @@ realFormals (A.Formal am t n)
-- This will use ProcGetParam if the Proc is in csParProcs, or the normal C -- This will use ProcGetParam if the Proc is in csParProcs, or the normal C
-- calling convention otherwise. -- calling convention otherwise.
genProcSpec :: A.Name -> A.SpecType -> Bool -> CGen () genProcSpec :: A.Name -> A.SpecType -> Bool -> CGen ()
genProcSpec n (A.Proc _ (sm, _) fs p) forwardDecl genProcSpec n (A.Proc _ (sm, rm) fs p) forwardDecl
= do cs <- getCompState = do cs <- getCompState
let (header, params) = if n `Set.member` csParProcs cs let (header, params) = if n `Set.member` csParProcs cs
|| rm == A.Recursive
then (genParHeader, genParParams) then (genParHeader, genParParams)
else (genNormalHeader, return ()) else (genNormalHeader, return ())
header header
@ -2010,11 +2016,19 @@ withIf cond body
--{{{ proc call --{{{ proc call
cgenProcCall :: A.Name -> [A.Actual] -> CGen () cgenProcCall :: A.Name -> [A.Actual] -> CGen ()
cgenProcCall n as cgenProcCall n as
= do genName n = do A.Proc _ (_, rm) _ _ <- specTypeOfName n
tell [" (wptr"] case rm of
(A.Proc _ _ fs _) <- specTypeOfName n -- This is rather inefficient, because if a recursive PROC is called
call genActuals fs as -- anywhere (from other processes as well as from itself), it will
tell [");\n"] -- be done in a PAR.
A.Recursive ->
let m = A.nameMeta n
in call genPar A.PlainPar $ A.Only m $ A.ProcCall m n as
_ -> do genName n
tell [" (wptr"]
(A.Proc _ _ fs _) <- specTypeOfName n
call genActuals fs as
tell [");\n"]
--}}} --}}}
--{{{ intrinsic procs --{{{ intrinsic procs
cgenIntrinsicProc :: Meta -> String -> [A.Actual] -> CGen () cgenIntrinsicProc :: Meta -> String -> [A.Actual] -> CGen ()