Add a basic, editable view of the cache hierarchy.
This commit is contained in:
parent
559821f54a
commit
2b00e5c7a5
|
@ -1,5 +1,9 @@
|
|||
module CacheSim.Model exposing (..)
|
||||
import CacheSim.Raw exposing (..)
|
||||
|
||||
type alias Model = ()
|
||||
type alias Model =
|
||||
{ rawCacheModelHierarchy : RawCacheModelHierarchy
|
||||
}
|
||||
type alias Flags = ()
|
||||
type alias Msg = ()
|
||||
type Msg =
|
||||
UpdateRawModel Int (RawCacheModel -> RawCacheModel)
|
||||
|
|
36
src/CacheSim/View.elm
Normal file
36
src/CacheSim/View.elm
Normal file
|
@ -0,0 +1,36 @@
|
|||
module CacheSim.View exposing (..)
|
||||
import CacheSim.Raw exposing (..)
|
||||
import CacheSim.Model exposing (..)
|
||||
import Html exposing (Html, input, text, div, label, span, h2)
|
||||
import Html.Attributes exposing (type_, class, value, for)
|
||||
import Html.Events exposing (onInput)
|
||||
|
||||
labeledInput : String -> String -> (String -> Msg) -> Html Msg
|
||||
labeledInput s val f =
|
||||
div [ class "input-group" ]
|
||||
[ span [] [ text s ]
|
||||
, input [ value val, type_ "text", onInput f ] []
|
||||
]
|
||||
|
||||
viewRawCacheModel : Int -> RawCacheModel -> Html Msg
|
||||
viewRawCacheModel level rcm =
|
||||
let
|
||||
updateBlockSize s cm = { cm | blockSize = s}
|
||||
updateSetCount s cm = { cm | setCount = s}
|
||||
updateSetSize s cm = { cm | setSize = s}
|
||||
wrapUpdate f s = UpdateRawModel level (f s)
|
||||
|
||||
params = div [ class "cache-model-params" ]
|
||||
[ labeledInput "Block size" rcm.blockSize (wrapUpdate updateBlockSize)
|
||||
, labeledInput "Set count" rcm.setCount (wrapUpdate updateSetCount)
|
||||
, labeledInput "Set size" rcm.setSize (wrapUpdate updateSetSize)
|
||||
]
|
||||
in
|
||||
div [ class "cache-model" ]
|
||||
[ h2 [] [ text <| "L" ++ String.fromInt (level + 1) ++ " Cache" ]
|
||||
, params
|
||||
]
|
||||
|
||||
viewRawCacheModelHierarchy : RawCacheModelHierarchy -> Html Msg
|
||||
viewRawCacheModelHierarchy rcmh =
|
||||
div [ class "cache-model-hierarchy" ] <| List.indexedMap viewRawCacheModel rcmh
|
26
src/Main.elm
26
src/Main.elm
|
@ -1,21 +1,39 @@
|
|||
import CacheSim.Model exposing (..)
|
||||
import CacheSim.Cache exposing (..)
|
||||
import CacheSim.IntMap exposing (..)
|
||||
import CacheSim.Hierarchy exposing (..)
|
||||
import CacheSim.Raw exposing (..)
|
||||
import CacheSim.View exposing (..)
|
||||
import Browser exposing (Document, document)
|
||||
import Html exposing (text)
|
||||
|
||||
testCacheModelHierarchy =
|
||||
[ { blockSize = "128", setCount = "8", setSize = "1" }
|
||||
]
|
||||
|
||||
init : Flags -> (Model, Cmd Msg)
|
||||
init f = ((), Cmd.none)
|
||||
init f =
|
||||
let
|
||||
initialModel =
|
||||
{ rawCacheModelHierarchy = testCacheModelHierarchy
|
||||
}
|
||||
in
|
||||
(initialModel, Cmd.none)
|
||||
|
||||
view : Model -> Document Msg
|
||||
view m =
|
||||
{ title = "Cache Simulator"
|
||||
, body = [ text "Hello, world!" ]
|
||||
, body = [ viewRawCacheModelHierarchy m.rawCacheModelHierarchy ]
|
||||
}
|
||||
|
||||
update : Msg -> Model -> (Model, Cmd Msg)
|
||||
update msg m = (m, Cmd.none)
|
||||
update msg m =
|
||||
case msg of
|
||||
UpdateRawModel l f ->
|
||||
({ m | rawCacheModelHierarchy = intMapUpdate l f m.rawCacheModelHierarchy}, Cmd.none)
|
||||
|
||||
subscriptions : Model -> Sub Msg
|
||||
subscriptions m = Sub.none
|
||||
subscriptions m = Sub.none
|
||||
|
||||
main = document
|
||||
{ init = init
|
||||
|
|
Loading…
Reference in New Issue
Block a user