Compare commits

..

No commits in common. "3c0f5d34bf8241a55c4d791bd74170c80cf47ee0" and "b96c16918b9bf0c58711044eed7df4a03196d086" have entirely different histories.

5 changed files with 17 additions and 89 deletions

View File

@ -1,25 +0,0 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/browser": "1.0.1",
"elm/core": "1.0.2",
"elm/html": "1.0.0",
"elm/parser": "1.1.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}

View File

@ -35,11 +35,6 @@ accessViewBack (l, ap) = (l, accessPositionBack (List.length l) ap)
accessViewDone : AccessView -> Bool accessViewDone : AccessView -> Bool
accessViewDone (_, ap) = accessPositionDone ap accessViewDone (_, ap) = accessPositionDone ap
finalCacheHierarchy : CacheHierarchy -> AccessView -> CacheHierarchy
finalCacheHierarchy ch (l, ap) =
List.map .output l ++ List.drop (List.length l) ch
effectiveCacheHierarchy : CacheHierarchy -> AccessView -> CacheHierarchy effectiveCacheHierarchy : CacheHierarchy -> AccessView -> CacheHierarchy
effectiveCacheHierarchy c (l, ap) = effectiveCacheHierarchy c (l, ap) =
let let

View File

@ -6,7 +6,7 @@ import CacheSim.AccessView exposing (..)
type alias Model = type alias Model =
{ rawHierarchy : RawCacheModelHierarchy { rawHierarchy : RawCacheModelHierarchy
, hierarchy : Maybe CacheHierarchy , hierarchy : Maybe CacheHierarchy
, accessView : Maybe (List AccessView) , accessView : Maybe AccessView
, accessInput : String , accessInput : String
} }
type alias Flags = () type alias Flags = ()
@ -15,7 +15,7 @@ type Msg
| CreateRawModel | CreateRawModel
| DeleteRawModel Int | DeleteRawModel Int
| UseHierarchy (Maybe CacheModelHierarchy) | UseHierarchy (Maybe CacheModelHierarchy)
| Access (List Int) | Access Int
| ChangeAccessInput String | ChangeAccessInput String
| AccessViewForward | AccessViewForward
| AccessViewBack | AccessViewBack

View File

@ -38,19 +38,11 @@ updateUseHierarchy cmh m =
in in
(newModel, cmd) (newModel, cmd)
updateAccess : List Int -> Model -> (Model, Cmd Msg) updateAccess : Int -> Model -> (Model, Cmd Msg)
updateAccess li m = updateAccess i m =
let let
process c xs = accessResult = Maybe.andThen (Result.toMaybe << accessCacheHierarchy i) m.hierarchy
case xs of newModel = { m | accessView = Maybe.map (\ar -> (ar, Down 0)) accessResult }
[] -> Ok []
(i::t) ->
case accessCacheHierarchy i c of
Ok av -> Result.map ((::) (av, Down 0)) <| process (finalCacheHierarchy c (av, Done)) t
Err s -> Err s
accessResult = Maybe.andThen (\h -> Result.toMaybe <| process h li) m.hierarchy
newModel = { m | accessView = accessResult }
cmd = Cmd.none cmd = Cmd.none
in in
(newModel, cmd) (newModel, cmd)
@ -58,11 +50,11 @@ updateAccess li m =
updateAccessViewForward : Model -> (Model, Cmd Msg) updateAccessViewForward : Model -> (Model, Cmd Msg)
updateAccessViewForward m = updateAccessViewForward m =
let let
afterStep = Maybe.map (intMapUpdate 0 accessViewForward) m.accessView afterStep = Maybe.map accessViewForward m.accessView
replaceHierarchy avs h = List.map .output avs ++ List.drop (List.length avs) h
(newHierarchy, newAccessView) = (newHierarchy, newAccessView) =
case afterStep of case afterStep of
Just ((avs, Done)::[]) -> (Maybe.map (\h -> finalCacheHierarchy h (avs, Done)) m.hierarchy, Nothing) Just (avs, Done) -> (Maybe.map (replaceHierarchy avs) m.hierarchy, Nothing)
Just ((avs, Done)::xs) -> (Maybe.map (\h -> finalCacheHierarchy h (avs, Done)) m.hierarchy, Just xs)
as_ -> (m.hierarchy, as_) as_ -> (m.hierarchy, as_)
newModel = { m | accessView = newAccessView, hierarchy = newHierarchy } newModel = { m | accessView = newAccessView, hierarchy = newHierarchy }
cmd = Cmd.none cmd = Cmd.none
@ -72,7 +64,7 @@ updateAccessViewForward m =
updateAccessViewBack : Model -> (Model, Cmd Msg) updateAccessViewBack : Model -> (Model, Cmd Msg)
updateAccessViewBack m = updateAccessViewBack m =
let let
afterStep = Maybe.map (intMapUpdate 0 accessViewBack) m.accessView afterStep = Maybe.map accessViewBack m.accessView
newModel = { m | accessView = afterStep } newModel = { m | accessView = afterStep }
cmd = Cmd.none cmd = Cmd.none
in in

View File

