@@ -29,7 +29,13 @@ private Instruction getAnInstructionAtLine(IRFunction irFunc, Language::File fil
29
29
/**
30
30
* Represents a single operation in the IR.
31
31
*/
32
- class Instruction extends Construction:: TInstruction {
32
+ class Instruction extends Construction:: TStageInstruction {
33
+ Instruction ( ) {
34
+ // The base `TStageInstruction` type is a superset of the actual instructions appearing in this
35
+ // stage. This call lets the stage filter out the ones that are not reused from raw IR.
36
+ Construction:: hasInstruction ( this )
37
+ }
38
+
33
39
final string toString ( ) { result = getOpcode ( ) .toString ( ) + ": " + getAST ( ) .toString ( ) }
34
40
35
41
/**
@@ -194,14 +200,14 @@ class Instruction extends Construction::TInstruction {
194
200
* conversion.
195
201
*/
196
202
final Language:: Expr getConvertedResultExpression ( ) {
197
- result = Construction :: getInstructionConvertedResultExpression ( this )
203
+ result = Raw :: getInstructionConvertedResultExpression ( this )
198
204
}
199
205
200
206
/**
201
207
* Gets the unconverted form of the `Expr` whose result is computed by this instruction, if any.
202
208
*/
203
209
final Language:: Expr getUnconvertedResultExpression ( ) {
204
- result = Construction :: getInstructionUnconvertedResultExpression ( this )
210
+ result = Raw :: getInstructionUnconvertedResultExpression ( this )
205
211
}
206
212
207
213
final Language:: LanguageType getResultLanguageType ( ) {
@@ -212,6 +218,7 @@ class Instruction extends Construction::TInstruction {
212
218
* Gets the type of the result produced by this instruction. If the instruction does not produce
213
219
* a result, its result type will be `IRVoidType`.
214
220
*/
221
+ cached
215
222
final IRType getResultIRType ( ) { result = getResultLanguageType ( ) .getIRType ( ) }
216
223
217
224
/**
@@ -250,7 +257,7 @@ class Instruction extends Construction::TInstruction {
250
257
* result of the `Load` instruction is a prvalue of type `int`, representing
251
258
* the integer value loaded from variable `x`.
252
259
*/
253
- final predicate isGLValue ( ) { Construction :: getInstructionResultType ( this ) .hasType ( _, true ) }
260
+ final predicate isGLValue ( ) { getResultLanguageType ( ) .hasType ( _, true ) }
254
261
255
262
/**
256
263
* Gets the size of the result produced by this instruction, in bytes. If the
@@ -259,7 +266,7 @@ class Instruction extends Construction::TInstruction {
259
266
* If `this.isGLValue()` holds for this instruction, the value of
260
267
* `getResultSize()` will always be the size of a pointer.
261
268
*/
262
- final int getResultSize ( ) { result = Construction :: getInstructionResultType ( this ) .getByteSize ( ) }
269
+ final int getResultSize ( ) { result = getResultLanguageType ( ) .getByteSize ( ) }
263
270
264
271
/**
265
272
* Gets the opcode that specifies the operation performed by this instruction.
@@ -395,7 +402,7 @@ class Instruction extends Construction::TInstruction {
395
402
class VariableInstruction extends Instruction {
396
403
IRVariable var ;
397
404
398
- VariableInstruction ( ) { var = Construction :: getInstructionVariable ( this ) }
405
+ VariableInstruction ( ) { var = Raw :: getInstructionVariable ( this ) }
399
406
400
407
override string getImmediateString ( ) { result = var .toString ( ) }
401
408
@@ -410,7 +417,7 @@ class VariableInstruction extends Instruction {
410
417
class FieldInstruction extends Instruction {
411
418
Language:: Field field ;
412
419
413
- FieldInstruction ( ) { field = Construction :: getInstructionField ( this ) }
420
+ FieldInstruction ( ) { field = Raw :: getInstructionField ( this ) }
414
421
415
422
final override string getImmediateString ( ) { result = field .toString ( ) }
416
423
@@ -420,7 +427,7 @@ class FieldInstruction extends Instruction {
420
427
class FunctionInstruction extends Instruction {
421
428
Language:: Function funcSymbol ;
422
429
423
- FunctionInstruction ( ) { funcSymbol = Construction :: getInstructionFunction ( this ) }
430
+ FunctionInstruction ( ) { funcSymbol = Raw :: getInstructionFunction ( this ) }
424
431
425
432
final override string getImmediateString ( ) { result = funcSymbol .toString ( ) }
426
433
@@ -430,7 +437,7 @@ class FunctionInstruction extends Instruction {
430
437
class ConstantValueInstruction extends Instruction {
431
438
string value ;
432
439
433
- ConstantValueInstruction ( ) { value = Construction :: getInstructionConstantValue ( this ) }
440
+ ConstantValueInstruction ( ) { value = Raw :: getInstructionConstantValue ( this ) }
434
441
435
442
final override string getImmediateString ( ) { result = value }
436
443
@@ -440,7 +447,7 @@ class ConstantValueInstruction extends Instruction {
440
447
class IndexedInstruction extends Instruction {
441
448
int index ;
442
449
443
- IndexedInstruction ( ) { index = Construction :: getInstructionIndex ( this ) }
450
+ IndexedInstruction ( ) { index = Raw :: getInstructionIndex ( this ) }
444
451
445
452
final override string getImmediateString ( ) { result = index .toString ( ) }
446
453
@@ -603,11 +610,16 @@ class ConstantInstruction extends ConstantValueInstruction {
603
610
}
604
611
605
612
class IntegerConstantInstruction extends ConstantInstruction {
606
- IntegerConstantInstruction ( ) { getResultType ( ) instanceof Language:: IntegralType }
613
+ IntegerConstantInstruction ( ) {
614
+ exists ( IRType resultType |
615
+ resultType = getResultIRType ( ) and
616
+ ( resultType instanceof IRIntegerType or resultType instanceof IRBooleanType )
617
+ )
618
+ }
607
619
}
608
620
609
621
class FloatConstantInstruction extends ConstantInstruction {
610
- FloatConstantInstruction ( ) { getResultType ( ) instanceof Language :: FloatingPointType }
622
+ FloatConstantInstruction ( ) { getResultIRType ( ) instanceof IRFloatingPointType }
611
623
}
612
624
613
625
class StringConstantInstruction extends VariableInstruction {
@@ -704,7 +716,7 @@ class PointerArithmeticInstruction extends BinaryInstruction {
704
716
705
717
PointerArithmeticInstruction ( ) {
706
718
getOpcode ( ) instanceof PointerArithmeticOpcode and
707
- elementSize = Construction :: getInstructionElementSize ( this )
719
+ elementSize = Raw :: getInstructionElementSize ( this )
708
720
}
709
721
710
722
final override string getImmediateString ( ) { result = elementSize .toString ( ) }
@@ -753,7 +765,7 @@ class InheritanceConversionInstruction extends UnaryInstruction {
753
765
Language:: Class derivedClass ;
754
766
755
767
InheritanceConversionInstruction ( ) {
756
- Construction :: getInstructionInheritance ( this , baseClass , derivedClass )
768
+ Raw :: getInstructionInheritance ( this , baseClass , derivedClass )
757
769
}
758
770
759
771
final override string getImmediateString ( ) {
@@ -1216,7 +1228,7 @@ class CatchByTypeInstruction extends CatchInstruction {
1216
1228
1217
1229
CatchByTypeInstruction ( ) {
1218
1230
getOpcode ( ) instanceof Opcode:: CatchByType and
1219
- exceptionType = Construction :: getInstructionExceptionType ( this )
1231
+ exceptionType = Raw :: getInstructionExceptionType ( this )
1220
1232
}
1221
1233
1222
1234
final override string getImmediateString ( ) { result = exceptionType .toString ( ) }
@@ -1362,7 +1374,7 @@ class BuiltInOperationInstruction extends Instruction {
1362
1374
1363
1375
BuiltInOperationInstruction ( ) {
1364
1376
getOpcode ( ) instanceof BuiltInOperationOpcode and
1365
- operation = Construction :: getInstructionBuiltInOperation ( this )
1377
+ operation = Raw :: getInstructionBuiltInOperation ( this )
1366
1378
}
1367
1379
1368
1380
final Language:: BuiltInOperation getBuiltInOperation ( ) { result = operation }
0 commit comments