Commit bdc7b5ad by Zachary Snow

replace some invariant errors with pattern matching

parent cfff359b
...@@ -261,10 +261,9 @@ convertExpr scopes = ...@@ -261,10 +261,9 @@ convertExpr scopes =
baseOuter' = orientIdx dimOuter baseOuter baseOuter' = orientIdx dimOuter baseOuter
start = BinOp Mul idxInner' (rangeSize dimOuter) start = BinOp Mul idxInner' (rangeSize dimOuter)
baseDec = BinOp Add start baseOuter' baseDec = BinOp Add start baseOuter'
baseInc = case modeOuter of baseInc = if modeOuter == IndexedPlus
IndexedPlus -> BinOp Add (BinOp Sub baseDec len) one then BinOp Add (BinOp Sub baseDec len) one
IndexedMinus -> BinOp Sub (BinOp Add baseDec len) one else BinOp Sub (BinOp Add baseDec len) one
NonIndexed -> error "invariant violated"
base = endianCondExpr dimOuter baseDec baseInc base = endianCondExpr dimOuter baseDec baseInc
len = lenOuter len = lenOuter
range' = (base, len) range' = (base, len)
...@@ -309,16 +308,15 @@ convertExpr scopes = ...@@ -309,16 +308,15 @@ convertExpr scopes =
lenOrigMinusOne = BinOp Sub lenOrig (RawNum 1) lenOrigMinusOne = BinOp Sub lenOrig (RawNum 1)
baseSwapped = baseSwapped =
orientIdx dimInner $ orientIdx dimInner $
case mode of if mode == IndexedPlus
IndexedPlus -> then
endianCondExpr dimInner endianCondExpr dimInner
baseOrig baseOrig
(BinOp Add baseOrig lenOrigMinusOne) (BinOp Add baseOrig lenOrigMinusOne)
IndexedMinus -> else
endianCondExpr dimInner endianCondExpr dimInner
(BinOp Sub baseOrig lenOrigMinusOne) (BinOp Sub baseOrig lenOrigMinusOne)
baseOrig baseOrig
NonIndexed -> error "invariant violated"
base = BinOp Add offsetOuter (BinOp Mul sizeOuter baseSwapped) base = BinOp Add offsetOuter (BinOp Mul sizeOuter baseSwapped)
mode' = IndexedPlus mode' = IndexedPlus
len = BinOp Mul sizeOuter lenOrig len = BinOp Mul sizeOuter lenOrig
......
...@@ -52,8 +52,7 @@ convert files = ...@@ -52,8 +52,7 @@ convert files =
isNonDefault = (name /=) . moduleName isNonDefault = (name /=) . moduleName
alreadyExists = (flip Map.member info) . moduleName alreadyExists = (flip Map.member info) . moduleName
moduleName :: Description -> Identifier moduleName :: Description -> Identifier
moduleName (Part _ _ _ _ x _ _) = x moduleName = \(Part _ _ _ _ x _ _) -> x
moduleName _ = error "not possible"
explodeDescription other = [other] explodeDescription other = [other]
-- remove or rewrite source modules that are no longer needed -- remove or rewrite source modules that are no longer needed
...@@ -109,7 +108,7 @@ convert files = ...@@ -109,7 +108,7 @@ convert files =
replaceDefault _ other = [other] replaceDefault _ other = [other]
removeDefaultTypeParams :: Description -> Description removeDefaultTypeParams :: Description -> Description
removeDefaultTypeParams (part @ Part{}) = removeDefaultTypeParams part =
Part attrs extern kw ml (moduleDefaultName name) p items Part attrs extern kw ml (moduleDefaultName name) p items
where where
Part attrs extern kw ml name p items = Part attrs extern kw ml name p items =
...@@ -118,7 +117,6 @@ convert files = ...@@ -118,7 +117,6 @@ convert files =
rewriteDecl (ParamType Parameter x _) = rewriteDecl (ParamType Parameter x _) =
ParamType Parameter x UnknownType ParamType Parameter x UnknownType
rewriteDecl other = other rewriteDecl other = other
removeDefaultTypeParams _ = error "not possible"
isUsed :: Identifier -> Bool isUsed :: Identifier -> Bool
isUsed name = isUsed name =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment