Skip to content

Commit 98348a9

Browse files
author
Dave Bartolomeo
committed
C++: QLDoc for IR.qll
1 parent 88f89b3 commit 98348a9

File tree

5 files changed

+230
-5
lines changed
  • cpp/ql/src/semmle/code/cpp/ir/implementation
  • csharp/ql/src/experimental/ir/implementation

5 files changed

+230
-5
lines changed

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
/**
2+
* Provides classes that describe the Intermediate Representation (IR) of the program.
3+
*
4+
* The IR is a representation of the semantics of the program, with very little dependence on the
5+
* syntax that was used to write the program. For example, in C++, the statements `i += 1;`, `i++`,
6+
* and `++i` all have the same semantic effect, but appear in the AST as three different types of
7+
* `Expr` node. In the IR, all three statements are broken down into a sequence of fundamental
8+
* operations similar to:
9+
*
10+
* ```
11+
* r1(int*) = VariableAddress[i] // Compute the address of variable `i`
12+
* r2(int) = Load &:r1, m0 // Load the value of `i`
13+
* r3(int) = Constant[1] // An integer constant with the value `1`
14+
* r4(int) = Add r2, r3 // Add `1` to the value of `i`
15+
* r5(int) = Store &r1, r4 // Store the new value back into the variable `i`
16+
* ```
17+
*
18+
* This allows IR-based analysis to focus on the fundamental operations, rather than having to be
19+
* concerned with the various ways of expressing those operations in source code.
20+
*
21+
* The key classes in the IR are:
22+
*
23+
* - `IRFunction` - Contains the IR for an entire function definition, including all of that
24+
* function's `Instruction`s, `IRBlock`s, and `IRVariables`.
25+
* - `Instruction` - A single operation in the IR. An instruction specifies the operation to be
26+
* performed, the operands that produce the inputs to that operation, and the type of the result
27+
* of the operation. Control flows from an `Instruction` to one of a set of successor
28+
* `Instruction`s.
29+
* - `Operand` - An input value of an `Instruction`. All inputs of an `Instruction` are explicitly
30+
* represented as `Operand`s, even if the input was implicit in the source code. An `Operand` has
31+
* a link to the `Instruction` that consumes its value (its "use") and a link to the `Instruction`
32+
* that produces its value (its "definition").
33+
* - `IRVariable` - A variable accessed by the IR for a particular function. An `IRVariable` is
34+
* created for each variable directly accessed by the function. In addition, `IRVariable`s are
35+
* created to represent certain temporary storage locations that do not have explicitly declared
36+
* variables in the source code, such as the return value of the function.
37+
* - `IRBlock` - A "basic block" in the control flow graph of a function. An `IRBlock` contains a
38+
* sequence of instructions such that control flow can only enter the block at the first
39+
* instruction, and can only leave the block from the last instruction.
40+
* - `IRType` - The type of a value accessed in the IR. Unlike the `Type` class in the AST, `IRType`
41+
* is language-neutral. For example, in C++, `unsigned int`, `char32_t`, and `wchar_t` might all
42+
* be represented as the `IRType` `uint4`, a four-byte unsigned integer.
43+
*/
44+
145
import IRFunction
246
import Instruction
347
import IRBlock
@@ -11,11 +55,12 @@ import Imports::MemoryAccessKind
1155
private newtype TIRPropertyProvider = MkIRPropertyProvider()
1256

