Create "raw" (string-based) cache model types for user input.
This commit is contained in:
parent
5023b6c341
commit
ddfd65b099
49
src/CacheSim/Raw.elm
Normal file
49
src/CacheSim/Raw.elm
Normal file
|
@ -0,0 +1,49 @@
|
|||
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 y.blockSize x.blockSize == 0
|
||||
then validateCacheModelHierarchy (y::xs)
|
||||
else Err <| "Block cache size " ++ String.fromInt x.blockSize ++
|
||||
" is not a multiple of the next level cache's" ++
|
||||
" block size (" ++ String.fromInt y.blockSize ++ ")"
|
Loading…
Reference in New Issue
Block a user