From 3595d3c75503158e4eedaedbac8e81cbbe5ae54b Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 13 Dec 2019 13:39:35 +0100 Subject: Follow caller-save convention using stack, not full state restore --- Intermediate.hs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Intermediate.hs') 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 -- cgit v1.2.3-70-g09d2