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

View File

@ -3,6 +3,7 @@ import CacheSim.Model exposing (..)
import CacheSim.Hierarchy exposing (..) import CacheSim.Hierarchy exposing (..)
import CacheSim.Raw exposing (..) import CacheSim.Raw exposing (..)
import CacheSim.IntMap exposing (..) import CacheSim.IntMap exposing (..)
import CacheSim.AccessView exposing (..)
updateChangeRawModel : Int -> (RawCacheModel -> RawCacheModel) -> Model -> (Model, Cmd Msg) updateChangeRawModel : Int -> (RawCacheModel -> RawCacheModel) -> Model -> (Model, Cmd Msg)
updateChangeRawModel l f m = updateChangeRawModel l f m =
@ -36,3 +37,12 @@ updateUseHierarchy cmh m =
cmd = Cmd.none cmd = Cmd.none
in in
(newModel, cmd) (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 = initialModel =
{ rawHierarchy = testCacheModelHierarchy { rawHierarchy = testCacheModelHierarchy
, hierarchy = Nothing , hierarchy = Nothing
, accessView = Nothing
} }
in in
(initialModel, Cmd.none) (initialModel, Cmd.none)
@ -35,6 +36,7 @@ update msg m =
CreateRawModel -> updateCreateRawModel m CreateRawModel -> updateCreateRawModel m
DeleteRawModel i -> updateDeleteRawModel i m DeleteRawModel i -> updateDeleteRawModel i m
UseHierarchy cmh -> updateUseHierarchy cmh m UseHierarchy cmh -> updateUseHierarchy cmh m
Access i -> updateAccess i m
subscriptions : Model -> Sub Msg subscriptions : Model -> Sub Msg
subscriptions m = Sub.none subscriptions m = Sub.none