Added a test for genBytesIn in the C and C++ backends
This commit is contained in:
parent
c1c1397f67
commit
5450f77963
|
@ -86,7 +86,9 @@ data GenOps = GenOps {
|
|||
genAssert :: GenOps -> Meta -> A.Expression -> CGen (),
|
||||
-- | Generates an assignment statement with a single destination and single source.
|
||||
genAssign :: GenOps -> Meta -> [A.Variable] -> A.ExpressionList -> CGen (),
|
||||
-- | Generates the number of bytes in a fixed size type
|
||||
genBytesIn :: GenOps -> A.Type -> Maybe A.Variable -> CGen (),
|
||||
-- | Generates the number of bytes in a type that may have one free dimension
|
||||
genBytesIn' :: GenOps -> A.Type -> Maybe A.Variable -> CGen (Maybe Int),
|
||||
-- | Generates a case statement over the given expression with the structured as the body.
|
||||
genCase :: GenOps -> Meta -> A.Expression -> A.Structured -> CGen (),
|
||||
|
@ -121,8 +123,11 @@ data GenOps = GenOps {
|
|||
genMissing :: GenOps -> String -> CGen (),
|
||||
genMissingC :: GenOps -> CGen String -> CGen (),
|
||||
genMonadic :: GenOps -> Meta -> A.MonadicOp -> A.Expression -> CGen (),
|
||||
-- | Generates an output statement.
|
||||
genOutput :: GenOps -> A.Variable -> [A.OutputItem] -> CGen (),
|
||||
-- | Generates an output statement for a tagged protocol.
|
||||
genOutputCase :: GenOps -> A.Variable -> A.Name -> [A.OutputItem] -> CGen (),
|
||||
-- | Generates an output for an individual item.
|
||||
genOutputItem :: GenOps -> A.Variable -> A.OutputItem -> CGen (),
|
||||
-- | Generates a loop that maps over every element in a (potentially multi-dimensional) array
|
||||
genOverArray :: GenOps -> Meta -> A.Variable -> (SubscripterFunction -> Maybe (CGen ())) -> CGen (),
|
||||
|
@ -420,7 +425,8 @@ cgenBytesIn' ops (A.Array ds t) v
|
|||
Just rv ->
|
||||
do free <- genBytesInArray ds (i + 1)
|
||||
call genVariable ops rv
|
||||
tell ["_sizes[", show i, "] * "]
|
||||
call genSizeSuffix ops (show i)
|
||||
tell ["*"]
|
||||
return free
|
||||
Nothing ->
|
||||
do free <- genBytesInArray ds (i + 1)
|
||||
|
@ -434,8 +440,10 @@ cgenBytesIn' _ (A.Record n) _
|
|||
return Nothing
|
||||
-- This is so that we can do RETYPES checks on channels; we don't actually
|
||||
-- allow retyping between channels and other things.
|
||||
cgenBytesIn' _ (A.Chan {}) _
|
||||
= do tell ["sizeof (Channel *)"]
|
||||
cgenBytesIn' ops t@(A.Chan {}) _
|
||||
= do tell ["sizeof("]
|
||||
call genType ops t
|
||||
tell [")"]
|
||||
return Nothing
|
||||
cgenBytesIn' ops t _
|
||||
= case call getScalarType ops t of
|
||||
|
|
|
@ -768,6 +768,32 @@ testOutput = TestList
|
|||
overOutputItem ops = ops {genOutputItem = override2 caret}
|
||||
over ops = ops {genBytesIn = override2 caret}
|
||||
|
||||
testBytesIn :: Test
|
||||
testBytesIn = TestList
|
||||
[
|
||||
testBothSame "testBytesIn 0" "sizeof(int)" (tcall2 genBytesIn A.Int undefined)
|
||||
,testBothSame "testBytesIn 1" "sizeof(foo)" (tcall2 genBytesIn (A.Record foo) undefined)
|
||||
,testBoth "testBytesIn 2" "sizeof(Channel)" "sizeof(csp::One2OneChannel<int>)" (tcall2 genBytesIn (A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int) undefined)
|
||||
,testBoth "testBytesIn 3" "sizeof(Channel*)" "sizeof(csp::Chanin<int>)" (tcall2 genBytesIn (A.Chan A.DirInput (A.ChanAttributes False False) A.Int) undefined)
|
||||
|
||||
--Array with a single known dimension:
|
||||
,testBothSame "testBytesIn 100" "5*sizeof(int)" (tcall2 genBytesIn (A.Array [A.Dimension 5] A.Int) undefined)
|
||||
--single unknown dimension, no variable:
|
||||
,testBothFail "testBytesIn 101" (tcall2 genBytesIn (A.Array [A.UnknownDimension] A.Int) Nothing)
|
||||
--single unknown dimension, with variable:
|
||||
,testBothSame "testBytesIn 102" "$(@0)*sizeof(int)" ((tcall2 genBytesIn (A.Array [A.UnknownDimension] A.Int) (Just undefined)) . over)
|
||||
|
||||
--Array with all known dimensions:
|
||||
,testBothSame "testBytesIn 200" "7*6*5*sizeof(int)" (tcall2 genBytesIn (A.Array [A.Dimension 5,A.Dimension 6, A.Dimension 7] A.Int) undefined)
|
||||
--single unknown dimension, no variable:
|
||||
,testBothFail "testBytesIn 201" (tcall2 genBytesIn (A.Array [A.Dimension 5,A.Dimension 6,A.UnknownDimension] A.Int) Nothing)
|
||||
--single unknown dimension, with variable:
|
||||
,testBothSame "testBytesIn 202" "$(@2)*6*5*sizeof(int)" ((tcall2 genBytesIn (A.Array [A.Dimension 5,A.Dimension 6,A.UnknownDimension] A.Int) (Just undefined)) . over)
|
||||
|
||||
]
|
||||
where
|
||||
over ops = ops {genVariable = override1 dollar, genSizeSuffix = (\_ n -> tell["(@",n,")"])}
|
||||
|
||||
---Returns the list of tests:
|
||||
tests :: Test
|
||||
tests = TestList
|
||||
|
@ -776,6 +802,7 @@ tests = TestList
|
|||
,testArraySizes
|
||||
,testArraySubscript
|
||||
,testAssign
|
||||
,testBytesIn
|
||||
,testCase
|
||||
,testDeclaration
|
||||
,testDeclareInitFree
|
||||
|
|
Loading…
Reference in New Issue
Block a user