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
------------------------------------------------------------------------------
--- A tool to reduce the size of FlatCurry programs by replacing
--- the main FlatCurry file by a single FlatCurry file containing
--- no imports but all imported and potentially called functions.
---
--- @author Michael Hanus
--- @version June 2009
------------------------------------------------------------------------------

import List(intersperse)
import System
import FlatCurry.Types
import FlatCurry.Files
import FlatCurry.Compact

-- Check arguments and call main function:
main = do
  args <- getArgs
  case args of
    [prog]              -> compactProgAndReplace [] prog
    ["-export",prog]    -> compactProgAndReplace [Exports] prog
    ["-main",func,prog] -> compactProgAndReplace [Main func] prog
    _ -> putStrLn $ "ERROR: Illegal arguments: " ++
           concat (intersperse " " args) ++ "\n" ++
           "Usage: curry-compactflat [-export | -main func] <module_name>"

-- replace a FlatCurry program by a compactified version:
compactProgAndReplace options prog = do
  generateCompactFlatCurryFile (Required defaultRequired : options)
                               prog (prog++"_comp.fcy")
  let progfcy = flatCurryFileName prog
  system $ "mv "++prog++"_comp.fcy "++progfcy
  putStr $ "curry-compactflat: compacted program '"++progfcy++"' written.\n"