File tree Expand file tree Collapse file tree 5 files changed +20
-90
lines changed
cpp/ql/lib/semmle/code/cpp/ir/implementation
csharp/ql/src/experimental/ir/implementation Expand file tree Collapse file tree 5 files changed +20
-90
lines changed Original file line number Diff line number Diff line change @@ -255,28 +255,14 @@ private module Cached {
255255 cached
256256 newtype TIRBlock = MkIRBlock ( Instruction firstInstr ) { startsBasicBlock ( firstInstr ) }
257257
258- /** Gets the index of `i` in its `IRBlock`. */
259- private int getMemberIndex ( Instruction i ) {
260- startsBasicBlock ( i ) and
261- result = 0
262- or
263- exists ( Instruction iPrev |
264- adjacentInBlock ( iPrev , i ) and
265- result = getMemberIndex ( iPrev ) + 1
266- )
267- }
268-
269- private module BlockAdjacency = QlBuiltins:: EquivalenceRelation< Instruction , adjacentInBlock / 2 > ;
258+ /** Holds if `i` is the `index`th instruction the block starting with `first`. */
259+ private Instruction getInstructionFromFirst ( Instruction first , int index ) =
260+ shortestDistances( startsBasicBlock / 1 , adjacentInBlock / 2 ) ( first , result , index )
270261
271262 /** Holds if `i` is the `index`th instruction in `block`. */
272263 cached
273264 Instruction getInstruction ( TIRBlock block , int index ) {
274- exists ( Instruction first | block = MkIRBlock ( first ) |
275- first = result and index = 0
276- or
277- index = getMemberIndex ( result ) and
278- BlockAdjacency:: getEquivalenceClass ( first ) = BlockAdjacency:: getEquivalenceClass ( result )
279- )
265+ result = getInstructionFromFirst ( getFirstInstruction ( block ) , index )
280266 }
281267
282268 cached
Original file line number Diff line number Diff line change @@ -255,28 +255,14 @@ private module Cached {
255255 cached
256256 newtype TIRBlock = MkIRBlock ( Instruction firstInstr ) { startsBasicBlock ( firstInstr ) }
257257
258- /** Gets the index of `i` in its `IRBlock`. */
259- private int getMemberIndex ( Instruction i ) {
260- startsBasicBlock ( i ) and
261- result = 0
262- or
263- exists ( Instruction iPrev |
264- adjacentInBlock ( iPrev , i ) and
265- result = getMemberIndex ( iPrev ) + 1
266- )
267- }
268-
269- private module BlockAdjacency = QlBuiltins:: EquivalenceRelation< Instruction , adjacentInBlock / 2 > ;
258+ /** Holds if `i` is the `index`th instruction the block starting with `first`. */
259+ private Instruction getInstructionFromFirst ( Instruction first , int index ) =
260+ shortestDistances( startsBasicBlock / 1 , adjacentInBlock / 2 ) ( first , result , index )
270261
271262 /** Holds if `i` is the `index`th instruction in `block`. */
272263 cached
273264 Instruction getInstruction ( TIRBlock block , int index ) {
274- exists ( Instruction first | block = MkIRBlock ( first ) |
275- first = result and index = 0
276- or
277- index = getMemberIndex ( result ) and
278- BlockAdjacency:: getEquivalenceClass ( first ) = BlockAdjacency:: getEquivalenceClass ( result )
279- )
265+ result = getInstructionFromFirst ( getFirstInstruction ( block ) , index )
280266 }
281267
282268 cached
Original file line number Diff line number Diff line change @@ -255,28 +255,14 @@ private module Cached {
255255 cached
256256 newtype TIRBlock = MkIRBlock ( Instruction firstInstr ) { startsBasicBlock ( firstInstr ) }
257257
258- /** Gets the index of `i` in its `IRBlock`. */
259- private int getMemberIndex ( Instruction i ) {
260- startsBasicBlock ( i ) and
261- result = 0
262- or
263- exists ( Instruction iPrev |
264- adjacentInBlock ( iPrev , i ) and
265- result = getMemberIndex ( iPrev ) + 1
266- )
267- }
268-
269- private module BlockAdjacency = QlBuiltins:: EquivalenceRelation< Instruction , adjacentInBlock / 2 > ;
258+ /** Holds if `i` is the `index`th instruction the block starting with `first`. */
259+ private Instruction getInstructionFromFirst ( Instruction first , int index ) =
260+ shortestDistances( startsBasicBlock / 1 , adjacentInBlock / 2 ) ( first , result , index )
270261
271262 /** Holds if `i` is the `index`th instruction in `block`. */
272263 cached
273264 Instruction getInstruction ( TIRBlock block , int index ) {
274- exists ( Instruction first | block = MkIRBlock ( first ) |
275- first = result and index = 0
276- or
277- index = getMemberIndex ( result ) and
278- BlockAdjacency:: getEquivalenceClass ( first ) = BlockAdjacency:: getEquivalenceClass ( result )
279- )
265+ result = getInstructionFromFirst ( getFirstInstruction ( block ) , index )
280266 }
281267
282268 cached
Original file line number Diff line number Diff line change @@ -255,28 +255,14 @@ private module Cached {
255255 cached
256256 newtype TIRBlock = MkIRBlock ( Instruction firstInstr ) { startsBasicBlock ( firstInstr ) }
257257
258- /** Gets the index of `i` in its `IRBlock`. */
259- private int getMemberIndex ( Instruction i ) {
260- startsBasicBlock ( i ) and
261- result = 0
262- or
263- exists ( Instruction iPrev |
264- adjacentInBlock ( iPrev , i ) and
265- result = getMemberIndex ( iPrev ) + 1
266- )
267- }
268-
269- private module BlockAdjacency = QlBuiltins:: EquivalenceRelation< Instruction , adjacentInBlock / 2 > ;
258+ /** Holds if `i` is the `index`th instruction the block starting with `first`. */
259+ private Instruction getInstructionFromFirst ( Instruction first , int index ) =
260+ shortestDistances( startsBasicBlock / 1 , adjacentInBlock / 2 ) ( first , result , index )
270261
271262 /** Holds if `i` is the `index`th instruction in `block`. */
272263 cached
273264 Instruction getInstruction ( TIRBlock block , int index ) {
274- exists ( Instruction first | block = MkIRBlock ( first ) |
275- first = result and index = 0
276- or
277- index = getMemberIndex ( result ) and
278- BlockAdjacency:: getEquivalenceClass ( first ) = BlockAdjacency:: getEquivalenceClass ( result )
279- )
265+ result = getInstructionFromFirst ( getFirstInstruction ( block ) , index )
280266 }
281267
282268 cached
Original file line number Diff line number Diff line change @@ -255,28 +255,14 @@ private module Cached {
255255 cached
256256 newtype TIRBlock = MkIRBlock ( Instruction firstInstr ) { startsBasicBlock ( firstInstr ) }
257257
258- /** Gets the index of `i` in its `IRBlock`. */
259- private int getMemberIndex ( Instruction i ) {
260- startsBasicBlock ( i ) and
261- result = 0
262- or
263- exists ( Instruction iPrev |
264- adjacentInBlock ( iPrev , i ) and
265- result = getMemberIndex ( iPrev ) + 1
266- )
267- }
268-
269- private module BlockAdjacency = QlBuiltins:: EquivalenceRelation< Instruction , adjacentInBlock / 2 > ;
258+ /** Holds if `i` is the `index`th instruction the block starting with `first`. */
259+ private Instruction getInstructionFromFirst ( Instruction first , int index ) =
260+ shortestDistances( startsBasicBlock / 1 , adjacentInBlock / 2 ) ( first , result , index )
270261
271262 /** Holds if `i` is the `index`th instruction in `block`. */
272263 cached
273264 Instruction getInstruction ( TIRBlock block , int index ) {
274- exists ( Instruction first | block = MkIRBlock ( first ) |
275- first = result and index = 0
276- or
277- index = getMemberIndex ( result ) and
278- BlockAdjacency:: getEquivalenceClass ( first ) = BlockAdjacency:: getEquivalenceClass ( result )
279- )
265+ result = getInstructionFromFirst ( getFirstInstruction ( block ) , index )
280266 }
281267
282268 cached
You can’t perform that action at this time.
0 commit comments