@@ -27,11 +27,45 @@ private newtype TOperand =
27
27
defInstr = Construction:: getPhiOperandDefinition ( useInstr , predecessorBlock , overlap )
28
28
}
29
29
30
+ private class OperandBase extends TOperand {
31
+ abstract string toString ( ) ;
32
+ }
33
+
34
+ private class RegisterOperandBase extends OperandBase , TRegisterOperand {
35
+ abstract override string toString ( ) ;
36
+ }
37
+
38
+ private RegisterOperandBase registerOperand (
39
+ Instruction useInstr , RegisterOperandTag tag , Instruction defInstr
40
+ ) {
41
+ result = TRegisterOperand ( useInstr , tag , defInstr )
42
+ }
43
+
44
+ private class NonPhiMemoryOperandBase extends OperandBase , TNonPhiMemoryOperand {
45
+ abstract override string toString ( ) ;
46
+ }
47
+
48
+ private NonPhiMemoryOperandBase nonPhiMemoryOperand (
49
+ Instruction useInstr , MemoryOperandTag tag , Instruction defInstr , Overlap overlap
50
+ ) {
51
+ result = TNonPhiMemoryOperand ( useInstr , tag , defInstr , overlap )
52
+ }
53
+
54
+ private class PhiOperandBase extends OperandBase , TPhiOperand {
55
+ abstract override string toString ( ) ;
56
+ }
57
+
58
+ private PhiOperandBase phiOperand (
59
+ Instruction useInstr , Instruction defInstr , IRBlock predecessorBlock , Overlap overlap
60
+ ) {
61
+ result = TPhiOperand ( useInstr , defInstr , predecessorBlock , overlap )
62
+ }
63
+
30
64
/**
31
65
* A source operand of an `Instruction`. The operand represents a value consumed by the instruction.
32
66
*/
33
- class Operand extends TOperand {
34
- string toString ( ) { result = "Operand" }
67
+ class Operand extends OperandBase {
68
+ override string toString ( ) { result = "Operand" }
35
69
36
70
final Language:: Location getLocation ( ) { result = getUse ( ) .getLocation ( ) }
37
71
@@ -165,8 +199,8 @@ class Operand extends TOperand {
165
199
*/
166
200
class MemoryOperand extends Operand {
167
201
MemoryOperand ( ) {
168
- this = TNonPhiMemoryOperand ( _ , _ , _ , _ ) or
169
- this = TPhiOperand ( _ , _ , _ , _ )
202
+ this instanceof NonPhiMemoryOperandBase or
203
+ this instanceof PhiOperandBase
170
204
}
171
205
172
206
/**
@@ -204,8 +238,8 @@ class NonPhiOperand extends Operand {
204
238
OperandTag tag ;
205
239
206
240
NonPhiOperand ( ) {
207
- this = TRegisterOperand ( useInstr , tag , defInstr ) or
208
- this = TNonPhiMemoryOperand ( useInstr , tag , defInstr , _)
241
+ this = registerOperand ( useInstr , tag , defInstr ) or
242
+ this = nonPhiMemoryOperand ( useInstr , tag , defInstr , _)
209
243
}
210
244
211
245
final override Instruction getUse ( ) { result = useInstr }
@@ -222,21 +256,25 @@ class NonPhiOperand extends Operand {
222
256
/**
223
257
* An operand that consumes a register (non-memory) result.
224
258
*/
225
- class RegisterOperand extends NonPhiOperand , TRegisterOperand {
259
+ class RegisterOperand extends NonPhiOperand , RegisterOperandBase {
226
260
override RegisterOperandTag tag ;
227
261
262
+ final override string toString ( ) { result = tag .toString ( ) }
263
+
228
264
final override Overlap getDefinitionOverlap ( ) {
229
265
// All register results overlap exactly with their uses.
230
266
result instanceof MustExactlyOverlap
231
267
}
232
268
}
233
269
234
- class NonPhiMemoryOperand extends NonPhiOperand , MemoryOperand , TNonPhiMemoryOperand {
270
+ class NonPhiMemoryOperand extends NonPhiOperand , MemoryOperand , NonPhiMemoryOperandBase {
235
271
override MemoryOperandTag tag ;
236
272
Overlap overlap ;
237
273
238
274
NonPhiMemoryOperand ( ) { this = TNonPhiMemoryOperand ( useInstr , tag , defInstr , overlap ) }
239
275
276
+ final override string toString ( ) { result = tag .toString ( ) }
277
+
240
278
final override Overlap getDefinitionOverlap ( ) { result = overlap }
241
279
}
242
280
@@ -254,8 +292,6 @@ class TypedOperand extends NonPhiMemoryOperand {
254
292
*/
255
293
class AddressOperand extends RegisterOperand {
256
294
override AddressOperandTag tag ;
257
-
258
- override string toString ( ) { result = "Address" }
259
295
}
260
296
261
297
/**
@@ -264,8 +300,6 @@ class AddressOperand extends RegisterOperand {
264
300
*/
265
301
class BufferSizeOperand extends RegisterOperand {
266
302
override BufferSizeOperandTag tag ;
267
-
268
- override string toString ( ) { result = "BufferSize" }
269
303
}
270
304
271
305
/**
@@ -274,62 +308,48 @@ class BufferSizeOperand extends RegisterOperand {
274
308
*/
275
309
class LoadOperand extends TypedOperand {
276
310
override LoadOperandTag tag ;
277
-
278
- override string toString ( ) { result = "Load" }
279
311
}
280
312
281
313
/**
282
314
* The source value operand of a `Store` instruction.
283
315
*/
284
316
class StoreValueOperand extends RegisterOperand {
285
317
override StoreValueOperandTag tag ;
286
-
287
- override string toString ( ) { result = "StoreValue" }
288
318
}
289
319
290
320
/**
291
321
* The sole operand of a unary instruction (e.g. `Convert`, `Negate`, `Copy`).
292
322
*/
293
323
class UnaryOperand extends RegisterOperand {
294
324
override UnaryOperandTag tag ;
295
-
296
- override string toString ( ) { result = "Unary" }
297
325
}
298
326
299
327
/**
300
328
* The left operand of a binary instruction (e.g. `Add`, `CompareEQ`).
301
329
*/
302
330
class LeftOperand extends RegisterOperand {
303
331
override LeftOperandTag tag ;
304
-
305
- override string toString ( ) { result = "Left" }
306
332
}
307
333
308
334
/**
309
335
* The right operand of a binary instruction (e.g. `Add`, `CompareEQ`).
310
336
*/
311
337
class RightOperand extends RegisterOperand {
312
338
override RightOperandTag tag ;
313
-
314
- override string toString ( ) { result = "Right" }
315
339
}
316
340
317
341
/**
318
342
* The condition operand of a `ConditionalBranch` or `Switch` instruction.
319
343
*/
320
344
class ConditionOperand extends RegisterOperand {
321
345
override ConditionOperandTag tag ;
322
-
323
- override string toString ( ) { result = "Condition" }
324
346
}
325
347
326
348
/**
327
349
* The operand representing the target function of an `Call` instruction.
328
350
*/
329
351
class CallTargetOperand extends RegisterOperand {
330
352
override CallTargetOperandTag tag ;
331
-
332
- override string toString ( ) { result = "CallTarget" }
333
353
}
334
354
335
355
/**
@@ -347,43 +367,34 @@ class ArgumentOperand extends RegisterOperand {
347
367
*/
348
368
class ThisArgumentOperand extends ArgumentOperand {
349
369
override ThisArgumentOperandTag tag ;
350
-
351
- override string toString ( ) { result = "ThisArgument" }
352
370
}
353
371
354
372
/**
355
373
* An operand representing an argument to a function call.
356
374
*/
357
375
class PositionalArgumentOperand extends ArgumentOperand {
358
376
override PositionalArgumentOperandTag tag ;
359
- int argIndex ;
360
-
361
- PositionalArgumentOperand ( ) { argIndex = tag .getArgIndex ( ) }
362
-
363
- override string toString ( ) { result = "Arg(" + argIndex + ")" }
364
377
365
378
/**
366
379
* Gets the zero-based index of the argument.
367
380
*/
368
- final int getIndex ( ) { result = argIndex }
381
+ final int getIndex ( ) { result = tag . getArgIndex ( ) }
369
382
}
370
383
371
384
class SideEffectOperand extends TypedOperand {
372
385
override SideEffectOperandTag tag ;
373
-
374
- override string toString ( ) { result = "SideEffect" }
375
386
}
376
387
377
388
/**
378
389
* An operand of a `PhiInstruction`.
379
390
*/
380
- class PhiInputOperand extends MemoryOperand , TPhiOperand {
391
+ class PhiInputOperand extends MemoryOperand , PhiOperandBase {
381
392
PhiInstruction useInstr ;
382
393
Instruction defInstr ;
383
394
IRBlock predecessorBlock ;
384
395
Overlap overlap ;
385
396
386
- PhiInputOperand ( ) { this = TPhiOperand ( useInstr , defInstr , predecessorBlock , overlap ) }
397
+ PhiInputOperand ( ) { this = phiOperand ( useInstr , defInstr , predecessorBlock , overlap ) }
387
398
388
399
override string toString ( ) { result = "Phi" }
389
400
@@ -413,8 +424,6 @@ class PhiInputOperand extends MemoryOperand, TPhiOperand {
413
424
class ChiTotalOperand extends NonPhiMemoryOperand {
414
425
override ChiTotalOperandTag tag ;
415
426
416
- override string toString ( ) { result = "ChiTotal" }
417
-
418
427
final override MemoryAccessKind getMemoryAccess ( ) { result instanceof ChiTotalMemoryAccess }
419
428
}
420
429
@@ -424,7 +433,5 @@ class ChiTotalOperand extends NonPhiMemoryOperand {
424
433
class ChiPartialOperand extends NonPhiMemoryOperand {
425
434
override ChiPartialOperandTag tag ;
426
435
427
- override string toString ( ) { result = "ChiPartial" }
428
-
429
436
final override MemoryAccessKind getMemoryAccess ( ) { result instanceof ChiPartialMemoryAccess }
430
437
}
0 commit comments