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