Changed the C and C++ channel arrays to be actual arrays of channels, not arrays of channel pointers as they were before.
The effects of this change will not be fully tested until further tests have been written (especially for genVariable).
This commit is contained in:
parent
7ef16c3b6c
commit
b4ac249367
|
@ -373,6 +373,8 @@ cgenType ops (A.Array _ t)
|
||||||
tell ["*"]
|
tell ["*"]
|
||||||
cgenType _ (A.Record n) = genName n
|
cgenType _ (A.Record n) = genName n
|
||||||
-- UserProtocol -- not used
|
-- UserProtocol -- not used
|
||||||
|
-- Channels are of type "Channel", but channel-ends are of type "Channel*"
|
||||||
|
cgenType _ (A.Chan A.DirUnknown _ t) = tell ["Channel"]
|
||||||
cgenType _ (A.Chan _ _ t) = tell ["Channel*"]
|
cgenType _ (A.Chan _ _ t) = tell ["Channel*"]
|
||||||
-- Counted -- not used
|
-- Counted -- not used
|
||||||
-- Any -- not used
|
-- Any -- not used
|
||||||
|
@ -676,9 +678,9 @@ MYREC r: MYREC r; MYREC *r; MYREC *r;
|
||||||
CHAN OF INT c: Channel c; Channel *c;
|
CHAN OF INT c: Channel c; Channel *c;
|
||||||
c &c c
|
c &c c
|
||||||
|
|
||||||
[10]CHAN OF INT cs: Channel **cs; Channel **cs;
|
[10]CHAN OF INT cs: Channel *cs; Channel *cs;
|
||||||
cs cs cs
|
cs cs cs
|
||||||
cs[i] cs[i] cs[i]
|
cs[i] &cs[i] &cs[i]
|
||||||
|
|
||||||
I suspect there's probably a nicer way of doing this, but as a translation of
|
I suspect there's probably a nicer way of doing this, but as a translation of
|
||||||
the above table this isn't too horrible...
|
the above table this isn't too horrible...
|
||||||
|
@ -699,14 +701,10 @@ cgenVariable' :: GenOps -> Bool -> A.Variable -> CGen ()
|
||||||
cgenVariable' ops checkValid v
|
cgenVariable' ops checkValid v
|
||||||
= do am <- accessAbbrevMode v
|
= do am <- accessAbbrevMode v
|
||||||
t <- typeOfVariable v
|
t <- typeOfVariable v
|
||||||
let isSub = case v of
|
|
||||||
A.Variable _ _ -> False
|
|
||||||
A.SubscriptedVariable _ _ _ -> True
|
|
||||||
A.DirectedVariable _ _ _ -> False
|
|
||||||
|
|
||||||
let prefix = case (am, t) of
|
let prefix = case (am, t) of
|
||||||
(_, A.Array _ _) -> ""
|
(_, A.Array _ _) -> ""
|
||||||
(A.Original, A.Chan {}) -> if isSub then "" else "&"
|
(A.Original, A.Chan A.DirUnknown _ _) -> "&"
|
||||||
|
(A.Original, A.Chan _ _ _) -> ""
|
||||||
(A.Abbrev, A.Chan {}) -> ""
|
(A.Abbrev, A.Chan {}) -> ""
|
||||||
(A.Original, A.Record _) -> "&"
|
(A.Original, A.Record _) -> "&"
|
||||||
(A.Abbrev, A.Record _) -> ""
|
(A.Abbrev, A.Record _) -> ""
|
||||||
|
@ -1171,11 +1169,6 @@ cdeclareType ops t = call genType ops t
|
||||||
|
|
||||||
-- | Generate a declaration of a new variable.
|
-- | Generate a declaration of a new variable.
|
||||||
cgenDeclaration :: GenOps -> A.Type -> A.Name -> CGen ()
|
cgenDeclaration :: GenOps -> A.Type -> A.Name -> CGen ()
|
||||||
-- Channels are of type "Channel", but channel-ends are of type "Channel*"
|
|
||||||
cgenDeclaration ops (A.Chan A.DirUnknown _ _) n
|
|
||||||
= do tell ["Channel "]
|
|
||||||
genName n
|
|
||||||
tell [";"]
|
|
||||||
cgenDeclaration ops (A.Array ds t) n
|
cgenDeclaration ops (A.Array ds t) n
|
||||||
= do call declareType ops t
|
= do call declareType ops t
|
||||||
tell [" "]
|
tell [" "]
|
||||||
|
@ -1226,24 +1219,10 @@ cgenArraySizesLiteral ops ds
|
||||||
cdeclareInit :: GenOps -> Meta -> A.Type -> A.Variable -> Maybe (CGen ())
|
cdeclareInit :: GenOps -> Meta -> A.Type -> A.Variable -> Maybe (CGen ())
|
||||||
cdeclareInit ops _ (A.Chan A.DirUnknown _ _) var
|
cdeclareInit ops _ (A.Chan A.DirUnknown _ _) var
|
||||||
= Just $ do tell ["ChanInit("]
|
= Just $ do tell ["ChanInit("]
|
||||||
call genVariable ops var
|
call genVariableUnchecked ops var
|
||||||
tell [");"]
|
tell [");"]
|
||||||
cdeclareInit ops m t@(A.Array ds t') var
|
cdeclareInit ops m t@(A.Array ds t') var
|
||||||
= Just $ do init <- case t' of
|
= Just $ do init <- return (\sub -> call declareInit ops m t' (sub var))
|
||||||
A.Chan {} ->
|
|
||||||
do A.Specification _ store _ <- makeNonceVariable "storage" m (A.Array ds A.Int) A.VariableName A.Original
|
|
||||||
let storeV = A.Variable m store
|
|
||||||
tell ["Channel "]
|
|
||||||
genName store
|
|
||||||
call genFlatArraySize ops ds
|
|
||||||
tell [";\n"]
|
|
||||||
call declareArraySizes ops ds store
|
|
||||||
return (\sub -> Just $ do call genVariable ops (sub var)
|
|
||||||
tell [" = &"]
|
|
||||||
call genVariable ops (sub storeV)
|
|
||||||
tell [";\n"]
|
|
||||||
doMaybe $ call declareInit ops m t' (sub var))
|
|
||||||
_ -> return (\sub -> call declareInit ops m t' (sub var))
|
|
||||||
call genOverArray ops m var init
|
call genOverArray ops m var init
|
||||||
cdeclareInit ops m rt@(A.Record _) var
|
cdeclareInit ops m rt@(A.Record _) var
|
||||||
= Just $ do fs <- recordFields m rt
|
= Just $ do fs <- recordFields m rt
|
||||||
|
|
|
@ -85,8 +85,6 @@ import Pass
|
||||||
import ShowCode
|
import ShowCode
|
||||||
import TLP
|
import TLP
|
||||||
import Types
|
import Types
|
||||||
import Utils
|
|
||||||
|
|
||||||
|
|
||||||
--{{{ generator ops
|
--{{{ generator ops
|
||||||
-- | Operations for the C++CSP backend.
|
-- | Operations for the C++CSP backend.
|
||||||
|
@ -697,36 +695,12 @@ cppgenDeclaration ops t n
|
||||||
genName n
|
genName n
|
||||||
tell [";"]
|
tell [";"]
|
||||||
|
|
||||||
-- | Changed because of channel arrays.
|
-- | Changed because we don't need any initialisation in C++
|
||||||
cppdeclareInit :: GenOps -> Meta -> A.Type -> A.Variable -> Maybe (CGen ())
|
cppdeclareInit :: GenOps -> Meta -> A.Type -> A.Variable -> Maybe (CGen ())
|
||||||
cppdeclareInit ops m t@(A.Array ds t') var
|
|
||||||
= Just $ do init <- case t' of
|
|
||||||
A.Chan {} ->
|
|
||||||
return (\sub -> Just $ do call genVariable ops (sub var)
|
|
||||||
tell [" = new "]
|
|
||||||
call declareType ops t'
|
|
||||||
tell [";\n"]
|
|
||||||
doMaybe $ call declareInit ops m t' (sub var))
|
|
||||||
|
|
||||||
_ -> return (\sub -> call declareInit ops m t' (sub var))
|
|
||||||
call genOverArray ops m var init
|
|
||||||
|
|
||||||
cppdeclareInit _ _ _ _ = Nothing
|
cppdeclareInit _ _ _ _ = Nothing
|
||||||
|
|
||||||
-- | Changed to free channel arrays.
|
-- | Changed because we don't need any de-initialisation in C++, regardless of whether C does.
|
||||||
cppdeclareFree :: GenOps -> Meta -> A.Type -> A.Variable -> Maybe (CGen ())
|
cppdeclareFree :: GenOps -> Meta -> A.Type -> A.Variable -> Maybe (CGen ())
|
||||||
cppdeclareFree ops m t@(A.Array ds t') var
|
|
||||||
= Just $ do free <- case t' of
|
|
||||||
A.Chan {} ->
|
|
||||||
return (\sub -> Just $ do tell ["delete "]
|
|
||||||
call genVariable ops (sub var)
|
|
||||||
tell [";\n"]
|
|
||||||
--doMaybe $ call declareFree ops m t' (sub var)
|
|
||||||
)
|
|
||||||
|
|
||||||
_ -> return (\sub -> call declareFree ops m t' (sub var))
|
|
||||||
call genOverArray ops m var free
|
|
||||||
|
|
||||||
cppdeclareFree _ _ _ _ = Nothing
|
cppdeclareFree _ _ _ _ = Nothing
|
||||||
|
|
||||||
-- | Changed to work properly with declareFree to free channel arrays.
|
-- | Changed to work properly with declareFree to free channel arrays.
|
||||||
|
@ -1059,7 +1033,7 @@ cppgenArrayType ops const (A.Array dims t) rank
|
||||||
cppgenArrayType ops const t rank
|
cppgenArrayType ops const t rank
|
||||||
= do tell ["tockArrayView<"]
|
= do tell ["tockArrayView<"]
|
||||||
when (const) (tell ["const "])
|
when (const) (tell ["const "])
|
||||||
call genType ops t
|
call declareType ops t
|
||||||
tell [",",show rank, ">/**/"]
|
tell [",",show rank, ">/**/"]
|
||||||
|
|
||||||
-- | Changed from GenerateC to change the arrays and the channels
|
-- | Changed from GenerateC to change the arrays and the channels
|
||||||
|
@ -1069,17 +1043,8 @@ cppgenType ops arr@(A.Array _ _)
|
||||||
= cppgenArrayType ops False arr 0
|
= cppgenArrayType ops False arr 0
|
||||||
cppgenType _ (A.Record n) = genName n
|
cppgenType _ (A.Record n) = genName n
|
||||||
cppgenType _ (A.UserProtocol n) = genProtocolName n
|
cppgenType _ (A.UserProtocol n) = genProtocolName n
|
||||||
cppgenType ops ch@(A.Chan A.DirUnknown _ _)
|
cppgenType ops ch@(A.Chan {})
|
||||||
= do call declareType ops ch
|
= do call declareType ops ch
|
||||||
tell ["*"]
|
|
||||||
cppgenType ops (A.Chan A.DirInput _ t)
|
|
||||||
= do tell ["csp::Chanin<"]
|
|
||||||
call genType ops t
|
|
||||||
tell [">/**/"]
|
|
||||||
cppgenType ops (A.Chan A.DirOutput _ t)
|
|
||||||
= do tell ["csp::Chanout<"]
|
|
||||||
call genType ops t
|
|
||||||
tell [">/**/"]
|
|
||||||
cppgenType ops (A.Counted countType valueType)
|
cppgenType ops (A.Counted countType valueType)
|
||||||
= call genType ops (A.Array [A.UnknownDimension] valueType)
|
= call genType ops (A.Array [A.UnknownDimension] valueType)
|
||||||
cppgenType _ (A.Any)
|
cppgenType _ (A.Any)
|
||||||
|
|
|
@ -197,10 +197,10 @@ testGenType = TestList
|
||||||
,testBoth "GenType 200" "Time" "csp::Time" (tcall genType A.Time)
|
,testBoth "GenType 200" "Time" "csp::Time" (tcall genType A.Time)
|
||||||
,testBoth "GenType 201" "Time" "csp::Time" (tcall genType A.Timer)
|
,testBoth "GenType 201" "Time" "csp::Time" (tcall genType A.Timer)
|
||||||
|
|
||||||
,testBoth "GenType 300" "Channel*" "csp::One2OneChannel<int>*" (tcall genType $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int)
|
,testBoth "GenType 300" "Channel" "csp::One2OneChannel<int>" (tcall genType $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int)
|
||||||
,testBoth "GenType 301" "Channel*" "csp::One2AnyChannel<int>*" (tcall genType $ A.Chan A.DirUnknown (A.ChanAttributes False True) A.Int)
|
,testBoth "GenType 301" "Channel" "csp::One2AnyChannel<int>" (tcall genType $ A.Chan A.DirUnknown (A.ChanAttributes False True) A.Int)
|
||||||
,testBoth "GenType 302" "Channel*" "csp::Any2OneChannel<int>*" (tcall genType $ A.Chan A.DirUnknown (A.ChanAttributes True False) A.Int)
|
,testBoth "GenType 302" "Channel" "csp::Any2OneChannel<int>" (tcall genType $ A.Chan A.DirUnknown (A.ChanAttributes True False) A.Int)
|
||||||
,testBoth "GenType 303" "Channel*" "csp::Any2AnyChannel<int>*" (tcall genType $ A.Chan A.DirUnknown (A.ChanAttributes True True) A.Int)
|
,testBoth "GenType 303" "Channel" "csp::Any2AnyChannel<int>" (tcall genType $ A.Chan A.DirUnknown (A.ChanAttributes True True) A.Int)
|
||||||
|
|
||||||
,testBoth "GenType 400" "Channel*" "csp::Chanin<int>" (tcall genType $ A.Chan A.DirInput (A.ChanAttributes False False) A.Int)
|
,testBoth "GenType 400" "Channel*" "csp::Chanin<int>" (tcall genType $ A.Chan A.DirInput (A.ChanAttributes False False) A.Int)
|
||||||
,testBoth "GenType 401" "Channel*" "csp::Chanin<int>" (tcall genType $ A.Chan A.DirInput (A.ChanAttributes False True) A.Int)
|
,testBoth "GenType 401" "Channel*" "csp::Chanin<int>" (tcall genType $ A.Chan A.DirInput (A.ChanAttributes False True) A.Int)
|
||||||
|
@ -211,6 +211,9 @@ testGenType = TestList
|
||||||
--ANY and protocols can occur outside channels in C++ (e.g. temporaries for reading from channels), so they are tested here:
|
--ANY and protocols can occur outside channels in C++ (e.g. temporaries for reading from channels), so they are tested here:
|
||||||
,testCPPF "GenType 500" "tockAny" (tcall genType $ A.Any)
|
,testCPPF "GenType 500" "tockAny" (tcall genType $ A.Any)
|
||||||
,testCPPF "GenType 600" "protocol_foo" (tcall genType $ A.UserProtocol (simpleName "foo"))
|
,testCPPF "GenType 600" "protocol_foo" (tcall genType $ A.UserProtocol (simpleName "foo"))
|
||||||
|
|
||||||
|
,testBoth "GenType 700" "Channel*" "tockArrayView<csp::One2OneChannel<int>,1>" (tcall genType $ A.Array [A.Dimension 5] $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int)
|
||||||
|
,testBoth "GenType 701" "Channel**" "tockArrayView<csp::Chanin<int>,1>" (tcall genType $ A.Array [A.Dimension 5] $ A.Chan A.DirInput (A.ChanAttributes False False) A.Int)
|
||||||
]
|
]
|
||||||
|
|
||||||
testStop :: Test
|
testStop :: Test
|
||||||
|
@ -339,12 +342,12 @@ testDeclaration = TestList
|
||||||
(tcall2 genDeclaration (A.Array [A.Dimension 8,A.Dimension 9,A.Dimension 10] A.Int) foo)
|
(tcall2 genDeclaration (A.Array [A.Dimension 8,A.Dimension 9,A.Dimension 10] A.Int) foo)
|
||||||
|
|
||||||
--Arrays of channels and channel-ends:
|
--Arrays of channels and channel-ends:
|
||||||
,testBoth "genDeclaration 200" "Channel* foo[8];const int foo_sizes[]={8};"
|
,testBoth "genDeclaration 200" "Channel foo[8];const int foo_sizes[]={8};"
|
||||||
"csp::One2OneChannel<int>* foo_actual[8];tockArrayView<csp::One2OneChannel<int>*,1> foo(foo_actual,tockDims(8));"
|
"csp::One2OneChannel<int> foo_actual[8];tockArrayView<csp::One2OneChannel<int>,1> foo(foo_actual,tockDims(8));"
|
||||||
(tcall2 genDeclaration (A.Array [A.Dimension 8] $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int) foo)
|
(tcall2 genDeclaration (A.Array [A.Dimension 8] $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int) foo)
|
||||||
|
|
||||||
,testBoth "genDeclaration 201" "Channel* foo[8*9];const int foo_sizes[]={8,9};"
|
,testBoth "genDeclaration 201" "Channel foo[8*9];const int foo_sizes[]={8,9};"
|
||||||
"csp::One2OneChannel<int>* foo_actual[8*9];tockArrayView<csp::One2OneChannel<int>*,2> foo(foo_actual,tockDims(8,9));"
|
"csp::One2OneChannel<int> foo_actual[8*9];tockArrayView<csp::One2OneChannel<int>,2> foo(foo_actual,tockDims(8,9));"
|
||||||
(tcall2 genDeclaration (A.Array [A.Dimension 8, A.Dimension 9] $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int) foo)
|
(tcall2 genDeclaration (A.Array [A.Dimension 8, A.Dimension 9] $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int) foo)
|
||||||
|
|
||||||
,testBoth "genDeclaration 202" "Channel* foo[8];const int foo_sizes[]={8};"
|
,testBoth "genDeclaration 202" "Channel* foo[8];const int foo_sizes[]={8};"
|
||||||
|
@ -364,6 +367,8 @@ testDeclareInitFree = TestList
|
||||||
,testAll 1 ("ChanInit((&foo));","") ("","") $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int
|
,testAll 1 ("ChanInit((&foo));","") ("","") $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int
|
||||||
,testAllSame 2 ("","") $ A.Chan A.DirInput (A.ChanAttributes False False) A.Int
|
,testAllSame 2 ("","") $ A.Chan A.DirInput (A.ChanAttributes False False) A.Int
|
||||||
,testAllSame 3 ("","") $ A.Array [A.Dimension 4] A.Int
|
,testAllSame 3 ("","") $ A.Array [A.Dimension 4] A.Int
|
||||||
|
,testAll 4 ("^ChanInit((&foo[0]));^","") ("","") $ A.Array [A.Dimension 4] $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int
|
||||||
|
,testAllSame 5 ("","") $ A.Array [A.Dimension 4] $ A.Chan A.DirInput (A.ChanAttributes False False) A.Int
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
testAll :: Int -> (String,String) -> (String,String) -> A.Type -> Test
|
testAll :: Int -> (String,String) -> (String,String) -> A.Type -> Test
|
||||||
|
|
Loading…
Reference in New Issue
Block a user