diff --git a/src/Main.hs b/src/Main.hs index d00b7af..0355cec 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -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 -> diff --git a/src/SixtyPical/Analyzer.hs b/src/SixtyPical/Analyzer.hs index 0dcd7e5..486110d 100644 --- a/src/SixtyPical/Analyzer.hs +++ b/src/SixtyPical/Analyzer.hs @@ -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 diff --git a/src/SixtyPical/Context.hs b/src/SixtyPical/Context.hs index 7c1cc57..5b5f5ed 100644 --- a/src/SixtyPical/Context.hs +++ b/src/SixtyPical/Context.hs @@ -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