-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorklist.hs
43 lines (27 loc) · 828 Bytes
/
Worklist.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
31
32
33
34
35
36
37
38
39
40
41
42
43
module Worklist where
import Program
import LLVM.AST.Instruction
import LLVM.AST.Type
import LLVM.AST.Global
import LLVM.AST.Operand
import LLVM.AST.Constant
type Worklist = [Node]
isEmpty :: Worklist -> Bool
isEmpty wklist = length wklist == 0
add :: Worklist -> Node -> Worklist
add wklist node = wklist ++ [node]
addSet :: Worklist -> [Node] -> Worklist
addSet wklist nodes = foldl (\acc node -> add acc node) wklist nodes
popInner :: Worklist -> Maybe (Node, Worklist)
popInner wklist =
if length wklist == 0
then Nothing
else let popped = head wklist
wklist' = tail wklist in
Just (popped, wklist')
pop :: Worklist -> (Node, Worklist)
pop wklist = case popInner wklist of
Just tuple -> tuple
Nothing -> error "Worklist is empty"
newWorklist :: Worklist
newWorklist = []