Index: src/comp/ASyntax.hs =================================================================== --- src/comp/ASyntax.hs (revision 34711) +++ src/comp/ASyntax.hs (working copy) @@ -55,6 +55,7 @@ aTReset, aTInout, aTInout_, + isRealType, isStringType, isSizedString, isUnsizedString, @@ -460,6 +461,10 @@ aTInout n = ATAbstract idInout [n] aTInout_ n = ATAbstract idInout_ [n] +isRealType :: AType -> Bool +isRealType (ATReal) = True +isRealType _ = False + -- Useful routines for working with ATString types isStringType :: AType -> Bool isStringType (ATString _) = True Index: src/comp/AConv.hs =================================================================== --- src/comp/AConv.hs (revision 34711) +++ src/comp/AConv.hs (working copy) @@ -459,10 +459,11 @@ (ASClock _ _) -> return e' (ASReset _ _) -> return e' (ASInout _ _) -> return e' - _ | noCSE -> return e' - _ -> do - (i, t, e'') <- find e' (aType e') (getIExprPosition e) - return (ASDef t i) + (ASReal _ _ _) -> return e' + _ | noCSE -> return e' + _ -> do + (i, t, e'') <- find e' (aType e') (getIExprPosition e) + return (ASDef t i) aExprArg :: VArgInfo -> IExpr a -> M AExpr aExprArg (Param _) = aExprNoCSE Index: src/comp/PreStrings.hs =================================================================== --- src/comp/PreStrings.hs (revision 34711) +++ src/comp/PreStrings.hs (working copy) @@ -474,6 +474,7 @@ fsTestPlusargs = mkFString "$test$plusargs" fsRealToBits = mkFString "$realtobits" fsBitsToReal = mkFString "$bitstoreal" +fsBits2Real = mkFString "$bits2real" fsFile = mkFString "File" Index: src/comp/LambdaCalcUtil.hs =================================================================== --- src/comp/LambdaCalcUtil.hs (revision 34711) +++ src/comp/LambdaCalcUtil.hs (working copy) @@ -901,10 +901,6 @@ isBoolType :: AType -> Bool isBoolType t = (t == mkATBool) -isRealType :: AType -> Bool -isRealType (ATReal) = True -isRealType _ = False - getBitType :: AExpr -> AType getBitType e = case (ae_type e) of Index: src/comp/AExpand.hs =================================================================== --- src/comp/AExpand.hs (revision 34711) +++ src/comp/AExpand.hs (working copy) @@ -625,8 +625,10 @@ -- - $signed and $unsigned -- (since they only work if inlined into the appropriate system task call) -mustInline (AFunCall {ae_funname = n }) = n `elem` ["$signed", "$unsigned"] -mustInline e = isStringType (aType e) +mustInline (AFunCall {ae_funname = n }) | n `elem` ["$signed", "$unsigned"] = True +mustInline e | isRealType (aType e) = True +mustInline e | isStringType (aType e) = True +mustInline _ = False -- ============================== -- Function: expand Index: src/comp/MakeSymTab.hs =================================================================== --- src/comp/MakeSymTab.hs (revision 34711) +++ src/comp/MakeSymTab.hs (working copy) @@ -595,7 +595,7 @@ -- return result is either bits/string or is a -- primitive action/actionvalue isGoodResult :: CType -> Bool - isGoodResult t = (isTypeBit t) || (isTypeString t) || + isGoodResult t = (isTypeBit t) || (isTypeString t) || (isTypeReal t) || (isTypeActionValue_ t) || (isTypePrimAction t) isGoodArg :: CType -> Bool Index: src/comp/CType.hs =================================================================== --- src/comp/CType.hs (revision 34711) +++ src/comp/CType.hs (working copy) @@ -10,7 +10,7 @@ isTVar, isTCon, isIfc, isInterface, leftCon, leftTyCon, allTyCons, allTConNames, tyConArgs, splitTAp, normTAp, - isTypeBit, isTypeString, + isTypeBit, isTypeString, isTypeReal, isTypePrimAction, isTypeAction, isTypeActionValue, isTypeActionValue_, isTypePolyBit, bitWidth, @@ -61,7 +61,7 @@ import Position import Id import IdPrint -import PreIds(idArrow, idPrimPair, idPrimUnit, idBit, idString, +import PreIds(idArrow, idPrimPair, idPrimUnit, idBit, idString, idReal, idPrimAction, idAction, idActionValue_, idActionValue {-, idSizeOf -}) import Util(itos) @@ -385,6 +385,7 @@ isTypeBit = isTypeTConArgs idBit isTypeString = isTypeTConNoArgs idString +isTypeReal = isTypeTConNoArgs idReal isTypePrimAction = isTypeTConNoArgs idPrimAction isTypeAction = isTypeTConNoArgs idAction isTypeActionValue = isTypeTConArgs idActionValue Index: src/comp/PreIds.hs =================================================================== --- src/comp/PreIds.hs (revision 34711) +++ src/comp/PreIds.hs (working copy) @@ -522,6 +522,7 @@ idTestPlusargs = prelude_id_no fsTestPlusargs idRealToBits = prelude_id_no fsRealToBits idBitsToReal = prelude_id_no fsBitsToReal +idBits2Real = prelude_id_no fsBits2Real taskIds = [ idFinish, idStop, -- Index: src/comp/TCheck.hs =================================================================== --- src/comp/TCheck.hs (revision 34711) +++ src/comp/TCheck.hs (working copy) @@ -1653,7 +1653,8 @@ (idTestPlusargs, taskCheckNormal), -- (idRealToBits, taskCheckNormal), - (idBitsToReal, taskCheckNormal)] + (idBitsToReal, taskCheckNormal), + (idBits2Real, taskCheckNormal)] tiApply as td exp f e = do -- give the tyvar the position of the argument? Index: src/comp/AVerilogUtil.hs =================================================================== --- src/comp/AVerilogUtil.hs (revision 34711) +++ src/comp/AVerilogUtil.hs (working copy) @@ -586,6 +586,8 @@ [VMDecl $ VVDWire (vSize t_t) (VVar (vId i_t)) (vExpr vco e_t)] vDefMpd vco adef@(ADef i_t t_t@(ATString _) e_t _) _ = [VMDecl $ VVDWire (vSize t_t) (VVar (vId i_t)) (vExpr vco e_t)] +vDefMpd vco adef@(ADef i_t t_t@(ATReal) e_t _) _ = + [VMDecl $ VVDWire (vSize t_t) (VVar (vId i_t)) (vExpr vco e_t)] vDefMpd vco adef@(ADef _ _ _ _) _ = internalError( "unexpected pattern in AVerilog::vDefMpd: " ++ ppReadable adef ) ; @@ -1020,6 +1022,7 @@ vSize (ATAbstract i [n]) | i==idInout_ = Just (VEConst (n-1), VEConst 0) vSize t@(ATString (Just _)) = Just (VEConst ((aSize t)-1::Integer), VEConst 0) vSize (ATString Nothing) = Just (VEConst (dummy_string_size - 1::Integer), VEConst 0) +vSize (ATReal) = Nothing vSize t = internalError("Attempt to get size of non-Bit type: " ++ ppReadable t) -- Looks at VRange to determine if Verilog expression is 0 size [-1:0] yuck. Index: src/lib/Prelude/Prelude.bs =================================================================== --- src/lib/Prelude/Prelude.bs (revision 34711) +++ src/lib/Prelude/Prelude.bs (working copy) @@ -1369,9 +1369,14 @@ $realtobits :: Real -> Bit 64 $realtobits x = primRealToBits x -$bitstoreal :: Bit 64 -> Real -$bitstoreal x = primBitsToReal x +-- $bitstoreal :: Bit 64 -> Real +-- $bitstoreal x = primBitsToReal x +$bitstoreal :: (Bits a 64) => a -> Real +$bitstoreal x = if (isStaticIndex (pack x)) + then primBitsToReal (pack x) + else $bits2real (pack x) + -- ---------------------------------------------------------------- --@ \subsubsection{Maybe} @@ -3117,6 +3122,8 @@ foreign $signed :: Bit n -> Bit n = "$signed" foreign $unsigned :: Bit n -> Bit n = "$unsigned" +foreign $bits2real :: Bit 64 -> Real = "$bitstoreal" + -- XXX extra argument to $time and $stime to -- force applications to be saved on the heap $time :: ActionValue (Bit 64) @@ -3957,6 +3964,9 @@ instance FShow String where fshow value = $format value +instance FShow Real where + fshow value = $format "%.16g" value + instance FShow Char where fshow value = $format (charToString value) Index: src/sim/Makefile.libs =================================================================== --- src/sim/Makefile.libs (revision 34711) +++ src/sim/Makefile.libs (working copy) @@ -66,7 +66,7 @@ prim_mod_gatedclock.o \ prim_mod_resets.o \ dollar_display.o dollar_dumpvars.o dollar_plusargs.o \ - dollar_stop_finish.o dollar_time.o \ + dollar_stop_finish.o dollar_time.o dollar_bitstoreal.o \ mem_file.o module.o portability.o \ don_hack.o Index: src/sim/bs_system_tasks.h =================================================================== --- src/sim/bs_system_tasks.h (revision 34711) +++ src/sim/bs_system_tasks.h (working copy) @@ -127,4 +127,6 @@ unsigned long long bytes); extern void dollar_dumpflush(tSimStateHdl simHdl); +extern double dollar_bitstoreal(const char* ignore, tUInt64 bits); + #endif /* __BS_SYSTEM_TASKS_H__ */ Index: src/sim/dollar_bitstoreal.cxx =================================================================== --- src/sim/dollar_bitstoreal.cxx (revision 0) +++ src/sim/dollar_bitstoreal.cxx (revision 0) @@ -0,0 +1,19 @@ + +#include "bluesim_kernel_api.h" +#include +#include + +double dollar_bitstoreal(const char* ignore, tUInt64 bits) +{ + + + union Convert { + double dd; + tUInt64 u64; + }; + + Convert convert; + convert.u64 = bits; + return convert.dd; +} +