Merge git://github.com/darchon/clash into cλash
authorMatthijs Kooijman <m.kooijman@student.utwente.nl>
Tue, 14 Jul 2009 11:00:13 +0000 (13:00 +0200)
committerMatthijs Kooijman <m.kooijman@student.utwente.nl>
Tue, 14 Jul 2009 11:00:13 +0000 (13:00 +0200)
* git://github.com/darchon/clash:
  Added resize function

1  2 
Generate.hs

diff --combined Generate.hs
index 66dca927241cdca4091c2ead955120991e7207f1,1af1be33a63c977b0e5630f2fd32c0dec097efc5..f4cab36460d4f1b1b9e39ce5dc8819a582c68102
@@@ -42,8 -42,17 +42,8 @@@ genExprArgs wrap dst func args = d
    args' <- eitherCoreOrExprArgs args
    wrap dst func args'
  
 -idM :: a -> VHDLSession a
 -idM e = return e
 -
 -eitherM :: (a -> m c) -> (b -> m c) -> Either a b -> m c
 -eitherM f1 f2 e = do
 -  case e of
 -    Left e1 -> f1 e1
 -    Right e2 -> f2 e2
 -    
  eitherCoreOrExprArgs :: [Either CoreSyn.CoreExpr AST.Expr] -> VHDLSession [AST.Expr]
 -eitherCoreOrExprArgs args = mapM (eitherM (\x -> MonadState.lift vsType $ (varToVHDLExpr (exprToVar x))) idM) args
 +eitherCoreOrExprArgs args = mapM (Either.either ((MonadState.lift vsType) . varToVHDLExpr . exprToVar) return) args
  
  -- | A function to wrap a builder-like function that expects its arguments to
  -- be variables.
@@@ -125,6 -134,22 +125,22 @@@ genFromSizedWord' (Left res) f args = d
               map (\exp -> Nothing AST.:=>: AST.ADExpr exp) args
  genFromSizedWord' (Right name) _ _ = error $ "\nGenerate.genFromSizedWord': Cannot generate builtin function call assigned to a VHDLName: " ++ show name
  
+ genResize :: BuiltinBuilder
+ genResize = genExprArgs $ genExprRes genResize'
+ genResize' :: Either CoreSyn.CoreBndr AST.VHDLName -> CoreSyn.CoreBndr -> [AST.Expr] -> VHDLSession AST.Expr
+ genResize' (Left res) f [arg] = do {
+   ; let { ty = Var.varType res
+         ; (tycon, args) = Type.splitTyConApp ty
+         ; name = Name.getOccString (TyCon.tyConName tycon)
+         } ;
+   ; len <- case name of
+       "SizedInt" -> MonadState.lift vsType $ tfp_to_int (sized_int_len_ty ty)
+       "SizedWord" -> MonadState.lift vsType $ tfp_to_int (sized_word_len_ty ty)
+   ; return $ AST.PrimFCall $ AST.FCall (AST.NSimple (mkVHDLBasicId resizeId))
+              [Nothing AST.:=>: AST.ADExpr arg, Nothing AST.:=>: AST.ADExpr( AST.PrimLit (show len))]
+   }
+ genResize' (Right name) _ _ = error $ "\nGenerate.genFromSizedWord': Cannot generate builtin function call assigned to a VHDLName: " ++ show name
  -- FIXME: I'm calling genLitArgs which is very specific function,
  -- which needs to be fixed as well
  genFromInteger :: BuiltinBuilder
@@@ -1017,4 -1042,5 +1033,5 @@@ globalNameTable = Map.fromLis
    , (minusId          , (2, genOperator2 (AST.:-:)  ) )
    , (fromSizedWordId  , (1, genFromSizedWord        ) )
    , (fromIntegerId    , (1, genFromInteger          ) )
+   , (resizeId         , (1, genResize               ) )
    ]