forked from jkff/minxmod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTraceback.hs
30 lines (23 loc) · 1.05 KB
/
Traceback.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Traceback where
import Data.List (unfoldr)
import qualified Data.Map as M
import Data.Functor ((<$>))
import Types
import StateGraph
data Event = InsnExecuted { e_pid :: Pid, e_ip :: Int, e_insn :: Insn } deriving (Show)
data SimpleTraceEvent = LocalSpan { ste_pid :: Pid, ste_insns :: [(Int, Insn)] }
| ContextSwitch { ste_newPid :: Pid }
deriving (Show)
sg_node2prev' :: StateGraph -> M.Map Int (Int, Event)
sg_node2prev' = undefined
traceback :: StateGraph -> Int -> [Event]
traceback g i = unfoldr source i
where source i = genEvent <$> M.lookup i (sg_node2prev' g)
genEvent (p, e) = (e, p)
simplifyTraceback :: [Event] -> [SimpleTraceEvent]
simplifyTraceback (e@(InsnExecuted pid ip insn):es) = simplify' pid [] (e:es)
where
simplify' pid span [] = [LocalSpan pid (reverse span)]
simplify' pid span (e@(InsnExecuted pid' ip insn):es)
| pid == pid' = simplify' pid ((ip, insn):span) es
| otherwise = LocalSpan pid (reverse span) : ContextSwitch pid' : simplify' pid' [] (e:es)