Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 145 lines (126 sloc) 5.373 kb
738525c Moved Main.lhs
eb authored
1 > module Main where
2
9b56d0a Updated for GHC 7.2 (thanks to Sebastian Fischer)
Edwin Brady authored
3 > import System.Exit
738525c Moved Main.lhs
eb authored
4 > import System.Directory
5 > import System.Environment
6 > import System.IO
2bbafff Add -g option for debug info
eb authored
7 > import Distribution.Version
9b56d0a Updated for GHC 7.2 (thanks to Sebastian Fischer)
Edwin Brady authored
8 > import Control.Monad
738525c Moved Main.lhs
eb authored
9
10 > import Epic.Compiler
c3e9ebc Add -includedirs and -libdirs, and fix usleep warning
eb authored
11 > import Paths_epic
738525c Moved Main.lhs
eb authored
12
2bbafff Add -g option for debug info
eb authored
13 > versionString = showV (versionBranch version)
14 > where
15 > showV [] = ""
16 > showV [a] = show a
17 > showV (x:xs) = show x ++ "." ++ showV xs
18
738525c Moved Main.lhs
eb authored
19 > main = do args <- getArgs
20 > (fns, opts) <- getInput args
21 > outfile <- getOutput opts
22 > ofiles <- compileFiles fns (mkOpts opts)
23 > copts <- getCOpts opts
531fe71 Some improvements and additions to Epic.Epic interface
Edwin Brady authored
24 > -- extras <- getExtra opts
738525c Moved Main.lhs
eb authored
25 > if ((length ofiles) > 0 && (not (elem Obj opts)))
531fe71 Some improvements and additions to Epic.Epic interface
Edwin Brady authored
26 > then link (ofiles ++ copts) outfile (mkOpts opts)
738525c Moved Main.lhs
eb authored
27 > else return ()
28 > where mkOpts (KeepInt:xs) = KeepC:(mkOpts xs)
29 > mkOpts (TraceOn:xs) = Trace:(mkOpts xs)
30 > mkOpts (Header f:xs) = MakeHeader f:(mkOpts xs)
5bb7fa8 debug flag fix
eb authored
31 > mkOpts (DbgInfo:xs) = Debug:(mkOpts xs)
0f1042d Added '-checking x' command line flag
Edwin Brady authored
32 > mkOpts (CheckLvl i:xs) = Checking i:(mkOpts xs)
afc9440 Expose CompileOptions in Epic.Epic
Edwin Brady authored
33 > mkOpts (ExtMain:xs) = ExternalMain:(mkOpts xs)
531fe71 Some improvements and additions to Epic.Epic interface
Edwin Brady authored
34 > mkOpts (ExtraInc i:xs) = MainInc i:(mkOpts xs)
738525c Moved Main.lhs
eb authored
35 > mkOpts (_:xs) = mkOpts xs
36 > mkOpts [] = []
37
38 > compileFiles [] _ = return []
39 > compileFiles (fn:xs) opts
40 > | isDotE fn = do
41 > let ofile = getRoot fn ++ ".o"
42 > compileOpts fn ofile (Just (getRoot fn ++ ".ei")) opts
43 > rest <- compileFiles xs opts
44 > return (ofile:rest)
45 > | isDotO fn = do
46 > rest <- compileFiles xs opts
47 > return (fn:rest)
48 > | otherwise = do -- probably autogenerated, just build it.
49 > let ofile = fn ++ ".o"
50 > compileOpts fn ofile Nothing opts
51 > rest <- compileFiles xs opts
52 > return (ofile:rest)
53
54 > isDotE ('.':'e':[]) = True
55 > isDotE (_:xs) = isDotE xs
56 > isDotE [] = False
57
58 > isDotC ('.':'c':[]) = True
59 > isDotC (_:xs) = isDotC xs
60 > isDotC [] = False
61
62 > isDotO ('.':'o':[]) = True
63 > isDotO (_:xs) = isDotO xs
64 > isDotO [] = False
65
66 > mkExecname fn = case span (/='.') fn of
67 > (stem,".e") -> stem
68 > (stem,_) -> fn ++ ".exe"
69
70 > getRoot fn = case span (/='.') fn of
71 > (stem,_) -> stem
72
73 > getInput :: [String] -> IO ([FilePath],[Option])
74 > getInput args = do let opts = parseArgs args
c3e9ebc Add -includedirs and -libdirs, and fix usleep warning
eb authored
75 > processFlags opts False
738525c Moved Main.lhs
eb authored
76 > fns <- getFile opts
77 > if (length fns == 0)
78 > then do showUsage
79 > return (fns,opts)
80 > else return (fns,opts)
81
1aa9591 Export BigInt
Edwin Brady authored
82 > showUsage = do putStrLn $ "Epic version " ++ versionString
738525c Moved Main.lhs
eb authored
83 > putStrLn "Usage:\n\tepic <input file> [options]"
84 > exitWith (ExitFailure 1)
85
86 > data Option = KeepInt -- Don't delete intermediate file
87 > | TraceOn -- Trace while running (debug option)
88 > | Obj -- Just make the .o, don't link
89 > | File String -- File to send the compiler
90 > | Output String -- Output filename
91 > | Header String -- Header output filename
92 > | ExtraInc String -- extra files to inlude
93 > | COpt String -- option to send straight to gcc
94 > | ExtMain -- external main (i.e. in a .o)
c3e9ebc Add -includedirs and -libdirs, and fix usleep warning
eb authored
95 > | CFlags -- output include flags
96 > | LibFlags -- output linker flags
2bbafff Add -g option for debug info
eb authored
97 > | DbgInfo -- generate debug info
0f1042d Added '-checking x' command line flag
Edwin Brady authored
98 > | CheckLvl Int -- Checking level, 0 for none, default none
738525c Moved Main.lhs
eb authored
99 > deriving Eq
100
101 > parseArgs :: [String] -> [Option]
102 > parseArgs [] = []
103 > parseArgs ("-keepc":args) = KeepInt:(parseArgs args)
104 > parseArgs ("-trace":args) = TraceOn:(parseArgs args)
105 > parseArgs ("-c":args) = Obj:(parseArgs args)
106 > parseArgs ("-extmain":args) = ExtMain:(parseArgs args)
107 > parseArgs ("-o":name:args) = (Output name):(parseArgs args)
108 > parseArgs ("-h":name:args) = (Header name):(parseArgs args)
109 > parseArgs ("-i":inc:args) = (ExtraInc inc):(parseArgs args)
c3e9ebc Add -includedirs and -libdirs, and fix usleep warning
eb authored
110 > parseArgs ("-includedirs":args) = CFlags:(parseArgs args)
111 > parseArgs ("-libdirs":args) = LibFlags:(parseArgs args)
2bbafff Add -g option for debug info
eb authored
112 > parseArgs ("-g":args) = DbgInfo:(parseArgs args)
0f1042d Added '-checking x' command line flag
Edwin Brady authored
113 > parseArgs ("-checking":lvl:args) = CheckLvl (read lvl):(parseArgs args)
738525c Moved Main.lhs
eb authored
114 > parseArgs (('$':x):args) = (COpt (x ++ concat (map (" "++) args))):[]
115 > parseArgs (('-':x):args) = (COpt x):(parseArgs args)
116 > parseArgs (x:args) = (File x):(parseArgs args)
117
118 > getFile :: [Option] -> IO [FilePath]
119 > getFile ((File x):xs) = do fns <- getFile xs
120 > return (x:fns)
121 > getFile (_:xs) = getFile xs
122 > getFile [] = return []
123
124 > getOutput :: [Option] -> IO FilePath
125 > getOutput ((Output fn):xs) = return fn
126 > getOutput (_:xs) = getOutput xs
127 > getOutput [] = return "a.out"
128
129 > getCOpts :: [Option] -> IO [String]
130 > getCOpts ((COpt x):xs) = do fns <- getCOpts xs
131 > return (x:fns)
132 > getCOpts (_:xs) = getCOpts xs
133 > getCOpts [] = return []
134
c3e9ebc Add -includedirs and -libdirs, and fix usleep warning
eb authored
135 > processFlags :: [Option] -> Bool -> IO ()
136 > processFlags [] True = do putStrLn ""; exitWith ExitSuccess
137 > processFlags [] False = return ()
138 > processFlags (LibFlags:xs) _ = do datadir <- getDataDir
139 > putStr $ "-L"++datadir++"/evm "
140 > processFlags xs True
141 > processFlags (CFlags:xs) _ = do datadir <- getDataDir
142 > putStr $ "-I"++datadir++"/evm "
143 > processFlags xs True
144 > processFlags (_:xs) quit = processFlags xs quit
Something went wrong with that request. Please try again.