Add a way to "load" a cache hierarchy in from a model.

This commit is contained in:
Danila Fedorin 2019-05-28 20:22:05 -07:00
parent a3d6a1440f
commit 99a7be27a9
4 changed files with 17 additions and 1 deletions

View File

@ -1,11 +1,14 @@
module CacheSim.Model exposing (..)
import CacheSim.Raw exposing (..)
import CacheSim.Hierarchy exposing (..)
type alias Model =
{ rawHierarchy : RawCacheModelHierarchy
, hierarchy : Maybe CacheHierarchy
}
type alias Flags = ()
type Msg
= ChangeRawModel Int (RawCacheModel -> RawCacheModel)
| CreateRawModel
| DeleteRawModel Int
| UseHierarchy (Maybe CacheModelHierarchy)

View File

@ -1,5 +1,6 @@
module CacheSim.Update exposing (..)
import CacheSim.Model exposing (..)
import CacheSim.Hierarchy exposing (..)
import CacheSim.Raw exposing (..)
import CacheSim.IntMap exposing (..)
@ -27,3 +28,11 @@ updateDeleteRawModel l m =
cmd = Cmd.none
in
(newModel, cmd)
updateUseHierarchy : Maybe CacheModelHierarchy -> Model -> (Model, Cmd Msg)
updateUseHierarchy cmh m =
let
newModel = { m | hierarchy = Maybe.map freshCacheHierarchy cmh }
cmd = Cmd.none
in
(newModel, cmd)

View File

@ -64,7 +64,9 @@ viewRawCacheModelHierarchy rcmh =
Err e -> viewError False e
newButton = button "Add level" CreateRawModel
useButton = optionalButton isValid "Use hierarchy" CreateRawModel
useButton = case translationResult of
Ok cmh -> optionalButton True "Use hierarchy" (UseHierarchy <| Just cmh)
Err _ -> optionalButton False "Use hierarchy" (UseHierarchy Nothing)
in
div [ class "cache-model-hierarchy" ]
[ h2 [] [ text "Cache hierarchy" ]

View File

@ -17,6 +17,7 @@ init f =
let
initialModel =
{ rawHierarchy = testCacheModelHierarchy
, hierarchy = Nothing
}
in
(initialModel, Cmd.none)
@ -33,6 +34,7 @@ update msg m =
ChangeRawModel l f -> updateChangeRawModel l f m
CreateRawModel -> updateCreateRawModel m
DeleteRawModel i -> updateDeleteRawModel i m
UseHierarchy cmh -> updateUseHierarchy cmh m
subscriptions : Model -> Sub Msg
subscriptions m = Sub.none