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

bsc: remove use of old-time #721

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 4 additions & 6 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ Debian and Ubuntu systems, you can say:
$ apt-get install \
libghc-regex-compat-dev \
libghc-syb-dev \
libghc-old-time-dev \
libghc-split-dev

The second command will install the Haskell libraries `regex-compat`, `syb`,
`old-time`, and `split`, as well as some libraries that they depend on.
and `split`, as well as some libraries that they depend on.

If you wish to do profiling builds of the compiler itself, you will also need
to install versions of the Haskell libraries built using the profiling flags.
Expand All @@ -70,7 +69,6 @@ On Debian and Ubuntu, this can be done with:
ghc-prof \
libghc-regex-compat-prof \
libghc-syb-prof \
libghc-old-time-prof \
libghc-split-prof

You can do the analogous package-install on other Linux distributions using
Expand All @@ -87,12 +85,12 @@ commands to install Haskell libraries.
For cabal v2.x:

$ cabal update
$ cabal install regex-compat syb old-time split
$ cabal install regex-compat syb split

For cabal v3.x:

$ cabal update
$ cabal v1-install regex-compat syb old-time split
$ cabal v1-install regex-compat syb split

Cabal's newer `v2-install` has the advantage of not installing the
libraries into the GHC installation. This is useful if the GHC
Expand All @@ -104,7 +102,7 @@ passing an additional flag to GHC, which can be done by defining `GHC`
in the environment when calling `make` in the later steps.
For example (cabal v3.x only):

$ cabal v2-install --package-env=default syb old-time split
$ cabal v2-install --package-env=default syb split
$ make GHC="ghc -package-env default"

Bluespec compiler builds are tested with GHC 9.4.8.
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TOOLS=$(CC_TOOLS) \
$(YICES_TOOLS) \
$(STP_TOOLS) \

GHC_PKGS=regex-compat syb old-time split
GHC_PKGS=regex-compat syb split

SUBMODS=vendor/yices/v2.6/yices2

Expand Down
1 change: 0 additions & 1 deletion src/comp/ABin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ data ABinModInfo =
-- the name of the BSV package which defined this module
abmi_src_name :: String,
-- time when BSC was called to compile the .ba
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This accompanying comment would need to be removed too

--abmi_time :: ClockTime,
abmi_apkg :: APackage,
abmi_aschedinfo :: AScheduleInfo,
-- if this can be used prior to generating abin,
Expand Down
23 changes: 7 additions & 16 deletions src/comp/Depend.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import Control.Monad(when)
import System.Process(system)
import System.Exit(ExitCode(..))
import System.Directory(getModificationTime)
import System.Time -- XXX: in old-time package
import System.IO.Error(ioeGetErrorType)
import GHC.IO.Exception(IOErrorType(..))
import Data.Time.Clock.POSIX(utcTimeToPOSIXSeconds)
import Data.Time
import qualified Control.Exception as CE
import qualified Data.Map as DM

Expand Down Expand Up @@ -49,13 +48,11 @@ type PkgName = Id
type ModName = Id
type ForeignName = Id

type MClockTime = Maybe ClockTime

