module CacheSim.Raw exposing (..) import CacheSim.Cache exposing (..) import CacheSim.Hierarchy exposing (..) type alias RawCacheModel = { blockSize : String , setCount : String , setSize : String } type alias RawCacheModelHierarchy = List RawCacheModel translateRawCacheModel : RawCacheModel -> Result String CacheModel translateRawCacheModel rcm = let blockSizeInt = String.toInt rcm.blockSize setCountInt = String.toInt rcm.setCount setSizeInt = String.toInt rcm.setSize in case (blockSizeInt, setCountInt, setSizeInt) of (Just bs, Just sc, Just ss) -> Ok { blockSize = bs, setCount = sc, setSize = ss } (Nothing, _, _) -> Err <| "Unable to parse the block size: \"" ++ rcm.blockSize ++ "\"" (_, Nothing, _) -> Err <| "Unable to parse the set count: \"" ++ rcm.setCount ++ "\"" (_, _, Nothing) -> Err <| "Unable to parse the set size: \"" ++ rcm.setSize ++ "\"" translateRawCacheModelHierarchy : RawCacheModelHierarchy -> Result String CacheModelHierarchy translateRawCacheModelHierarchy rcmh = case rcmh of [] -> Ok [] cm::cms -> case translateRawCacheModel cm of Ok ncm -> Result.map ((::) ncm) <| translateRawCacheModelHierarchy cms Err e -> Err e validateCacheModelHierarchy : CacheModelHierarchy -> Result String CacheModelHierarchy validateCacheModelHierarchy cmh = case cmh of [] -> Ok [] x::[] -> Ok [x] x::y::xs -> if modBy x.blockSize y.blockSize == 0 then Result.map ((::) x) <| validateCacheModelHierarchy (y::xs) else Err <| "Block cache size " ++ String.fromInt y.blockSize ++ " is not a multiple of the next level cache's" ++ " block size (" ++ String.fromInt x.blockSize ++ ")"