1357
/**
14-
* Class that provides additional properties to be dumped for IR instructions and blocks when using
58+
* A class that provides additional properties to be dumped for IR instructions and blocks when using
1559
* the PrintIR module. Libraries that compute additional facts about IR elements can extend the
1660
* single instance of this class to specify the additional properties computed by the library.
1761
*/
1862
class IRPropertyProvider extends TIRPropertyProvider {
63+
/** Gets a textual representation of this element. */
1964
string toString() { result = "IRPropertyProvider" }
2065

2166
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IR.qll

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
/**
2+
* Provides classes that describe the Intermediate Representation (IR) of the program.
3+
*
4+
* The IR is a representation of the semantics of the program, with very little dependence on the
5+
* syntax that was used to write the program. For example, in C++, the statements `i += 1;`, `i++`,
6+
* and `++i` all have the same semantic effect, but appear in the AST as three different types of
7+
* `Expr` node. In the IR, all three statements are broken down into a sequence of fundamental
8+
* operations similar to:
9+
*
10+
* ```
11+
* r1(int*) = VariableAddress[i] // Compute the address of variable `i`
12+
* r2(int) = Load &:r1, m0 // Load the value of `i`
13+
* r3(int) = Constant[1] // An integer constant with the value `1`
14+
* r4(int) = Add r2, r3 // Add `1` to the value of `i`
15+
* r5(int) = Store &r1, r4 // Store the new value back into the variable `i`
16+
* ```
17+
*
18+
* This allows IR-based analysis to focus on the fundamental operations, rather than having to be
19+
* concerned with the various ways of expressing those operations in source code.
20+
*
21+
* The key classes in the IR are:
22+
*
23+
* - `IRFunction` - Contains the IR for an entire function definition, including all of that
24+
* function's `Instruction`s, `IRBlock`s, and `IRVariables`.
25+
* - `Instruction` - A single operation in the IR. An instruction specifies the operation to be
26+
* performed, the operands that produce the inputs to that operation, and the type of the result
27+
* of the operation. Control flows from an `Instruction` to one of a set of successor
28+
* `Instruction`s.
29+
* - `Operand` - An input value of an `Instruction`. All inputs of an `Instruction` are explicitly
30+
* represented as `Operand`s, even if the input was implicit in the source code. An `Operand` has
31+
* a link to the `Instruction` that consumes its value (its "use") and a link to the `Instruction`
32+
* that produces its value (its "definition").
33+
* - `IRVariable` - A variable accessed by the IR for a particular function. An `IRVariable` is
34+
* created for each variable directly accessed by the function. In addition, `IRVariable`s are
35+
* created to represent certain temporary storage locations that do not have explicitly declared
36+
* variables in the source code, such as the return value of the function.
37+
* - `IRBlock` - A "basic block" in the control flow graph of a function. An `IRBlock` contains a
38+
* sequence of instructions such that control flow can only enter the block at the first
39+
* instruction, and can only leave the block from the last instruction.
40+
* - `IRType` - The type of a value accessed in the IR. Unlike the `Type` class in the AST, `IRType`
41+
* is language-neutral. For example, in C++, `unsigned int`, `char32_t`, and `wchar_t` might all
42+
* be represented as the `IRType` `uint4`, a four-byte unsigned integer.
43+
*/
44+
145
import IRFunction
246
import Instruction
347
import IRBlock
@@ -11,11 +55,12 @@ import Imports::MemoryAccessKind
1155
private newtype TIRPropertyProvider = MkIRPropertyProvider()
1256

1357
/**
14-
* Class that provides additional properties to be dumped for IR instructions and blocks when using
58+
* A class that provides additional properties to be dumped for IR instructions and blocks when using
1559
* the PrintIR module. Libraries that compute additional facts about IR elements can extend the
1660
* single instance of this class to specify the additional properties computed by the library.
1761
*/
1862
class IRPropertyProvider extends TIRPropertyProvider {
63+
/** Gets a textual representation of this element. */
1964
string toString() { result = "IRPropertyProvider" }
2065

2166
/**

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
/**
2+
* Provides classes that describe the Intermediate Representation (IR) of the program.
3+
*
4+
* The IR is a representation of the semantics of the program, with very little dependence on the
5+
* syntax that was used to write the program. For example, in C++, the statements `i += 1;`, `i++`,
6+
* and `++i` all have the same semantic effect, but appear in the AST as three different types of
7+
* `Expr` node. In the IR, all three statements are broken down into a sequence of fundamental
8+
* operations similar to:
9+
*
10+
* ```
11+
* r1(int*) = VariableAddress[i] // Compute the address of variable `i`
12+
* r2(int) = Load &:r1, m0 // Load the value of `i`
13+
* r3(int) = Constant[1] // An integer constant with the value `1`
14+
* r4(int) = Add r2, r3 // Add `1` to the value of `i`
15+
* r5(int) = Store &r1, r4 // Store the new value back into the variable `i`
16+
* ```
17+
*
18+
* This allows IR-based analysis to focus on the fundamental operations, rather than having to be
19+
* concerned with the various ways of expressing those operations in source code.
20+
*
21+
* The key classes in the IR are:
22+
*
23+
* - `IRFunction` - Contains the IR for an entire function definition, including all of that
24+
* function's `Instruction`s, `IRBlock`s, and `IRVariables`.
25+
* - `Instruction` - A single operation in the IR. An instruction specifies the operation to be
26+
* performed, the operands that produce the inputs to that operation, and the type of the result
27+
* of the operation. Control flows from an `Instruction` to one of a set of successor
28+
* `Instruction`s.
29+
* - `Operand` - An input value of an `Instruction`. All inputs of an `Instruction` are explicitly
30+
* represented as `Operand`s, even if the input was implicit in the source code. An `Operand` has
31+
* a link to the `Instruction` that consumes its value (its "use") and a link to the `Instruction`
32+
* that produces its value (its "definition").
33+
* - `IRVariable` - A variable accessed by the IR for a particular function. An `IRVariable` is
34+
* created for each variable directly accessed by the function. In addition, `IRVariable`s are
35+
* created to represent certain temporary storage locations that do not have explicitly declared
36+
* variables in the source code, such as the return value of the function.
37+
* - `IRBlock` - A "basic block" in the control flow graph of a function. An `IRBlock` contains a
38+
* sequence of instructions such that control flow can only enter the block at the first
39+
* instruction, and can only leave the block from the last instruction.
40+
* - `IRType` - The type of a value accessed in the IR. Unlike the `Type` class in the AST, `IRType`
41+
* is language-neutral. For example, in C++, `unsigned int`, `char32_t`, and `wchar_t` might all
42+
* be represented as the `IRType` `uint4`, a four-byte unsigned integer.
43+
*/
44+
145
import IRFunction
246
import Instruction
347
import IRBlock
@@ -11,11 +55,12 @@ import Imports::MemoryAccessKind
1155
private newtype TIRPropertyProvider = MkIRPropertyProvider()
1256

1357
/**
14-
* Class that provides additional properties to be dumped for IR instructions and blocks when using
58+
* A class that provides additional properties to be dumped for IR instructions and blocks when using
1559
* the PrintIR module. Libraries that compute additional facts about IR elements can extend the
1660
* single instance of this class to specify the additional properties computed by the library.
1761
*/
1862
class IRPropertyProvider extends TIRPropertyProvider {
63+
/** Gets a textual representation of this element. */
1964
string toString() { result = "IRPropertyProvider" }
2065

2166
/**

csharp/ql/src/experimental/ir/implementation/raw/IR.qll

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
/**
2+
* Provides classes that describe the Intermediate Representation (IR) of the program.
3+
*
4+
* The IR is a representation of the semantics of the program, with very little dependence on the
5+
* syntax that was used to write the program. For example, in C++, the statements `i += 1;`, `i++`,
6+
* and `++i` all have the same semantic effect, but appear in the AST as three different types of
7+
* `Expr` node. In the IR, all three statements are broken down into a sequence of fundamental
8+
* operations similar to:
9+
*
10+
* ```
11+
* r1(int*) = VariableAddress[i] // Compute the address of variable `i`
12+
* r2(int) = Load &:r1, m0 // Load the value of `i`
13+
* r3(int) = Constant[1] // An integer constant with the value `1`
14+
* r4(int) = Add r2, r3 // Add `1` to the value of `i`
15+
* r5(int) = Store &r1, r4 // Store the new value back into the variable `i`
16+
* ```
17+
*
18+
* This allows IR-based analysis to focus on the fundamental operations, rather than having to be
19+
* concerned with the various ways of expressing those operations in source code.
20+
*
21+
* The key classes in the IR are:
22+
*
23+
* - `IRFunction` - Contains the IR for an entire function definition, including all of that
24+
* function's `Instruction`s, `IRBlock`s, and `IRVariables`.
25+
* - `Instruction` - A single operation in the IR. An instruction specifies the operation to be
26+
* performed, the operands that produce the inputs to that operation, and the type of the result
27+
* of the operation. Control flows from an `Instruction` to one of a set of successor
28+
* `Instruction`s.
29+
* - `Operand` - An input value of an `Instruction`. All inputs of an `Instruction` are explicitly
30+
* represented as `Operand`s, even if the input was implicit in the source code. An `Operand` has
31+
* a link to the `Instruction` that consumes its value (its "use") and a link to the `Instruction`
32+
* that produces its value (its "definition").
33+
* - `IRVariable` - A variable accessed by the IR for a particular function. An `IRVariable` is
34+
* created for each variable directly accessed by the function. In addition, `IRVariable`s are
35+
* created to represent certain temporary storage locations that do not have explicitly declared
36+
* variables in the source code, such as the return value of the function.
37+
* - `IRBlock` - A "basic block" in the control flow graph of a function. An `IRBlock` contains a
38+
* sequence of instructions such that control flow can only enter the block at the first
39+
* instruction, and can only leave the block from the last instruction.
40+
* - `IRType` - The type of a value accessed in the IR. Unlike the `Type` class in the AST, `IRType`
41+
* is language-neutral. For example, in C++, `unsigned int`, `char32_t`, and `wchar_t` might all
42+
* be represented as the `IRType` `uint4`, a four-byte unsigned integer.
43+
*/
44+
145
import IRFunction
246
import Instruction
347
import IRBlock
@@ -11,11 +55,12 @@ import Imports::MemoryAccessKind
1155
private newtype TIRPropertyProvider = MkIRPropertyProvider()
1256

1357
/**
14-
* Class that provides additional properties to be dumped for IR instructions and blocks when using
58+
* A class that provides additional properties to be dumped for IR instructions and blocks when using
1559
* the PrintIR module. Libraries that compute additional facts about IR elements can extend the
1660
* single instance of this class to specify the additional properties computed by the library.
1761
*/
1862
class IRPropertyProvider extends TIRPropertyProvider {
63+
/** Gets a textual representation of this element. */
1964
string toString() { result = "IRPropertyProvider" }
2065

2166
/**

csharp/ql/src/experimental/ir/implementation/unaliased_ssa/IR.qll

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
/**
2+
* Provides classes that describe the Intermediate Representation (IR) of the program.
3+
*
4+
* The IR is a representation of the semantics of the program, with very little dependence on the
5+
* syntax that was used to write the program. For example, in C++, the statements `i += 1;`, `i++`,
6+
* and `++i` all have the same semantic effect, but appear in the AST as three different types of
7+
* `Expr` node. In the IR, all three statements are broken down into a sequence of fundamental
8+
* operations similar to:
9+
*
10+
* ```
11+
* r1(int*) = VariableAddress[i] // Compute the address of variable `i`
12+
* r2(int) = Load &:r1, m0 // Load the value of `i`
13+
* r3(int) = Constant[1] // An integer constant with the value `1`
14+
* r4(int) = Add r2, r3 // Add `1` to the value of `i`
15+
* r5(int) = Store &r1, r4 // Store the new value back into the variable `i`
16+
* ```
17+
*
18+
* This allows IR-based analysis to focus on the fundamental operations, rather than having to be
19+
* concerned with the various ways of expressing those operations in source code.
20+
*
21+
* The key classes in the IR are:
22+
*
23+
* - `IRFunction` - Contains the IR for an entire function definition, including all of that
24+
* function's `Instruction`s, `IRBlock`s, and `IRVariables`.
25+
* - `Instruction` - A single operation in the IR. An instruction specifies the operation to be
26+
* performed, the operands that produce the inputs to that operation, and the type of the result
27+
* of the operation. Control flows from an `Instruction` to one of a set of successor
28+
* `Instruction`s.
29+
* - `Operand` - An input value of an `Instruction`. All inputs of an `Instruction` are explicitly
30+
* represented as `Operand`s, even if the input was implicit in the source code. An `Operand` has
31+
* a link to the `Instruction` that consumes its value (its "use") and a link to the `Instruction`
32+
* that produces its value (its "definition").
33+
* - `IRVariable` - A variable accessed by the IR for a particular function. An `IRVariable` is
34+
* created for each variable directly accessed by the function. In addition, `IRVariable`s are
35+
* created to represent certain temporary storage locations that do not have explicitly declared
36+
* variables in the source code, such as the return value of the function.
37+
* - `IRBlock` - A "basic block" in the control flow graph of a function. An `IRBlock` contains a
38+
* sequence of instructions such that control flow can only enter the block at the first
39+
* instruction, and can only leave the block from the last instruction.
40+
* - `IRType` - The type of a value accessed in the IR. Unlike the `Type` class in the AST, `IRType`
41+
* is language-neutral. For example, in C++, `unsigned int`, `char32_t`, and `wchar_t` might all
42+
* be represented as the `IRType` `uint4`, a four-byte unsigned integer.
43+
*/
44+
145
import IRFunction
246
import Instruction
347
import IRBlock
@@ -11,11 +55,12 @@ import Imports::MemoryAccessKind
1155
private newtype TIRPropertyProvider = MkIRPropertyProvider()
1256

1357
/**
14-
* Class that provides additional properties to be dumped for IR instructions and blocks when using
58+
* A class that provides additional properties to be dumped for IR instructions and blocks when using
1559
* the PrintIR module. Libraries that compute additional facts about IR elements can extend the
1660
* single instance of this class to specify the additional properties computed by the library.
1761
*/
1862
class IRPropertyProvider extends TIRPropertyProvider {
63+
/** Gets a textual representation of this element. */
1964
string toString() { result = "IRPropertyProvider" }
2065

2166
/**

0 commit comments

Comments
 (0)