1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-26 16:29:28 +00:00

Pretty-print usages

This commit is contained in:
Cat's Eye Technologies 2014-04-04 13:49:45 +01:00
parent 11265e3060
commit a86738c387
3 changed files with 29 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import SixtyPical.Model
import SixtyPical.Parser (parseProgram)
import SixtyPical.Checker (checkAndTransformProgram)
import SixtyPical.Analyzer (analyzeProgram)
import SixtyPical.Context (ppAnalysis)
import SixtyPical.Emitter (emitProgram)
-- -- -- -- driver -- -- -- --
@ -33,7 +34,7 @@ main = do
("analyze", Right program) ->
case checkAndTransformProgram program of
Just newprog ->
putStrLn $ show $ analyzeProgram newprog
ppAnalysis $ analyzeProgram newprog
("emit", Right program) ->
case checkAndTransformProgram program of
Just newprog ->

View File

@ -35,6 +35,7 @@ checkInstr (COPY src dst) progCtx routCtx =
-- TODO check that src is not poisoned
Map.insert dst (UpdatedWith src) routCtx
checkInstr (DELTA dst val) progCtx routCtx =
-- TODO check that dst is not poisoned
Map.insert dst (UpdatedWith (Immediate val)) routCtx
checkInstr (JSR name) progCtx routCtx =
case Map.lookup name progCtx of

View File

@ -42,3 +42,29 @@ mergeRoutCtxs routCtx calledRoutCtx =
Map.insert location (PoisonedWith ulocation) routCtxAccum
in
Map.foldrWithKey (poison) routCtx calledRoutCtx
ppAnalysis :: ProgramContext -> IO ()
ppAnalysis progCtx =
let
li = Map.toList progCtx
in do
ppRoutines li
ppRoutines [] = return ()
ppRoutines ((name, routCtx):rest) = do
putStrLn $ name
ppRoutine routCtx
putStrLn ""
ppRoutines rest
ppRoutine routCtx =
let
li = Map.toList routCtx
in do
ppUsages li
ppUsages [] = return ()
ppUsages ((loc, usage):rest) = do
putStrLn $ (" " ++ (show loc) ++ ": " ++ (show usage))
ppUsages rest