Skip to content

Commit

Permalink
llvm: Haddocks for callstacks
Browse files Browse the repository at this point in the history
  • Loading branch information
langston-barrett committed Jan 10, 2024
1 parent 77ac1a9 commit 50e83e9
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,28 @@ newtype FunctionName =
FunctionName { getFunctionName :: Text }
deriving (Eq, Monoid, Ord, Semigroup)

-- | Call stacks (lists of function names), mostly for diagnostics
newtype CallStack =
CallStack { runCallStack :: Seq FunctionName }
deriving (Eq, Monoid, Ord, Semigroup)

-- | Add a function name to the top of the call stack
cons :: FunctionName -> CallStack -> CallStack
cons top (CallStack rest) = CallStack (top Seq.<| rest)

-- | Is this 'CallStack' empty?
null :: CallStack -> Bool
null = Seq.null . runCallStack

-- | Summarize the 'StackFrame's of a 'MemState' into a 'CallStack'
getCallStack :: MemState sym -> CallStack
getCallStack =
\case
EmptyMem{} -> CallStack mempty
StackFrame _ _ nm _ rest -> cons (FunctionName nm) (getCallStack rest)
BranchFrame _ _ _ rest -> getCallStack rest

-- | Pretty-print a call stack (one function per line)
ppCallStack :: CallStack -> PP.Doc ann
ppCallStack =
PP.vsep . toList . fmap (PP.pretty . getFunctionName) . runCallStack

0 comments on commit 50e83e9

Please sign in to comment.