data PkgInfo = PkgInfo {
pkgName :: PkgName,
fileName :: FileName,
srcMod :: MClockTime,
lastMod :: MClockTime,
srcMod :: Maybe UTCTime,
lastMod :: Maybe UTCTime,
imports :: [PkgName],
includes :: [FileName],
gens :: [ModName],
Expand All @@ -65,12 +62,6 @@ data PkgInfo = PkgInfo {
}
deriving (Show)

getModificationTime' :: FilePath -> IO ClockTime
getModificationTime' file =
do utcTime <- getModificationTime file
let s = (floor . utcTimeToPOSIXSeconds) utcTime
return (TOD s 0)

-- returns a list of Bluespec source files which need recompiling.
-- (This used to also return a list of all generated files which would
-- result from codegen, so that a later stage could link them. But this
Expand Down Expand Up @@ -294,15 +285,15 @@ isPreludePkg flags n =
-- Check if out-of-date with respect to an imported module.
-- Recompilation is needed if the imported file will be
-- recompiled or if it has a later date stamp.
needsUpd :: MClockTime -> [PkgInfo] -> PkgName -> Bool
needsUpd :: Maybe UTCTime -> [PkgInfo] -> PkgName -> Bool
needsUpd myMod pis n =
case findInfo n pis of
Nothing -> internalError ("needsUpd " ++ pfpString n)
Just pi -> recompile pi || lastMod pi > myMod

getModTime :: String -> IO MClockTime
getModTime f = CE.catch (getModificationTime' f >>= return . Just) handler
where handler :: CE.SomeException -> IO MClockTime
getModTime :: String -> IO (Maybe UTCTime)
getModTime f = CE.catch (getModificationTime f >>= return . Just) handler
where handler :: CE.SomeException -> IO (Maybe UTCTime)
handler _ = return Nothing

-----
Expand Down
1 change: 0 additions & 1 deletion src/comp/GenABin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module GenABin(genABinFile, readABinFile) where
import Error(internalError, ErrMsg(..), ErrorHandle, bsErrorUnsafe)
import Position

--import Time(ClockTime)
import Backend
import Wires
import ASyntax
Expand Down
12 changes: 6 additions & 6 deletions src/comp/IExpandUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ import Control.Monad(when, liftM)
import Control.Monad.State(StateT, runStateT, evalStateT, lift, liftIO,
gets, get, put, modify)
import Data.IORef
import System.IO.Unsafe
import Data.Time
import Data.List
import Data.Maybe
import Data.Char(isAlphaNum)
import System.Time -- XXX: from old-time package
import Debug.Trace(traceM)
import qualified Data.Array as Array
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Generics as Generic
import Debug.Trace(traceM)
import System.IO.Unsafe

import Eval
import PPrint
Expand Down Expand Up @@ -2072,9 +2072,9 @@ newIStateLocForRule id hide [] = internalError "newIStateLocForRule: Empty loc"

traceProgress :: String -> G ()
traceProgress str = liftIO $ do
ct <- getClockTime
now <- toCalendarTime ct
traceM ("[" ++ calendarTimeToString now ++ "] elab progress: " ++ str)
ct <- getCurrentTime
tz <- getCurrentTimeZone
traceM ("[" ++ show (utcToLocalTime tz ct) ++ "] elab progress: " ++ str)

showTopProgress :: String -> G ()
showTopProgress str = do
Expand Down
4 changes: 1 addition & 3 deletions src/comp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ $(warning Building unoptimized to work around a bug in GHC 9.2.1)
GHCOPTLEVEL ?= -O0
endif

GHC += -Wtabs -fmax-pmcheck-models=800
GHC += -Wtabs -fmax-pmcheck-models=800 -freverse-errors
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this GHC flag change belong in this PR?


# end ifeq ($(GHCMAJOR),9)
else
Expand Down Expand Up @@ -134,8 +134,6 @@ PACKAGES = \
-package process \
-package filepath \
-package time \
-package old-time \
-package old-locale \
-package split \
-package syb \
-package integer-gmp \
Expand Down
27 changes: 15 additions & 12 deletions src/comp/SimBlocksToC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import Data.List(nub, (\\), find, genericLength, sortBy, groupBy)
import Data.List.Split(wordsBy)
import Data.Maybe(catMaybes, isJust, fromJust)
import Data.Function(on)
import Data.Time
import Data.Time.Clock.POSIX
import Control.Monad.State(runState)
import System.Time -- XXX: in old-time package
import qualified Data.Map as M

import ErrorUtil(internalError)
Expand All @@ -26,7 +27,6 @@ import VModInfo(vName_to_id)
import PPrint(ppReadable) -- hiding (int, char)
import Util(concatMapM, mapFst, mapSnd)
import SimFileUtils(codeGenOptionDescr)
import TopUtils(TimeInfo(..))
import Version(versionname)
import BuildVersion(buildVersion)

Expand All @@ -35,13 +35,13 @@ import BuildVersion(buildVersion)
-- Create many .cxx and .h files from the entire list of SimCCBlocks
-- and SimCCScheds. The blocks are grouped by module, the schedules
-- cut across all modules.
simBlocksToC :: Flags -> TimeInfo -> SBId ->
simBlocksToC :: Flags -> Maybe UTCTime -> SBId ->
(Maybe String) -> (Maybe String) ->
SBMap -> ForeignFuncMap ->
[String] -> [SimCCBlock] -> [SimCCSched] ->
[SimCCClockGroup] -> SimCCGateInfo ->
(String -> String -> IO String) -> IO [String]
simBlocksToC flags time top_block def_clk def_rst
simBlocksToC flags mcreation_time top_block def_clk def_rst
sb_map ff_map reused mod_blocks scheds
clk_groups gate_info writeFileC = do
let sub_ids = [ i | sb <- M.elems sb_map, (i, _, _) <- sb_state sb ]
Expand Down Expand Up @@ -95,7 +95,7 @@ simBlocksToC flags time top_block def_clk def_rst

let cvtModBlock = convertModuleBlock flags sb_map ff_map clk_map wdef_mod_map reused top_block
module_names <- concatMapM (cvtModBlock writeFileC) mod_blocks
schedule_names <- convertSchedules flags time top_block def_clk def_rst sb_map ff_map
schedule_names <- convertSchedules flags mcreation_time top_block def_clk def_rst sb_map ff_map
wdef_inst_map scheds clk_groups gate_info writeFileC
return $ module_names ++ schedule_names

Expand Down Expand Up @@ -207,12 +207,12 @@ convertModuleBlock flags sb_map ff_map clk_map wdef_mod_map reused top_blk write
writeFileC

-- Convert the schedule and reset functions into .cxx and .h files
convertSchedules :: Flags -> TimeInfo -> SBId ->
convertSchedules :: Flags -> Maybe UTCTime -> SBId ->
(Maybe String) -> (Maybe String) ->
SBMap -> ForeignFuncMap -> M.Map String [AId] ->
[SimCCSched] -> [SimCCClockGroup] -> SimCCGateInfo ->
(String -> String -> IO String) -> IO [String]
convertSchedules flags creation_time top_id def_clk def_rst sb_map ff_map
convertSchedules flags mcreation_time top_id def_clk def_rst sb_map ff_map
wdef_map scheds clk_groups gate_info writeFileC = do
let ids = []
top_blk = lookupSB sb_map top_id
Expand Down Expand Up @@ -489,12 +489,15 @@ convertSchedules flags creation_time top_id def_clk def_rst sb_map ff_map
get_creation_time = function (userType "time_t")
(mkScopedVar "get_creation_time")
[]
(TimeInfo _ clock_time@(TOD t _)) = if (timeStamps flags)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the flag check from here and put it in the caller?

then creation_time
else TimeInfo 0 (TOD 0 0)
time_str = calendarTimeToString (toUTCTime clock_time)

( time_str, time_secs ) = case mcreation_time of
Nothing -> ( "1970-01-01 00:00:00 UTC", 0 )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to create a UTCTime value representing this and call show on it?

Just clock_time -> ( show clock_time
, floor $ nominalDiffTimeToSeconds (utcTimeToPOSIXSeconds clock_time)
)

gct_def = define get_creation_time
(comment time_str (ret (Just (mkUInt64 t))))
(comment time_str (ret (Just (mkUInt64 time_secs))))
version_methods = [ comment "Fill in version numbers" gv_def
, comment "Get the model creation time" gct_def
]
Expand Down
20 changes: 7 additions & 13 deletions src/comp/TopUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module TopUtils where
#if defined(__GLASGOW_HASKELL__) && (__GLASGOW_HASKELL__ >= 804)
import Prelude hiding ((<>))
#endif
import Data.Time
import Text.Printf(printf)
import System.IO(hFlush, stdout)
import System.CPUTime(getCPUTime)
import Control.Monad(when, unless)
import Control.Monad.Trans(MonadIO(..))
import System.Time -- XXX: from old-time package
-- hbc libs
import PFPrint
-- utility libs
Expand Down Expand Up @@ -189,24 +189,18 @@ commentC ls = unlines (["/*"] ++ map (" * " ++) ls ++ [" */"])
commentV ls = unlines (["//"] ++ map ("// " ++) ls ++ ["//"])

-----

getCPUTimeDoublePortable :: IO Double
getCPUTimeDoublePortable = do
t <- getCPUTime
return (fromInteger t * 1.0e-12)

data TimeInfo = TimeInfo Double ClockTime
data TimeInfo = TimeInfo Double UTCTime
deriving (Show)

getNow :: IO TimeInfo
getNow = do
t <- getCPUTimeDoublePortable
ct <- getClockTime
-- get portable cpu time
t <- fmap (\t -> fromInteger t * 1.0e-12) getCPUTime
ct <- getCurrentTime
return (TimeInfo t ct)

diffTimeInfo :: TimeInfo -> TimeInfo -> (Double, Double)
diffTimeInfo (TimeInfo t ct) (TimeInfo t' ct') = (t'-t, tdToDouble (diffClockTimes ct' ct))
where tdToDouble d = fromIntegral ((tdHour d * 60 + tdMin d) * 60 + tdSec d) + fromInteger (tdPicosec d) * 1.0e-12
diffTimeInfo (TimeInfo t ct) (TimeInfo t' ct') = (t' - t, realToFrac (diffUTCTime ct' ct))

putStrLnF :: String -> IO ()
putStrLnF s = do putStrLn s; hFlush stdout
Expand Down Expand Up @@ -294,7 +288,7 @@ showCnt cnt s = text $ itos cnt ++ " " ++ s
-- | Makes a timestamp string for generated code, respecting the timeStamps flag
mkTimestampComment :: Flags -> IO String
mkTimestampComment flags
| timeStamps flags = getClockTime >>= return . ("On " ++) . show
| timeStamps flags = getCurrentTime >>= return . ("On " ++) . show
| otherwise = return ""

mkGenFileHeader :: Flags -> IO [String]
Expand Down
Loading
Loading