Skip to content

Commit beb9c9c

Browse files
C++: Sync identical files
1 parent 97fd7b4 commit beb9c9c

File tree

2 files changed

+88
-6
lines changed

2 files changed

+88
-6
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/PrintIR.qll

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
private import IR
22
import cpp
3+
import semmle.code.cpp.ir.IRConfiguration
4+
5+
private newtype TPrintIRConfiguration = MkPrintIRConfiguration()
6+
7+
/**
8+
* The query can extend this class to control which functions are printed.
9+
*/
10+
class PrintIRConfiguration extends TPrintIRConfiguration {
11+
string toString() {
12+
result = "PrintIRConfiguration"
13+
}
14+
15+
/**
16+
* Holds if the IR for `func` should be printed. By default, holds for all
17+
* functions.
18+
*/
19+
predicate shouldPrintFunction(Function func) {
20+
any()
21+
}
22+
}
23+
24+
private predicate shouldPrintFunction(Function func) {
25+
exists(PrintIRConfiguration config |
26+
config.shouldPrintFunction(func)
27+
)
28+
}
29+
30+
/**
31+
* Override of `IRConfiguration` to only create IR for the functions that are to be dumped.
32+
*/
33+
private class FilteredIRConfiguration extends IRConfiguration {
34+
override predicate shouldCreateIRForFunction(Function func) {
35+
shouldPrintFunction(func)
36+
}
37+
}
338

439
private string getAdditionalInstructionProperty(Instruction instr, string key) {
540
exists(IRPropertyProvider provider |
@@ -14,9 +49,15 @@ private string getAdditionalBlockProperty(IRBlock block, string key) {
1449
}
1550

1651
private newtype TPrintableIRNode =
17-
TPrintableFunctionIR(FunctionIR funcIR) or
18-
TPrintableIRBlock(IRBlock block) or
19-
TPrintableInstruction(Instruction instr)
52+
TPrintableFunctionIR(FunctionIR funcIR) {
53+
shouldPrintFunction(funcIR.getFunction())
54+
} or
55+
TPrintableIRBlock(IRBlock block) {
56+
shouldPrintFunction(block.getFunction())
57+
} or
58+
TPrintableInstruction(Instruction instr) {
59+
shouldPrintFunction(instr.getFunction())
60+
}
2061

2162
/**
2263
* A node to be emitted in the IR graph.

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/PrintIR.qll

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
private import IR
22
import cpp
3+
import semmle.code.cpp.ir.IRConfiguration
4+
5+
private newtype TPrintIRConfiguration = MkPrintIRConfiguration()
6+
7+
/**
8+
* The query can extend this class to control which functions are printed.
9+
*/
10+
class PrintIRConfiguration extends TPrintIRConfiguration {
11+
string toString() {
12+
result = "PrintIRConfiguration"
13+
}
14+
15+
/**
16+
* Holds if the IR for `func` should be printed. By default, holds for all
17+
* functions.
18+
*/
19+
predicate shouldPrintFunction(Function func) {
20+
any()
21+
}
22+
}
23+
24+
private predicate shouldPrintFunction(Function func) {
25+
exists(PrintIRConfiguration config |
26+
config.shouldPrintFunction(func)
27+
)
28+
}
29+
30+
/**
31+
* Override of `IRConfiguration` to only create IR for the functions that are to be dumped.
32+
*/
33+
private class FilteredIRConfiguration extends IRConfiguration {
34+
override predicate shouldCreateIRForFunction(Function func) {
35+
shouldPrintFunction(func)
36+
}
37+
}
338

439
private string getAdditionalInstructionProperty(Instruction instr, string key) {
540
exists(IRPropertyProvider provider |
@@ -14,9 +49,15 @@ private string getAdditionalBlockProperty(IRBlock block, string key) {
1449
}
1550

1651
private newtype TPrintableIRNode =
17-
TPrintableFunctionIR(FunctionIR funcIR) or
18-
TPrintableIRBlock(IRBlock block) or
19-
TPrintableInstruction(Instruction instr)
52+
TPrintableFunctionIR(FunctionIR funcIR) {
53+
shouldPrintFunction(funcIR.getFunction())
54+
} or
55+
TPrintableIRBlock(IRBlock block) {
56+
shouldPrintFunction(block.getFunction())
57+
} or
58+
TPrintableInstruction(Instruction instr) {
59+
shouldPrintFunction(instr.getFunction())
60+
}
2061

2162
/**
2263
* A node to be emitted in the IR graph.

0 commit comments

Comments
 (0)