Add a "cache view" type to step through a cache access.

This commit is contained in:
Danila Fedorin 2019-05-28 21:35:46 -07:00
parent eebf82d40a
commit 672d321616
4 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,54 @@
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
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

View File

@ -1,10 +1,12 @@
module CacheSim.Model exposing (..)
import CacheSim.Raw exposing (..)
import CacheSim.Hierarchy exposing (..)
import CacheSim.AccessView exposing (..)
type alias Model =
{ rawHierarchy : RawCacheModelHierarchy
, hierarchy : Maybe CacheHierarchy
, accessView : Maybe AccessView
}
type alias Flags = ()
type Msg
@ -12,3 +14,4 @@ type Msg
| CreateRawModel
| DeleteRawModel Int
| UseHierarchy (Maybe CacheModelHierarchy)
| Access Int

View File

@ -3,6 +3,7 @@ import CacheSim.Model exposing (..)
import CacheSim.Hierarchy exposing (..)
import CacheSim.Raw exposing (..)
import CacheSim.IntMap exposing (..)
import CacheSim.AccessView exposing (..)
updateChangeRawModel : Int -> (RawCacheModel -> RawCacheModel) -> Model -> (Model, Cmd Msg)
updateChangeRawModel l f m =
@ -36,3 +37,12 @@ updateUseHierarchy cmh m =
cmd = Cmd.none
in
(newModel, cmd)
updateAccess : Int -> Model -> (Model, Cmd Msg)
updateAccess i m =
let
accessResult = Maybe.map (accessCacheHierarchy i) m.hierarchy
newModel = m
cmd = Cmd.none
in
(newModel, cmd)

View File

@ -18,6 +18,7 @@ init f =
initialModel =
{ rawHierarchy = testCacheModelHierarchy
, hierarchy = Nothing
, accessView = Nothing
}
in
(initialModel, Cmd.none)
@ -35,6 +36,7 @@ update msg m =
CreateRawModel -> updateCreateRawModel m
DeleteRawModel i -> updateDeleteRawModel i m
UseHierarchy cmh -> updateUseHierarchy cmh m
Access i -> updateAccess i m
subscriptions : Model -> Sub Msg
subscriptions m = Sub.none