-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOptimizerMain.hs
43 lines (36 loc) · 1.77 KB
/
OptimizerMain.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import System.Environment
import System.IO
import Control.Concurrent.MVar
import Control.Monad.State
import AST
import Optimizer
import FileUtils
import MainCommon
--Author: Aleksander Balicki
--Binary for optimization, ./smopt -a does summary, cat machinefile | ./smopt 10, does optimization with 10 second time limit
main :: IO ()
main = do
args <- getArgs
case args of
[arg] -> case arg of
"-a" -> do
files <- listFiles "inputs/"
contentlist <- mapM readFile files
astlist <- mapM (oldNewAstWithSize 10 optimize) contentlist
let (oldSizeSum, newSizeSum) = foldl (\(x,y) ((_,x2),(_,y2)) -> (x+x2, y+y2)) (0,0) astlist
putStrLn $ "old size sum: " ++ show oldSizeSum
putStrLn $ "new size sum: " ++ show newSizeSum
putStrLn $ "sum delta: " ++ show (oldSizeSum - newSizeSum) ++ " (" ++
show (100.0 - (fromIntegral newSizeSum / fromIntegral oldSizeSum * 100.0) :: Double) ++ "% reduction)"
_ -> do
let time = read arg :: Int
cont <- getContents
((_, oldSize), (newAst, newSize)) <- oldNewAstWithSize time optimize cont
-- case ast of
-- Nothing -> hPutStrLn stderr "timed out"
putStrLn $ pp newAst
putStrLn $ "old size: " ++ show oldSize --(takeMVar bestSolution)
putStrLn $ "new size: " ++ show newSize
putStrLn $ "delta:" ++ show (oldSize - newSize) ++ " (" ++
show (100.0 - (fromIntegral newSize / fromIntegral oldSize * 100.0) :: Double) ++ "% reduction)"
_ -> putStrLn "Use -a for the summary run or give an Integer as an argument and pipe a machine into it"