-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1163 from langston-barrett/lb/llvm-callstack
llvm: Export `CallStack` internals from an internal module
- Loading branch information
Showing
3 changed files
with
59 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
crucible-llvm/src/Lang/Crucible/LLVM/MemModel/CallStack/Internal.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
------------------------------------------------------------------------ | ||
-- | | ||
-- Module : Lang.Crucible.LLVM.MemModel.CallStack.Internal | ||
-- Description : Call stacks from the LLVM memory model (implementation details) | ||
-- Copyright : (c) Galois, Inc 2024 | ||
-- License : BSD3 | ||
-- Maintainer : Langston Barrett <[email protected]> | ||
-- Stability : provisional | ||
------------------------------------------------------------------------ | ||
|
||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Lang.Crucible.LLVM.MemModel.CallStack.Internal where | ||
|
||
import Data.Foldable (toList) | ||
import Data.Sequence (Seq) | ||
import qualified Data.Sequence as Seq | ||
import Data.Text (Text) | ||
import qualified Prettyprinter as PP | ||
|
||
import Lang.Crucible.LLVM.MemModel.MemLog (MemState(..)) | ||
|
||
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 |