@ -4,7 +4,6 @@ import CacheSim.Model exposing (..)
import CacheSim.Cache exposing (..) import CacheSim.Cache exposing (..)
import CacheSim.AccessView exposing (..) import CacheSim.AccessView exposing (..)
import CacheSim.Hierarchy exposing (..) import CacheSim.Hierarchy exposing (..)
import Parser exposing ((|.))
import Html exposing (Html, Attribute, input, text, div, label, span, h2, h3, table, tr, td, th, p, h1) import Html exposing (Html, Attribute, input, text, div, label, span, h2, h3, table, tr, td, th, p, h1)
import Html.Attributes exposing (type_, class, value, for, classList, disabled, colspan, hidden) import Html.Attributes exposing (type_, class, value, for, classList, disabled, colspan, hidden)
import Html.Events exposing (onInput, onClick) import Html.Events exposing (onInput, onClick)
@ -78,7 +77,7 @@ viewRawCacheModel level rcm =
deleteButton = dangerButton "Delete" (DeleteRawModel level) deleteButton = dangerButton "Delete" (DeleteRawModel level)
params = div [] params = div []
[ labeledInput "Block size (words)" rcm.blockSize (wrapUpdate updateBlockSize) [ labeledInput "Block size" rcm.blockSize (wrapUpdate updateBlockSize)
, labeledInput "Set count" rcm.setCount (wrapUpdate updateSetCount) , labeledInput "Set count" rcm.setCount (wrapUpdate updateSetCount)
, labeledInput "Set size" rcm.setSize (wrapUpdate updateSetSize) , labeledInput "Set size" rcm.setSize (wrapUpdate updateSetSize)
] ]
@ -96,17 +95,13 @@ viewRawCacheModelHierarchy rcmh =
<| List.indexedMap viewRawCacheModel rcmh <| List.indexedMap viewRawCacheModel rcmh
translationResult = Result.andThen validateCacheModelHierarchy translationResult = Result.andThen validateCacheModelHierarchy
<| translateRawCacheModelHierarchy rcmh <| translateRawCacheModelHierarchy rcmh
checkedResult =
case translationResult of
Ok h -> if h == [] then Err "Please specify at least one cache level." else Ok h
Err e -> Err e
errorHtml = errorHtml =
case checkedResult of case translationResult of
Ok _ -> viewError True "" Ok _ -> viewError True ""
Err e -> viewError False e Err e -> viewError False e
newButton = button "Add level" CreateRawModel newButton = button "Add level" CreateRawModel
useButton = resultButton checkedResult "Use hierarchy" (UseHierarchy << Just) useButton = resultButton translationResult "Use hierarchy" (UseHierarchy << Just)
in in
div [] div []
[ h2 [] [ text "Cache hierarchy" ] [ h2 [] [ text "Cache hierarchy" ]
@ -203,34 +198,13 @@ viewAccessLog (aes, ap) =
viewAccessInput : Model -> Html Msg viewAccessInput : Model -> Html Msg
viewAccessInput m = viewAccessInput m =
let let
parser = accessButton = maybeButton (String.toInt m.accessInput) "Access address" Access
Parser.map (List.map (\i -> i // 4)) <|
Parser.sequence
{ start = ""
, end = ""
, separator = ","
, spaces = Parser.spaces
, item = Parser.int
, trailing = Parser.Optional
}
parseErrorToString _ = "Unable to parse input. Please enter a sequence of numbers separated by commas."
parseResult = Parser.run (parser |. Parser.end) m.accessInput
checkedResult =
case parseResult of
Ok is -> if is == [] then Err "Please enter at least one number." else Ok is
Err e -> Err <| parseErrorToString e
accessButton = resultButton checkedResult "Access address" Access
errorHtml =
case checkedResult of
Ok _ -> viewError True ""
Err e -> viewError False e
editHierarchyButton = button "Edit hierarchy" (UseHierarchy Nothing) editHierarchyButton = button "Edit hierarchy" (UseHierarchy Nothing)
in in
div [] div []
[ h2 [] [ text "Run access simulation" ] [ h2 [] [ text "Run access simulation" ]
, labeledInput "Access byte address" m.accessInput ChangeAccessInput , labeledInput "Access address" m.accessInput ChangeAccessInput
, buttonWrapper [ accessButton, editHierarchyButton ] , buttonWrapper [ accessButton, editHierarchyButton ]
, errorHtml
] ]
viewDescription : Html Msg viewDescription : Html Msg
@ -267,15 +241,7 @@ viewBase m =
Maybe.withDefault [] Maybe.withDefault []
<| Maybe.map (List.singleton << viewCacheHierarchy) <| m.hierarchy <| Maybe.map (List.singleton << viewCacheHierarchy) <| m.hierarchy
Just _ -> [] Just _ -> []
accessView = Maybe.withDefault [] <| Maybe.map (List.singleton << viewAccessView m) <| Maybe.andThen (List.head) <| m.accessView accessView = Maybe.withDefault [] <| Maybe.map (List.singleton << viewAccessView m) <| m.accessView
remainingAccessView =
case Maybe.map (\l -> List.length l - 1) m.accessView of
Just n -> if n <= 0 then [] else
[ div [ class "alert", class "alert-info" ] [ text <|
"Simulating more than one access. " ++ (String.fromInt n) ++
" addresses in queue." ]
]
_ -> []
in in
div [ class "container" ] div [ class "container" ]
<| [ viewDescription] ++ rawView ++ accessInputView ++ remainingAccessView ++ accessView ++ cacheView <| [ viewDescription] ++ rawView ++ accessInputView ++ accessView ++ cacheView