X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=clash%2FCLasH%2FVHDL%2FGenerate.hs;h=b6aa8c63a1a39d3bc58cdf47d7b00ac1c9f8eb9b;hb=70654a9d134697f4d3703ff4a8747a1e078afd7b;hp=191ae9cf5a6e9242b54d6bbcec17047ac3c3bbfb;hpb=e82d5210946093b03d9c46b7ffbcb556304e5b0b;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git a/clash/CLasH/VHDL/Generate.hs b/clash/CLasH/VHDL/Generate.hs index 191ae9c..b6aa8c6 100644 --- a/clash/CLasH/VHDL/Generate.hs +++ b/clash/CLasH/VHDL/Generate.hs @@ -301,7 +301,7 @@ mkConcSm (bndr, expr@(CoreSyn.Case (CoreSyn.Var scrut) _ _ alts)) = do let enums = [AST.PrimLit "'1'", AST.PrimLit "'0'"] return (enums, scrut_expr) (BuiltinType "Bool") -> do - let enums = [AST.PrimLit "true", AST.PrimLit "false"] + let enums = [AST.PrimLit "false", AST.PrimLit "true"] return (enums, scrut_expr) _ -> error $ "\nSelector case on weird scrutinee: " ++ pprString scrut ++ " scrutinee type: " ++ pprString (Id.idType scrut) -- Omit first condition, which is the default. Look up each altcon in @@ -310,8 +310,9 @@ mkConcSm (bndr, expr@(CoreSyn.Case (CoreSyn.Var scrut) _ _ alts)) = do -- Compare the (constructor field of the) scrutinee with each of the -- alternatives. let cond_exprs = map (\x -> cmp AST.:=: x) altcons - -- Rotate expressions to the left, so that the expression related to the default case is the last - exprs <- MonadState.lift tsType $ mapM (varToVHDLExpr . (\(_,_,CoreSyn.Var expr) -> expr)) ((tail alts) ++ [head alts]) + -- Rotate expressions to the leftso that the expression related to the default case is the last + let alts' = (tail alts) ++ [head alts] + exprs <- MonadState.lift tsType $ mapM (varToVHDLExpr . (\(_,_,CoreSyn.Var expr) -> expr)) alts' --((tail alts) ++ [head alts]) return ([mkAltsAssign (Left bndr) cond_exprs exprs], []) mkConcSm (_, CoreSyn.Case _ _ _ _) = error "\nVHDL.mkConcSm: Not in normal form: Case statement does not have a simple variable as scrutinee" @@ -496,7 +497,7 @@ genFromInteger' (Left res) f args = do "Unsigned" -> MonadState.lift tsType $ tfp_to_int (sized_word_len_ty ty) "Index" -> do bound <- MonadState.lift tsType $ tfp_to_int (ranged_word_bound_ty ty) - return $ floor (logBase 2 (fromInteger (toInteger (bound)))) + 1 + return $ (ceiling (logBase 2 (fromInteger (toInteger (bound))))) let fname = case name of "Signed" -> toSignedId ; "Unsigned" -> toUnsignedId ; "Index" -> toUnsignedId case args of [integer] -> do -- The type and dictionary arguments are removed by genApplication