-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathDeadCodeElimination.hs
More file actions
29 lines (24 loc) · 714 Bytes
/
Copy pathDeadCodeElimination.hs
File metadata and controls
29 lines (24 loc) · 714 Bytes
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
module Eclair.AST.Transforms.DeadCodeElimination
( transform
) where
import Eclair.Transform
import Eclair.AST.Analysis
import Eclair.AST.IR
transform :: Container DeadCode -> Transform AST AST
transform analysis =
pureTransform $ cata $ \case
ModuleF nodeId decls ->
Module nodeId $ filter (not . isDead) decls
RuleF nodeId name args clauses ->
Rule nodeId name args $
filter (\c -> not (isDead c || isRedundantAssign c)) clauses
astf ->
embed astf
where
deadCodeNodeIds =
map unDeadCode analysis
isDead ast =
getNodeId ast `elem` deadCodeNodeIds
isRedundantAssign = \case
Constraint _ Equals lhs rhs -> lhs == rhs
_ -> False