From 5023b6c341c8aa7638aa3fdb4518bb48661894ca Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 28 May 2019 19:01:14 -0700 Subject: [PATCH] Add basic hierarchy code. --- src/CacheSim/Hierarchy.elm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/CacheSim/Hierarchy.elm diff --git a/src/CacheSim/Hierarchy.elm b/src/CacheSim/Hierarchy.elm new file mode 100644 index 0000000..64bfd74 --- /dev/null +++ b/src/CacheSim/Hierarchy.elm @@ -0,0 +1,23 @@ +module CacheSim.Hierarchy exposing (..) +import CacheSim.Cache exposing (..) + +type alias CacheModelHierarchy = List CacheModel +type alias CacheHierarchy = List Cache + +accessCacheHierarchy : WordAddr -> CacheHierarchy -> Result String (List (AccessEffect Cache)) +accessCacheHierarchy wa ch = + case ch of + [] -> Ok [] + c::cs -> + case accessCache wa c of + Ok { result, output } -> + case result of + Hit -> + Ok [ { result = Hit, output = output } ] + Miss -> + Result.map ((::) { result = Miss, output = output }) + <| accessCacheHierarchy wa cs + Err e -> Err e + +freshCacheHierarchy : CacheModelHierarchy -> CacheHierarchy +freshCacheHierarchy cmh = List.map freshCache cmh