Display errors.

This commit is contained in:
Danila Fedorin 2019-05-28 20:08:04 -07:00
parent 87cc4c4cb9
commit a3d6a1440f
3 changed files with 35 additions and 9 deletions

View File

@ -21,11 +21,11 @@ translateRawCacheModel rcm =
(Just bs, Just sc, Just ss) ->
Ok { blockSize = bs, setCount = sc, setSize = ss }
(Nothing, _, _) ->
Err <| "Unable to parse the block size: " ++ rcm.blockSize
Err <| "Unable to parse the block size: \"" ++ rcm.blockSize ++ "\""
(_, Nothing, _) ->
Err <| "Unable to parse the set count: " ++ rcm.setCount
Err <| "Unable to parse the set count: \"" ++ rcm.setCount ++ "\""
(_, _, Nothing) ->
Err <| "Unable to parse the set size: " ++ rcm.setSize
Err <| "Unable to parse the set size: \"" ++ rcm.setSize ++ "\""
translateRawCacheModelHierarchy : RawCacheModelHierarchy -> Result String CacheModelHierarchy
translateRawCacheModelHierarchy rcmh =
@ -42,8 +42,8 @@ validateCacheModelHierarchy cmh =
[] -> Ok []
x::[] -> Ok [x]
x::y::xs ->
if modBy y.blockSize x.blockSize == 0
if modBy x.blockSize y.blockSize == 0
then validateCacheModelHierarchy (y::xs)
else Err <| "Block cache size " ++ String.fromInt x.blockSize ++
else Err <| "Block cache size " ++ String.fromInt y.blockSize ++
" is not a multiple of the next level cache's" ++
" block size (" ++ String.fromInt y.blockSize ++ ")"
" block size (" ++ String.fromInt x.blockSize ++ ")"

View File

@ -2,9 +2,16 @@ module CacheSim.View exposing (..)
import CacheSim.Raw exposing (..)
import CacheSim.Model exposing (..)
import Html exposing (Html, input, text, div, label, span, h2, h3)
import Html.Attributes exposing (type_, class, value, for)
import Html.Attributes exposing (type_, class, value, for, classList, disabled)
import Html.Events exposing (onInput, onClick)
optionalButton : Bool -> String -> Msg -> Html Msg
optionalButton e s m =
let
events = if e then [ onClick m ] else [ disabled (not e) ]
in
input ([ type_ "button", value s ] ++ events) []
button : String -> Msg -> Html Msg
button s m = input [ type_ "button", onClick m, value s] []
@ -45,11 +52,30 @@ viewRawCacheModelHierarchy rcmh =
let
models = div [ class "cache-model-levels" ]
<|List.indexedMap viewRawCacheModel rcmh
translationResult = Result.andThen validateCacheModelHierarchy
<| translateRawCacheModelHierarchy rcmh
isValid =
case translationResult of
Ok _ -> True
Err _ -> False
errorHtml =
case translationResult of
Ok _ -> viewError True ""
Err e -> viewError False e
newButton = button "Add level" CreateRawModel
useButton = optionalButton isValid "Use hierarchy" CreateRawModel
in
div [ class "cache-model-hierarchy" ]
[ h2 [] [ text "Cache hierarchy" ]
, buttonWrapper [ newButton ]
, errorHtml
, buttonWrapper [ newButton, useButton ]
, models
]
viewError : Bool -> String -> Html Msg
viewError hide e = span [ classList [ ("hidden", hide) ] ] [ text e ]
viewBase : Model -> Html Msg
viewBase m =
div [] [ viewRawCacheModelHierarchy m.rawHierarchy ]

View File

@ -24,7 +24,7 @@ init f =
view : Model -> Document Msg
view m =
{ title = "Cache Simulator"
, body = [ viewRawCacheModelHierarchy m.rawHierarchy ]
, body = [ viewBase m ]
}
update : Msg -> Model -> (Model, Cmd Msg)