60 lines
1.9 KiB
Elm
60 lines
1.9 KiB
Elm
module CacheSim.AccessView exposing (..)
|
|
import CacheSim.Cache exposing (..)
|
|
import CacheSim.Hierarchy exposing (..)
|
|
|
|
type AccessPosition = Down Int | Up Int | Done
|
|
type alias AccessView = (List (AccessEffect Cache), AccessPosition)
|
|
|
|
accessPositionForward : Int -> AccessPosition -> AccessPosition
|
|
accessPositionForward depth av =
|
|
case av of
|
|
Down n -> if n == depth - 1 then Up n else Down (n + 1)
|
|
Up n -> if n == 0 then Done else Up (n - 1)
|
|
Done -> Done
|
|
|
|
accessPositionBack : Int -> AccessPosition -> AccessPosition
|
|
accessPositionBack depth av =
|
|
case av of
|
|
Down 0 -> Down 0
|
|
Down n -> Down (n-1)
|
|
Up n -> if n == (depth - 1) then Down n else Up (n + 1)
|
|
Done -> Up 0
|
|
|
|
accessPositionDone : AccessPosition -> Bool
|
|
accessPositionDone av =
|
|
case av of
|
|
Done -> True
|
|
_ -> False
|
|
|
|
accessViewForward : AccessView -> AccessView
|
|
accessViewForward (l, ap) = (l, accessPositionForward (List.length l) ap)
|
|
|
|
accessViewBack : AccessView -> AccessView
|
|
accessViewBack (l, ap) = (l, accessPositionBack (List.length l) ap)
|
|
|
|
accessViewDone : AccessView -> Bool
|
|
accessViewDone (_, ap) = accessPositionDone ap
|
|
|
|
finalCacheHierarchy : CacheHierarchy -> AccessView -> CacheHierarchy
|
|
finalCacheHierarchy ch (l, ap) =
|
|
List.map .output l ++ List.drop (List.length l) ch
|
|
|
|
|
|
effectiveCacheHierarchy : CacheHierarchy -> AccessView -> CacheHierarchy
|
|
effectiveCacheHierarchy c (l, ap) =
|
|
let
|
|
finalContents = List.map .output l
|
|
unaccessed = List.drop (List.length l) c
|
|
notDone =
|
|
case ap of
|
|
Done -> []
|
|
Down _ -> List.take (List.length l) c
|
|
Up n -> List.take n c
|
|
done =
|
|
case ap of
|
|
Done -> finalContents
|
|
Down _ -> []
|
|
Up n -> List.drop n finalContents
|
|
in
|
|
notDone ++ done ++ unaccessed
|