- Timestamp:
- 09/14/08 21:54:19 (3 months ago)
- Files:
-
- 1 modified
-
v6/smop/m0ld/M0ld.hs (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
v6/smop/m0ld/M0ld.hs
r22204 r22244 1 1 import Text.ParserCombinators.Parsec hiding (label) 2 2 import qualified Data.Map as Map 3 import System.IO hiding (getContents,putStrLn,print )4 import Prelude hiding (getContents,putStrLn,print )3 import System.IO hiding (getContents,putStrLn,print,putStr) 4 import Prelude hiding (getContents,putStrLn,print,putStr) 5 5 import System.IO.UTF8 6 6 import Debug.Trace 7 import System.Console.GetOpt 8 import System.Environment 7 9 8 10 type Register = [Char] … … 240 242 emit stmts regMap labelsMap = concatMap (\op -> toBytecode op regMap labelsMap) stmts ++ [0] 241 243 244 joinStr sep [] = "" 242 245 joinStr sep list = foldl (\a b -> a ++ sep ++ b) (head list) (tail list) 243 246 … … 269 272 ++ "})" 270 273 274 prettyPrintBytecode stmts = 275 let labelsMap = mapLabels stmts 276 regMap = mapRegisters stmts 277 freeRegs = countRegister stmts 278 prettyPrintOp (Decl _ _) = "" 279 prettyPrintOp op = (joinStr " " $ ( map show (toBytecode op regMap labelsMap))) ++ "\n" 280 in concat $ map prettyPrintOp stmts 281 271 282 type ImplicitDecls = Map.Map Value [Char] 272 283 … … 274 285 275 286 main = do 287 args <- getArgs 288 let (options,nonoptions,errors) = getOpt RequireOrder [Option [] ["print-bytecode"] (NoArg "print-bytecode") "print resulting mold bytecode in a human readable form"] args 289 mapM putStr errors 276 290 hFlush stdout 277 291 line <- getContents … … 279 293 Left err -> error $ show err 280 294 Right (stmts,constants) -> do 281 putStrLn $ dumpToC $ (implicitDecls constants) ++ stmts 295 if elem "print-bytecode" options then putStrLn $ prettyPrintBytecode $ (implicitDecls constants) ++ stmts 296 else putStrLn $ dumpToC $ (implicitDecls constants) ++ stmts
