@@ -175,6 +175,7 @@ let calculateStateMetrics interproceduralGraphDistanceFrom (state: IGraphTrackab
175
175
let mutable notVisitedBasicBlocksInZone = 0
176
176
let mutable notTouchedBasicBlocksInZone = 0
177
177
let basicBlocks = HashSet<_>()
178
+
178
179
currentBasicBlock.OutgoingEdges.Values |> Seq.iter basicBlocks.UnionWith
179
180
180
181
basicBlocks
@@ -348,41 +349,47 @@ let collectStatesInfoToDump (basicBlocks: ResizeArray<BasicBlock>) =
348
349
349
350
statesInfoToDump
350
351
351
- let getFirstFreePathConditionVertexId =
352
+ let getFirstFreePathConditionVertexId , resetPathConditionVertexIdCounter =
352
353
let mutable count = 0 u< pathConditionVertexId>
353
354
354
355
fun () ->
355
356
let res = count
356
357
count <- count + 1 u< pathConditionVertexId>
357
358
res
359
+ , fun () -> count <- 0 u< pathConditionVertexId>
358
360
359
- let pathConditionVertices = Dictionary< Core.term, PathConditionVertex>()
360
-
361
- let collectPathCondition term = // TODO: Support other operations
362
- let termsToVisit =
363
- Stack< Core.term * uint< pathConditionVertexId>> [| ( term, getFirstFreePathConditionVertexId ()) |]
361
+ let pathConditionVertices = HashSet< Core.term>()
362
+ let termsWithId = Dictionary< Core.term, uint< pathConditionVertexId>>()
364
363
364
+ let collectPathCondition
365
+ term
366
+ ( termsWithId : Dictionary < Core.term , uint < pathConditionVertexId >>)
367
+ ( processedPathConditionVertices : HashSet < Core.term >)
368
+ = // TODO: Support other operations
369
+ let termsToVisit = Stack< Core.term> [| term |]
365
370
let pathConditionDelta = ResizeArray< PathConditionVertex>()
366
371
372
+ let getIdForTerm term =
373
+ if termsWithId.ContainsKey term then
374
+ termsWithId.[ term]
375
+ else
376
+ let newId = getFirstFreePathConditionVertexId ()
377
+ termsWithId.Add( term, newId)
378
+ newId
379
+
380
+ let handleChild term ( children : ResizeArray < _ >) =
381
+ children.Add( getIdForTerm term)
382
+ termsToVisit.Push term
383
+
367
384
while termsToVisit.Count > 0 do
368
- let currentTerm , currentTermId = termsToVisit.Pop()
385
+ let currentTerm = termsToVisit.Pop()
369
386
370
387
let markAsVisited ( vertexType : pathConditionVertexType ) children =
371
- let newVertex = PathConditionVertex( currentTermId , vertexType, children)
372
- pathConditionVertices .Add( currentTerm, newVertex )
388
+ let newVertex = PathConditionVertex( getIdForTerm currentTerm , vertexType, children)
389
+ processedPathConditionVertices .Add currentTerm |> ignore
373
390
pathConditionDelta.Add newVertex
374
391
375
- let handleTerm term ( children : ResizeArray < _ >) =
376
- let termId =
377
- if not <| pathConditionVertices.ContainsKey term then
378
- getFirstFreePathConditionVertexId ()
379
- else
380
- pathConditionVertices.[ term]. Id
381
-
382
- children.Add termId
383
- termsToVisit.Push(( term, termId))
384
-
385
- if not <| pathConditionVertices.ContainsKey currentTerm then
392
+ if not <| processedPathConditionVertices.Contains currentTerm then
386
393
match currentTerm.term with
387
394
| Nop -> markAsVisited pathConditionVertexType.Nop [||]
388
395
| Concrete(_, _) -> markAsVisited pathConditionVertexType.Constant [||]
@@ -391,7 +398,7 @@ let collectPathCondition term = // TODO: Support other operations
391
398
let children = ResizeArray< uint< pathConditionVertexId>>()
392
399
393
400
for t in termList do
394
- handleTerm t children
401
+ handleChild t children
395
402
396
403
let children = children.ToArray()
397
404
@@ -443,30 +450,30 @@ let collectPathCondition term = // TODO: Support other operations
443
450
let children = ResizeArray< uint< pathConditionVertexId>>()
444
451
445
452
for _, t in PersistentDict.toSeq fields do
446
- handleTerm t children
453
+ handleChild t children
447
454
448
455
markAsVisited pathConditionVertexType.Struct ( children.ToArray())
449
456
| HeapRef(_, _) -> markAsVisited pathConditionVertexType.HeapRef [||]
450
457
| Ref(_) -> markAsVisited pathConditionVertexType.Ref [||]
451
458
| Ptr(_, _, t) ->
452
459
let children = ResizeArray< uint< pathConditionVertexId>> [||]
453
- handleTerm t children
460
+ handleChild t children
454
461
markAsVisited pathConditionVertexType.Ptr ( children.ToArray())
455
462
| Slice( t, listOfTuples) ->
456
463
let children = ResizeArray< uint< pathConditionVertexId>> [||]
457
- handleTerm t children
464
+ handleChild t children
458
465
459
466
for t1, t2, t3, _ in listOfTuples do
460
- handleTerm t1 children
461
- handleTerm t2 children
462
- handleTerm t3 children
467
+ handleChild t1 children
468
+ handleChild t2 children
469
+ handleChild t3 children
463
470
464
471
markAsVisited pathConditionVertexType.Slice ( children.ToArray())
465
472
| Ite(_) -> markAsVisited pathConditionVertexType.Ite [||]
466
473
467
474
pathConditionDelta
468
475
469
- let collectGameState ( basicBlocks : ResizeArray < BasicBlock >) filterStates =
476
+ let collectGameState ( basicBlocks : ResizeArray < BasicBlock >) filterStates processedPathConditionVertices termsWithId =
470
477
471
478
let vertices = ResizeArray<_>()
472
479
let allStates = HashSet<_>()
@@ -486,13 +493,13 @@ let collectGameState (basicBlocks: ResizeArray<BasicBlock>) filterStates =
486
493
let pathCondition = s.PathCondition |> PC.toSeq
487
494
488
495
for term in pathCondition do
489
- pathConditionDelta.AddRange( collectPathCondition term)
496
+ pathConditionDelta.AddRange( collectPathCondition term termsWithId processedPathConditionVertices )
490
497
491
498
let pathConditionRoot =
492
499
PathConditionVertex(
493
500
id = getFirstFreePathConditionVertexId (),
494
501
pathConditionVertexType = pathConditionVertexType.PathConditionRoot,
495
- children = [| for p in pathCondition -> pathConditionVertices .[ p]. Id |]
502
+ children = [| for p in pathCondition -> termsWithId .[ p] |]
496
503
)
497
504
498
505
pathConditionDelta.Add pathConditionRoot
@@ -556,7 +563,7 @@ let collectGameStateDelta () =
556
563
let added = basicBlocks.Add( basicBlock)
557
564
()
558
565
559
- collectGameState ( ResizeArray basicBlocks) false
566
+ collectGameState ( ResizeArray basicBlocks) false pathConditionVertices termsWithId
560
567
561
568
let dumpGameState fileForResultWithoutExtension ( movedStateId : uint < stateId >) =
562
569
let basicBlocks = ResizeArray<_>()
@@ -566,7 +573,9 @@ let dumpGameState fileForResultWithoutExtension (movedStateId: uint<stateId>) =
566
573
basicBlock.IsGoal <- method.Key.InCoverageZone
567
574
basicBlocks.Add( basicBlock)
568
575
569
- let gameState = collectGameState basicBlocks true
576
+ let gameState =
577
+ collectGameState basicBlocks true ( HashSet< Core.term>()) ( Dictionary< Core.term, uint< pathConditionVertexId>>())
578
+
570
579
let statesInfoToDump = collectStatesInfoToDump basicBlocks
571
580
let gameStateJson = JsonSerializer.Serialize gameState
572
581
let statesInfoJson = JsonSerializer.Serialize statesInfoToDump
0 commit comments