Skip to content

Commit 726f25f

Browse files
committed
Some testing for DerivedInductionMap.
1 parent b79b8a1 commit 726f25f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/Language/Fortran/Analysis/DataFlowSpec.hs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,36 @@ spec =
195195
let dm = genDefMap bm
196196
let rDefs = reachingDefinitions dm gr
197197
let flTo = genFlowsToGraph bm dm gr rDefs
198+
let domMap = dominators gr
199+
let bedges = genBackEdgeMap domMap gr
200+
let diMap = genDerivedInductionMap bedges gr
198201
it "flowsTo" $ do
199202
(S.fromList . edges . trc $ flTo) `shouldSatisfy`
200203
-- Find the flows of the assignment statements in the program.
201204
S.isSubsetOf (findLabelsBlEdges pf [(1,2),(1,3),(3,2)])
202205

206+
describe "funcflow2" $ do
207+
let pf = pParser F90 programFuncFlow2
208+
let sgr = genSuperBBGr (genBBlockMap pf)
209+
let gr = superBBGrGraph sgr
210+
let bm = genBlockMap pf
211+
let dm = genDefMap bm
212+
let rDefs = reachingDefinitions dm gr
213+
let flTo = genFlowsToGraph bm dm gr rDefs
214+
let domMap = dominators gr
215+
let bedges = genBackEdgeMap domMap gr
216+
let diMap = genDerivedInductionMap bedges gr
217+
let (iLabel, iName):_ = [ (fromJust (insLabel a), varName e)
218+
| e@(ExpValue a _ (ValVariable _)) <- rhsExprs pf, srcName e == "i" ]
219+
let (jLabel, jName):_ = [ (fromJust (insLabel a), varName e)
220+
| e@(ExpValue a _ (ValVariable _)) <- lhsExprs pf, srcName e == "j" ]
221+
it "flowsTo" $ do
222+
(S.fromList . edges . trc $ flTo) `shouldSatisfy`
223+
-- Find the flows of the assignment statements in the program.
224+
S.isSubsetOf (findLabelsBlEdges pf [(1,2),(1,3),(3,2)])
225+
it "derivedInduction" $ do
226+
IM.lookup iLabel diMap `shouldBe` Just (IELinear iName 1 0)
227+
IM.lookup jLabel diMap `shouldBe` Just (IELinear iName 6 2)
203228

204229
--------------------------------------------------
205230
-- Label-finding helper functions to help write tests that are
@@ -365,6 +390,20 @@ programFuncFlow1 = unlines [
365390
, " end program main"
366391
]
367392

393+
programFuncFlow2 = unlines [
394+
" program main"
395+
, " integer :: i, j"
396+
, " 1 do i = 1, 10"
397+
, " 2 j = 2*f(3*i)"
398+
, " end do"
399+
, " contains"
400+
, " integer function f(k)"
401+
, " integer :: k"
402+
, " 3 f = k + 1"
403+
, " end function f"
404+
, " end program main"
405+
]
406+
368407
-- Local variables:
369408
-- mode: haskell
370409
-- haskell-program-name: "cabal repl test-suite:spec"

0 commit comments

Comments
 (0)