CacheSim/src/CacheSim/View.elm

37 lines
1.4 KiB
Elm
Raw Normal View History

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}
2019-05-28 19:37:22 -07:00
wrapUpdate f s = ChangeRawModel 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