first commit
This commit is contained in:
commit
ef58d5b07e
34 changed files with 2210 additions and 0 deletions
7
bin/Clash.hs
Normal file
7
bin/Clash.hs
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
import Prelude
|
||||
import System.Environment (getArgs)
|
||||
import Clash.Main (defaultMain)
|
||||
|
||||
main :: IO ()
|
||||
main = getArgs >>= defaultMain
|
7
bin/Clashi.hs
Normal file
7
bin/Clashi.hs
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
import Prelude
|
||||
import System.Environment (getArgs)
|
||||
import Clash.Main (defaultMain)
|
||||
|
||||
main :: IO ()
|
||||
main = getArgs >>= defaultMain . ("--interactive":)
|
46
bin/Main.hs
Normal file
46
bin/Main.hs
Normal file
|
@ -0,0 +1,46 @@
|
|||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
{-# LANGUAGE ConstraintKinds #-}
|
||||
|
||||
module Main where
|
||||
|
||||
import Prelude
|
||||
import System.Environment (getArgs, getProgName)
|
||||
import System.Exit (exitFailure)
|
||||
import Data.Maybe (listToMaybe)
|
||||
import Data.List (isPrefixOf)
|
||||
import Text.Show.Pretty (ppShow)
|
||||
|
||||
import Simulation (simulation, Args(..))
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
rawArgs <- getArgs
|
||||
args <- parseArgs rawArgs
|
||||
states <- simulation args
|
||||
putStrLn "Simulating Machine"
|
||||
-- mapM_ (putStrLn . ppShow) states -- Uncomment to print each state, if needed.
|
||||
putStrLn $ "Last state: " ++ show (last states)
|
||||
putStrLn $ "Executed for " ++ show (length states) ++ " cycles"
|
||||
putStrLn "Simulation complete"
|
||||
|
||||
-- Function to parse command line arguments into the Args data type
|
||||
parseArgs :: [String] -> IO Args
|
||||
parseArgs argv =
|
||||
case extractKey "firmware" argv of
|
||||
Just firmwarePath -> return Args { firmware = firmwarePath }
|
||||
Nothing -> do
|
||||
progName <- getProgName
|
||||
putStrLn "Error: No firmware file found."
|
||||
putStrLn $ "Usage: " ++ progName ++ " --firmware=FILE"
|
||||
exitFailure
|
||||
|
||||
filterByKey :: String -> [String] -> [String]
|
||||
filterByKey key argv = filter (switch `isPrefixOf`) argv
|
||||
where
|
||||
switch = "--" ++ key ++ "="
|
||||
|
||||
extractKey :: String -> [String] -> Maybe String
|
||||
extractKey key argv = listToMaybe $ map removePrefix $ filterByKey key argv
|
||||
where removePrefix = drop $ length ("--" ++ key ++ "=")
|
Reference in a new issue