Skip to content

Commit 8edd9cf

Browse files
authored
Merge pull request #1693 from GaloisInc/T1662
Update submodule versions and fix #1662
2 parents 4666760 + 43af17f commit 8edd9cf

File tree

11 files changed

+23
-75
lines changed

11 files changed

+23
-75
lines changed

cabal.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ packages:
4242
source-repository-package
4343
type: git
4444
location: https://github.com/eddywestbrook/hobbits.git
45-
tag: e2df7a85ea8dfebce2be8065afdca96cbaef12ae
45+
tag: e49911ce987c4e0fea8c63608d16638b243b051f

deps/cryptol

Submodule cryptol updated 59 files

deps/macaw

Submodule macaw updated 127 files

src/SAWScript/Crucible/LLVM/Skeleton.hs

+13-65
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Control.Arrow
2727
import Control.Monad
2828
import Control.Lens
2929

30+
import qualified Data.IntMap.Strict as IntMap
3031
import Data.Maybe
3132
import Data.Text (Text)
3233
import qualified Data.Text as Text
@@ -36,6 +37,7 @@ import Data.Set (Set)
3637
import qualified Data.Set as Set
3738

3839
import qualified Text.LLVM as LLVM
40+
import qualified Text.LLVM.DebugUtils as LLVM
3941

4042
--------------------------------------------------------------------------------
4143
-- ** Skeletons
@@ -101,43 +103,27 @@ parseType (LLVM.Array i t) = pure $ TypeSkeleton t True
101103
]
102104
parseType t = pure $ TypeSkeleton t False []
103105

104-
debugInfoGlobalLines :: LLVM.Module -> Map Text Int
105-
debugInfoGlobalLines = go . LLVM.modUnnamedMd
106-
where
107-
go :: [LLVM.UnnamedMd] -> Map Text Int
108-
go (LLVM.UnnamedMd
109-
{ LLVM.umValues = LLVM.ValMdDebugInfo
110-
(LLVM.DebugInfoGlobalVariable LLVM.DIGlobalVariable
111-
{ LLVM.digvName = Just n
112-
, LLVM.digvLine = l
113-
}
114-
)
115-
}:xs) = Map.insert (Text.pack n) (fromIntegral l) $ go xs
116-
go (_:xs) = go xs
117-
go [] = Map.empty
118-
119-
parseGlobal :: Map Text Int -> LLVM.Global -> IO GlobalSkeleton
106+
parseGlobal :: Map String Int -> LLVM.Global -> IO GlobalSkeleton
120107
parseGlobal ls LLVM.Global
121108
{ LLVM.globalSym = LLVM.Symbol s
122109
, LLVM.globalType = t
123110
, LLVM.globalValue = v
124111
, LLVM.globalAttrs = LLVM.GlobalAttrs { LLVM.gaConstant = c }
125112
} = do
126-
let nm = Text.pack s
127113
ty <- parseType t
128114
pure GlobalSkeleton
129115
{ _globSkelName = Text.pack s
130-
, _globSkelLoc = flip Location Nothing <$> Map.lookup nm ls
116+
, _globSkelLoc = flip Location Nothing <$> Map.lookup s ls
131117
, _globSkelType = ty
132118
, _globSkelMutable = not c
133119
, _globSkelInitialized = isJust v
134120
}
135121

136-
parseArg :: LLVM.Typed LLVM.Ident -> (Maybe Text, Maybe Location) -> IO ArgSkeleton
122+
parseArg :: LLVM.Typed LLVM.Ident -> (Maybe String, Maybe Location) -> IO ArgSkeleton
137123
parseArg LLVM.Typed { LLVM.typedType = t } (nm, loc) = do
138124
ty <- parseType t
139125
pure ArgSkeleton
140-
{ _argSkelName = nm
126+
{ _argSkelName = Text.pack <$> nm
141127
, _argSkelLoc = loc
142128
, _argSkelType = ty
143129
}
@@ -167,7 +153,7 @@ stmtDebugDeclares
167153
, Just (LLVM.ValMdLoc LLVM.DebugLoc { LLVM.dlLine = line, LLVM.dlCol = col }) <- lookup "dbg" md
168154
= Map.insert (fromIntegral a) (Location (fromIntegral line) . Just $ fromIntegral col) $ stmtDebugDeclares stmts
169155
stmtDebugDeclares
170-
(LLVM.Effect
156+
(LLVM.Effect
171157
(LLVM.Call _ _
172158
(LLVM.ValSymbol (LLVM.Symbol s))
173159
[ _
@@ -185,45 +171,7 @@ stmtDebugDeclares (_:stmts) = stmtDebugDeclares stmts
185171
defineName :: LLVM.Define -> Text
186172
defineName LLVM.Define { LLVM.defName = LLVM.Symbol s } = Text.pack s
187173

188-
debugInfoArgNames :: LLVM.Module -> LLVM.Define -> Map Int Text
189-
debugInfoArgNames m d =
190-
case Map.lookup "dbg" $ LLVM.defMetadata d of
191-
Just (LLVM.ValMdRef s) -> scopeArgs s
192-
_ -> Map.empty
193-
where
194-
scopeArgs :: Int -> Map Int Text
195-
scopeArgs s = go $ LLVM.modUnnamedMd m
196-
where go :: [LLVM.UnnamedMd] -> Map Int Text
197-
go [] = Map.empty
198-
go (LLVM.UnnamedMd
199-
{ LLVM.umValues =
200-
LLVM.ValMdDebugInfo
201-
(LLVM.DebugInfoLocalVariable
202-
LLVM.DILocalVariable
203-
{ LLVM.dilvScope = Just (LLVM.ValMdRef s')
204-
, LLVM.dilvArg = a
205-
, LLVM.dilvName = Just n
206-
})}:xs) =
207-
if s == s' then Map.insert (fromIntegral a) (Text.pack n) $ go xs else go xs
208-
go (_:xs) = go xs
209-
210-
debugInfoDefineLines :: LLVM.Module -> Map Text Int
211-
debugInfoDefineLines = go . LLVM.modUnnamedMd
212-
where
213-
go :: [LLVM.UnnamedMd] -> Map Text Int
214-
go (LLVM.UnnamedMd
215-
{ LLVM.umValues = LLVM.ValMdDebugInfo
216-
(LLVM.DebugInfoSubprogram LLVM.DISubprogram
217-
{ LLVM.dispName = Just n
218-
, LLVM.dispIsDefinition = True
219-
, LLVM.dispLine = l
220-
}
221-
)
222-
}:xs) = Map.insert (Text.pack n) (fromIntegral l) $ go xs
223-
go (_:xs) = go xs
224-
go [] = Map.empty
225-
226-
parseDefine :: Map Text Int -> LLVM.Module -> LLVM.Define -> IO FunctionSkeleton
174+
parseDefine :: Map String Int -> LLVM.Module -> LLVM.Define -> IO FunctionSkeleton
227175
parseDefine _ _ LLVM.Define { LLVM.defVarArgs = True } =
228176
fail "Skeleton generation does not support varargs"
229177
parseDefine ls m d@LLVM.Define
@@ -233,13 +181,13 @@ parseDefine ls m [email protected]
233181
, LLVM.defRetType = ret
234182
} = do
235183
let stmts = mconcat $ LLVM.bbStmts <$> body
236-
let argNames = debugInfoArgNames m d
184+
let argNames = LLVM.debugInfoArgNames m d
237185
let debugDeclares = stmtDebugDeclares stmts
238-
argSkels <- zipWithM parseArg args $ (flip Map.lookup argNames &&& flip Map.lookup debugDeclares) <$> [1, 2..]
186+
argSkels <- zipWithM parseArg args $ (flip IntMap.lookup argNames &&& flip Map.lookup debugDeclares) <$> [1, 2..]
239187
retTy <- parseType ret
240188
pure FunctionSkeleton
241189
{ _funSkelName = Text.pack s
242-
, _funSkelLoc = flip Location Nothing <$> Map.lookup (Text.pack s) ls
190+
, _funSkelLoc = flip Location Nothing <$> Map.lookup s ls
243191
, _funSkelArgs = argSkels
244192
, _funSkelRet = retTy
245193
, _funSkelCalls = Set.intersection
@@ -249,8 +197,8 @@ parseDefine ls m [email protected]
249197

250198
moduleSkeleton :: LLVM.Module -> IO ModuleSkeleton
251199
moduleSkeleton ast = do
252-
globs <- mapM (parseGlobal $ debugInfoGlobalLines ast) $ LLVM.modGlobals ast
253-
funs <- mapM (parseDefine (debugInfoDefineLines ast) ast) $ LLVM.modDefines ast
200+
globs <- mapM (parseGlobal $ LLVM.debugInfoGlobalLines ast) $ LLVM.modGlobals ast
201+
funs <- mapM (parseDefine (LLVM.debugInfoDefineLines ast) ast) $ LLVM.modDefines ast
254202
pure $ ModuleSkeleton
255203
{ _modSkelGlobals = Map.fromList $ (\g -> (g ^. globSkelName, g)) <$> globs
256204
, _modSkelFunctions = Map.fromList $ (\f -> (f ^. funSkelName, f)) <$> funs

0 commit comments

Comments
 (0)