From 8d007312480b77e37afcc6440f26e56172d8f3a0 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 28 May 2019 22:51:02 -0700 Subject: [PATCH] Add log of events to view. --- src/CacheSim/View.elm | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/CacheSim/View.elm b/src/CacheSim/View.elm index c14f20b..9a41775 100644 --- a/src/CacheSim/View.elm +++ b/src/CacheSim/View.elm @@ -133,13 +133,41 @@ viewAccessView m av = currentCache = Maybe.withDefault [] m.hierarchy in div [ class "access-view" ] - [ viewCacheHierarchy <| effectiveCacheHierarchy currentCache av + [ h2 [] [ text "Access Simulation" ] , buttonWrapper [ button "Forward" AccessViewForward , button "Back" AccessViewBack ] + , viewAccessLog av + , viewCacheHierarchy <| effectiveCacheHierarchy currentCache av ] +viewAccessLog : AccessView -> Html Msg +viewAccessLog (aes, ap) = + let + resultSpan r = + case r of + Hit -> span [ class "success" ] [ text "HIT" ] + Miss -> span [ class "failure" ] [ text "MISS" ] + downEvent n ae = div [ class "event" ] + [ text <| "L" ++ String.fromInt (n + 1) + , resultSpan ae.result + ] + upEvent n ae = div [ class "event" ] + [ text <| "Updated L" ++ String.fromInt (n + 1) + ] + events = + case ap of + Done -> [] + Down n -> List.indexedMap downEvent <| List.take (n + 1) aes + Up n -> List.indexedMap downEvent aes ++ + (List.indexedMap upEvent <| List.drop n aes) + in + div [ class "access-log" ] + [ h3 [] [ text "Simulation events" ] + , div [ class "access-log-events" ] events + ] + viewAccessInput : Model -> Html Msg viewAccessInput m = let