Run MiMa for a specified amount of steps
Also, print IP and Acc at the time of the dump
This commit is contained in:
parent
082a205a7e
commit
1c895add5a
2 changed files with 33 additions and 9 deletions
|
|
@ -1,3 +1,5 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module MimaRun where
|
||||
|
||||
import Control.Monad
|
||||
|
|
@ -7,6 +9,7 @@ import Options.Applicative
|
|||
import Mima.Load
|
||||
import Mima.State
|
||||
import Mima.Util
|
||||
import Mima.Word
|
||||
|
||||
data Settings = Settings
|
||||
{ infile :: String
|
||||
|
|
@ -53,12 +56,17 @@ runMima settings s =
|
|||
case steps settings of
|
||||
Nothing -> do
|
||||
putStrLn "Running until HALT or execution exception..."
|
||||
let (s', e) = run s
|
||||
let (s', e, x) = run s
|
||||
putStrLn $ "Ran for " ++ show x ++ " steps"
|
||||
T.putStrLn $ toText e
|
||||
pure s'
|
||||
Just _ -> do
|
||||
putStrLn "This option is currently not supported"
|
||||
undefined
|
||||
Just n -> do
|
||||
let (s', me, x) = runN n s
|
||||
putStrLn $ "Ran for " ++ show x ++ " steps"
|
||||
case me of
|
||||
Nothing -> putStrLn "Encountered no exception"
|
||||
Just e -> T.putStrLn $ toText e
|
||||
pure s'
|
||||
|
||||
-- TODO exception handling
|
||||
main :: IO ()
|
||||
|
|
@ -71,6 +79,9 @@ main = do
|
|||
let s = initialState mem
|
||||
s' <- if norun settings then pure s else runMima settings s
|
||||
|
||||
T.putStrLn $ "IP: " <> addrToHexDec (msIp s') <> " "
|
||||
<> "Acc: " <> wordToHexDec (msAcc s')
|
||||
|
||||
unless (quiet settings) $ do
|
||||
putStrLn "Dump of memory:"
|
||||
T.putStrLn $ memoryToText (sparse settings) (msMemory s')
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ module Mima.State
|
|||
, ExecException(..)
|
||||
, step
|
||||
, run
|
||||
, runN
|
||||
) where
|
||||
|
||||
import Data.Bits
|
||||
|
|
@ -146,8 +147,20 @@ executeLargeOpcode HALT ms =
|
|||
executeLargeOpcode NOT ms = incrementIp ms{msAcc = complement (msAcc ms)}
|
||||
executeLargeOpcode RAR ms = incrementIp ms{msAcc = rotateR (msAcc ms) 1}
|
||||
|
||||
run :: MimaState -> (MimaState, ExecException)
|
||||
run ms =
|
||||
case step ms of
|
||||
Left e -> (ms, e)
|
||||
Right ms' -> run ms'
|
||||
run :: MimaState -> (MimaState, ExecException, Integer)
|
||||
run ms = helper 0 ms
|
||||
where
|
||||
helper completed s =
|
||||
case step s of
|
||||
Left e -> (s, e, completed)
|
||||
Right s' -> helper (completed + 1) s'
|
||||
|
||||
runN :: Integer -> MimaState -> (MimaState, Maybe ExecException, Integer)
|
||||
runN n ms = helper 0 ms
|
||||
where
|
||||
helper completed s =
|
||||
if completed >= n
|
||||
then (s, Nothing, completed)
|
||||
else case step s of
|
||||
Left e -> (s, Just e, completed)
|
||||
Right s' -> helper (completed + 1) s'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue