@@ -227,6 +227,43 @@ data LLVMStmt (f :: CrucibleType -> Type) :: CrucibleType -> Type where
227
227
! (f (LLVMPointerType wptr )) {- Second pointer -} ->
228
228
LLVMStmt f (BVType wptr )
229
229
230
+ -- | Debug information
231
+ LLVM_Debug ::
232
+ ! (LLVM_Dbg f c ) {- Debug variant -} ->
233
+ LLVMStmt f UnitType
234
+
235
+ -- | Debug statement variants - these have no semantic meaning
236
+ data LLVM_Dbg f c where
237
+ -- | Annotates a value pointed to by a pointer with local-variable debug information
238
+ --
239
+ -- <https://llvm.org/docs/SourceLevelDebugging.html#llvm-dbg-addr>
240
+ LLVM_Dbg_Addr ::
241
+ HasPtrWidth wptr =>
242
+ ! (f (LLVMPointerType wptr )) {- Pointer to local variable -} ->
243
+ L. DILocalVariable {- Local variable information -} ->
244
+ L. DIExpression {- Complex expression -} ->
245
+ LLVM_Dbg f (LLVMPointerType wptr )
246
+
247
+ -- | Annotates a value pointed to by a pointer with local-variable debug information
248
+ --
249
+ -- <https://llvm.org/docs/SourceLevelDebugging.html#llvm-dbg-declare>
250
+ LLVM_Dbg_Declare ::
251
+ HasPtrWidth wptr =>
252
+ ! (f (LLVMPointerType wptr )) {- Pointer to local variable -} ->
253
+ L. DILocalVariable {- Local variable information -} ->
254
+ L. DIExpression {- Complex expression -} ->
255
+ LLVM_Dbg f (LLVMPointerType wptr )
256
+
257
+ -- | Annotates a value with local-variable debug information
258
+ --
259
+ -- <https://llvm.org/docs/SourceLevelDebugging.html#llvm-dbg-value>
260
+ LLVM_Dbg_Value ::
261
+ ! (TypeRepr c ) {- Type of local variable -} ->
262
+ ! (f c ) {- Value of local variable -} ->
263
+ L. DILocalVariable {- Local variable information -} ->
264
+ L. DIExpression {- Complex expression -} ->
265
+ LLVM_Dbg f c
266
+
230
267
$ (return [] )
231
268
232
269
instance TypeApp LLVMExtensionExpr where
@@ -315,6 +352,7 @@ instance TypeApp LLVMStmt where
315
352
LLVM_PtrLe {} -> knownRepr
316
353
LLVM_PtrAddOffset w _ _ _ -> LLVMPointerRepr w
317
354
LLVM_PtrSubtract w _ _ _ -> BVRepr w
355
+ LLVM_Debug {} -> knownRepr
318
356
319
357
instance PrettyApp LLVMStmt where
320
358
ppApp pp = \ case
@@ -342,6 +380,13 @@ instance PrettyApp LLVMStmt where
342
380
pretty " ptrAddOffset" <+> ppGlobalVar mvar <+> pp x <+> pp y
343
381
LLVM_PtrSubtract _ mvar x y ->
344
382
pretty " ptrSubtract" <+> ppGlobalVar mvar <+> pp x <+> pp y
383
+ LLVM_Debug dbg -> ppApp pp dbg
384
+
385
+ instance PrettyApp LLVM_Dbg where
386
+ ppApp pp = \ case
387
+ LLVM_Dbg_Addr x _ _ -> pretty " dbg.addr" <+> pp x
388
+ LLVM_Dbg_Declare x _ _ -> pretty " dbg.declare" <+> pp x
389
+ LLVM_Dbg_Value _ x _ _ -> pretty " dbg.value" <+> pp x
345
390
346
391
-- TODO: move to a Pretty instance
347
392
ppGlobalVar :: GlobalVar Mem -> Doc ann
@@ -351,6 +396,26 @@ ppGlobalVar = viaShow
351
396
ppAlignment :: Alignment -> Doc ann
352
397
ppAlignment = viaShow
353
398
399
+ instance TestEqualityFC LLVM_Dbg where
400
+ testEqualityFC testSubterm = $ (U. structuralTypeEquality [t |LLVM_Dbg|]
401
+ [(U. DataArg 0 `U. TypeApp ` U. AnyType , [| testSubterm| ])
402
+ ,(U. ConType [t |TypeRepr|] `U. TypeApp ` U. AnyType , [| testEquality| ])
403
+ ])
404
+
405
+ instance OrdFC LLVM_Dbg where
406
+ compareFC compareSubterm = $ (U. structuralTypeOrd [t |LLVM_Dbg|]
407
+ [(U. DataArg 0 `U. TypeApp ` U. AnyType , [| compareSubterm| ])
408
+ ,(U. ConType [t |TypeRepr|] `U. TypeApp ` U. AnyType , [| compareF| ])
409
+ ])
410
+
411
+ instance FoldableFC LLVM_Dbg where
412
+ foldMapFC = foldMapFCDefault
413
+ instance FunctorFC LLVM_Dbg where
414
+ fmapFC = fmapFCDefault
415
+
416
+ instance TraversableFC LLVM_Dbg where
417
+ traverseFC = $ (U. structuralTraversal [t |LLVM_Dbg|] [] )
418
+
354
419
instance TestEqualityFC LLVMStmt where
355
420
testEqualityFC testSubterm =
356
421
$ (U. structuralTypeEquality [t |LLVMStmt|]
@@ -359,6 +424,7 @@ instance TestEqualityFC LLVMStmt where
359
424
,(U. ConType [t |GlobalVar|] `U. TypeApp ` U. AnyType , [| testEquality| ])
360
425
,(U. ConType [t |CtxRepr|] `U. TypeApp ` U. AnyType , [| testEquality| ])
361
426
,(U. ConType [t |TypeRepr|] `U. TypeApp ` U. AnyType , [| testEquality| ])
427
+ ,(U. ConType [t |LLVM_Dbg|] `U. TypeApp ` U. DataArg 0 `U. TypeApp ` U. AnyType , [| testEqualityFC testSubterm| ])
362
428
])
363
429
364
430
instance OrdFC LLVMStmt where
@@ -369,6 +435,7 @@ instance OrdFC LLVMStmt where
369
435
,(U. ConType [t |GlobalVar|] `U. TypeApp ` U. AnyType , [| compareF| ])
370
436
,(U. ConType [t |CtxRepr|] `U. TypeApp ` U. AnyType , [| compareF| ])
371
437
,(U. ConType [t |TypeRepr|] `U. TypeApp ` U. AnyType , [| compareF| ])
438
+ ,(U. ConType [t |LLVM_Dbg|] `U. TypeApp ` U. DataArg 0 `U. TypeApp ` U. AnyType , [| compareFC compareSubterm| ])
372
439
])
373
440
374
441
instance FunctorFC LLVMStmt where
@@ -379,4 +446,6 @@ instance FoldableFC LLVMStmt where
379
446
380
447
instance TraversableFC LLVMStmt where
381
448
traverseFC =
382
- $ (U. structuralTraversal [t |LLVMStmt|] [] )
449
+ $ (U. structuralTraversal [t |LLVMStmt|]
450
+ [(U. ConType [t |LLVM_Dbg|] `U. TypeApp ` U. DataArg 0 `U. TypeApp ` U. AnyType , [| traverseFC| ])
451
+ ])
0 commit comments