Changeset 22245 for v6

Show
Ignore:
Timestamp:
09/14/08 22:33:49 (3 months ago)
Author:
pmurias
Message:

[m0ld] --print-bytecode prints out constants too

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • v6/smop/m0ld/M0ld.hs

    r22244 r22245  
    272272        ++ "})" 
    273273 
    274 prettyPrintBytecode stmts = 
     274prettyPrintConstant :: [Char] -> Value -> [Char] 
     275prettyPrintConstant indent value = indent ++ case value of 
     276    StringConstant str -> (show str) ++ "\n" 
     277    IntegerConstant int -> (show int) ++ "\n" 
     278    None -> "" 
     279    Var name -> "¢" ++ name ++ "\n" 
     280    SubMold stmts -> "{\n" ++ (prettyPrintBytecode ("  " ++ indent) stmts) ++ indent ++ "}\n" 
     281prettyPrintBytecode indent stmts = 
    275282    let labelsMap = mapLabels stmts 
    276283        regMap    = mapRegisters stmts 
    277284        freeRegs  = countRegister stmts 
    278285        prettyPrintOp (Decl _ _) = "" 
    279         prettyPrintOp op = (joinStr " " $ ( map show (toBytecode op regMap labelsMap))) ++ "\n" 
    280         in concat $ map prettyPrintOp stmts 
     286        prettyPrintOp op = indent ++ (joinStr " " $ ( map show (toBytecode op regMap labelsMap))) ++ "\n" 
     287        decls = [prettyPrintConstant indent c | Decl reg c <- filter (not . isReg) stmts] 
     288        in (concat $ map (\(i,e) -> indent ++ "$" ++ (show i) ++ " = " ++ e) (zip [0..(length decls - 1)] decls)) ++ 
     289            (concat $ map prettyPrintOp stmts) 
    281290 
    282291type ImplicitDecls = Map.Map Value [Char] 
     
    293302        Left err      -> error  $ show err 
    294303        Right (stmts,constants) -> do  
    295             if elem "print-bytecode" options then putStrLn $ prettyPrintBytecode $ (implicitDecls constants) ++ stmts 
     304            if elem "print-bytecode" options then putStrLn $ prettyPrintBytecode "" $ (implicitDecls constants) ++ stmts 
    296305                else putStrLn $ dumpToC $ (implicitDecls constants) ++ stmts