Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch to make kansas-lava compile with GHC 7.6 #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Language/KansasLava/Netlist/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ToTypedExpr v where
-- | Given a type and a value, convert it to a netlist Expr.
toTypedExpr :: Type -> v -> Expr

instance (Integral a) => ToTypedExpr (Driver a) where
instance (Show a, Integral a) => ToTypedExpr (Driver a) where
-- From a std_logic* into a typed Expr
toTypedExpr ty (Lit n) = toTypedExpr ty n
toTypedExpr ty (Generic n) = toTypedExpr ty n
Expand Down Expand Up @@ -75,11 +75,11 @@ fromIntegerToExpr t i =
instance ToTypedExpr RepValue where
-- From a literal into a typed Expr
-- NOTE: We use Integer here as a natural, and assume overflow
toTypedExpr (S n) r = ExprFunCall "to_signed"
toTypedExpr (S n) r = ExprFunCall "to_signed"
[ ExprLit Nothing $ ExprNum $ fromRepToInteger r
, ExprLit Nothing $ ExprNum $ fromIntegral n
]
toTypedExpr (U n) r = ExprFunCall "to_unsigned"
toTypedExpr (U n) r = ExprFunCall "to_unsigned"
[ ExprLit Nothing $ ExprNum $ fromRepToInteger r
, ExprLit Nothing $ ExprNum $ fromIntegral n
]
Expand All @@ -98,7 +98,7 @@ class ToStdLogicExpr v where
toStdLogicEleExpr :: Int -> Type -> v -> Expr
toStdLogicEleExpr = error "toStdLogicEleExpr"

instance (Integral a) => ToStdLogicExpr (Driver a) where
instance (Show a, Integral a) => ToStdLogicExpr (Driver a) where
-- From a std_logic* (because you are a driver) into a std_logic.
toStdLogicExpr ty _
| typeWidth ty == 0 = ExprVar "\"\""
Expand Down Expand Up @@ -160,7 +160,7 @@ class ToIntegerExpr v where
-- | Given a type and a signal, generate the appropriate Netlist Expr.
toIntegerExpr :: Type -> v -> Expr

instance (Integral i) => ToIntegerExpr (Driver i) where
instance (Show i, Integral i) => ToIntegerExpr (Driver i) where
-- can assume a small (shift-by) number
toIntegerExpr _ (Lit v) = ExprLit Nothing $ ExprNum (fromRepToInteger v)
toIntegerExpr GenericTy other = toTypedExpr GenericTy other -- HACK
Expand Down Expand Up @@ -240,7 +240,7 @@ isHigh (ExprLit Nothing (ExprBit T)) = ExprVar "true"
isHigh d = ExprBinary Equals d (ExprLit Nothing (ExprBit T))

-- | Convert a driver to an Expr to be used as a memory address.
toMemIndex :: Integral t => Type -> Driver t -> Expr
toMemIndex :: (Show t, Integral t) => Type -> Driver t -> Expr
toMemIndex ty _ | typeWidth ty == 0 = ExprLit Nothing (ExprNum 0)
toMemIndex _ (Lit n) = ExprLit Nothing $ ExprNum $ fromRepToInteger n
toMemIndex ty dr = to_integer $ unsigned $ toStdLogicExpr ty dr
Expand Down
5 changes: 3 additions & 2 deletions Language/KansasLava/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Paths_kansas_lava

import Control.Applicative
import qualified Control.Exception as E
import qualified System.IO.Error as IOE (catchIOError)
import Control.Monad
import Data.List as List
import Data.Maybe as Maybe
Expand Down Expand Up @@ -802,10 +803,10 @@ readPreludeFile :: String -> IO String
readPreludeFile fname = do
ks <- getEnv "KANSAS_LAVA_ROOT"
Strict.readFile (ks </> fname)
`Prelude.catch` \_ -> do
`IOE.catchIOError` \_ -> do
path <- getDataFileName fname
Strict.readFile path
`Prelude.catch` \_ -> do
`IOE.catchIOError` \_ -> do
putStrLn "Set the KANSAS_LAVA_ROOT environment variable"
putStrLn "to point to the root of the KsLava source directory."
exitFailure
Expand Down
4 changes: 2 additions & 2 deletions Language/KansasLava/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,9 @@ iterateS f start = out where
---------------------------------------------------------------------

-- These varients of succ/pred can handle bounded values and do proper looping.
loopingIncS :: (Bounded a, Num a, Rep a, sig ~ Signal i) => sig a -> sig a
loopingIncS :: (Eq a, Bounded a, Num a, Rep a, sig ~ Signal i) => sig a -> sig a
loopingIncS a = mux (a .==. maxBound) (a + 1, pureS 0)

loopingDecS :: (Bounded a, Num a, Rep a, sig ~ Signal i) => sig a -> sig a
loopingDecS :: (Eq a, Bounded a, Num a, Rep a, sig ~ Signal i) => sig a -> sig a
loopingDecS a = mux (a .==. 0) (a - 1, pureS maxBound)