summaryrefslogtreecommitdiff
path: root/Intermediate.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Intermediate.hs')
-rw-r--r--Intermediate.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/Intermediate.hs b/Intermediate.hs
index 7984176..a020509 100644
--- a/Intermediate.hs
+++ b/Intermediate.hs
@@ -38,6 +38,8 @@ data InsCode
| ICallC Ref [Ref]
| IAllocClo Name [Ref]
| IDiscard Ref
+ | IPush [Ref] -- pushes references on the stack; should be matched with an IPop with the same number of references
+ | IPop [Ref]
deriving Eq
data Terminator
@@ -77,6 +79,8 @@ instance AllRefs InsCode where
allRefs (ICallC r rs) = sortUniq (r : rs)
allRefs (IAllocClo _ rs) = sortUniq rs
allRefs (IDiscard r) = [r]
+ allRefs (IPush rs) = sortUniq rs
+ allRefs (IPop rs) = sortUniq rs
instance AllRefs Terminator where
allRefs (IBr r _ _) = [r]
@@ -106,6 +110,8 @@ icReadTemps = \case
ICallC r rs -> onlyTemporaries (r : rs)
IAllocClo _ rs -> onlyTemporaries rs
IDiscard r -> onlyTemporaries [r]
+ IPush rs -> onlyTemporaries rs
+ IPop _ -> []
termReadTemps :: Terminator -> [Int]
termReadTemps = \case
@@ -123,6 +129,7 @@ bbWrittenTemps :: BB -> [Int]
bbWrittenTemps (BB _ inss _) = concatMap insWrittenTemps inss
insWrittenTemps :: Instruction -> [Int]
+insWrittenTemps (_, IPop rs) = onlyTemporaries rs
insWrittenTemps (d, _) = onlyTemporaries [d]
onlyTemporaries :: [Ref] -> [Int]
@@ -171,6 +178,8 @@ instance Show InsCode where
show (ICallC r as) = "callc " ++ show r ++ " " ++ show as
show (IAllocClo name vs) = "alloc-closure \"" ++ name ++ "\" " ++ show vs
show (IDiscard r) = "discard " ++ show r
+ show (IPush rs) = "push " ++ show rs
+ show (IPop rs) = "pop " ++ show rs
instance Show Terminator where
show (IBr r b1 b2) = "br " ++ show r ++ " " ++ show b1 ++ " " ++ show b2