@@ -27,11 +27,45 @@ private newtype TOperand =
2727 defInstr = Construction:: getPhiOperandDefinition ( useInstr , predecessorBlock , overlap )
2828 }
2929
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+
3064/**
3165 * A source operand of an `Instruction`. The operand represents a value consumed by the instruction.
3266 */
33- class Operand extends TOperand {
34- string toString ( ) { result = "Operand" }
67+ class Operand extends OperandBase {
68+ override string toString ( ) { result = "Operand" }
3569
3670 final Language:: Location getLocation ( ) { result = getUse ( ) .getLocation ( ) }
3771
@@ -165,8 +199,8 @@ class Operand extends TOperand {
165199 */
166200class MemoryOperand extends Operand {
167201 MemoryOperand ( ) {
168- this = TNonPhiMemoryOperand ( _ , _ , _ , _ ) or
169- this = TPhiOperand ( _ , _ , _ , _ )
202+ this instanceof NonPhiMemoryOperandBase or
203+ this instanceof PhiOperandBase
170204 }
171205
172206 /**
@@ -204,8 +238,8 @@ class NonPhiOperand extends Operand {
204238 OperandTag tag ;
205239
206240 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 , _)
209243 }
210244
211245 final override Instruction getUse ( ) { result = useInstr }
@@ -222,21 +256,25 @@ class NonPhiOperand extends Operand {
222256/**
223257 * An operand that consumes a register (non-memory) result.
224258 */
225- class RegisterOperand extends NonPhiOperand , TRegisterOperand {
259+ class RegisterOperand extends NonPhiOperand , RegisterOperandBase {
226260 override RegisterOperandTag tag ;
227261
262+ final override string toString ( ) { result = tag .toString ( ) }
263+
228264 final override Overlap getDefinitionOverlap ( ) {
229265 // All register results overlap exactly with their uses.
230266 result instanceof MustExactlyOverlap
231267 }
232268}
233269
234- class NonPhiMemoryOperand extends NonPhiOperand , MemoryOperand , TNonPhiMemoryOperand {
270+ class NonPhiMemoryOperand extends NonPhiOperand , MemoryOperand , NonPhiMemoryOperandBase {
235271 override MemoryOperandTag tag ;
236272 Overlap overlap ;
237273
238274 NonPhiMemoryOperand ( ) { this = TNonPhiMemoryOperand ( useInstr , tag , defInstr , overlap ) }
239275
276+ final override string toString ( ) { result = tag .toString ( ) }
277+
240278 final override Overlap getDefinitionOverlap ( ) { result = overlap }
241279}
242280
@@ -254,8 +292,6 @@ class TypedOperand extends NonPhiMemoryOperand {
254292 */
255293class AddressOperand extends RegisterOperand {
256294 override AddressOperandTag tag ;
257-
258- override string toString ( ) { result = "Address" }
259295}
260296
261297/**
@@ -264,8 +300,6 @@ class AddressOperand extends RegisterOperand {
264300 */
265301class BufferSizeOperand extends RegisterOperand {
266302 override BufferSizeOperandTag tag ;
267-
268- override string toString ( ) { result = "BufferSize" }
269303}
270304
271305/**
@@ -274,62 +308,48 @@ class BufferSizeOperand extends RegisterOperand {
274308 */
275309class LoadOperand extends TypedOperand {
276310 override LoadOperandTag tag ;
277-
278- override string toString ( ) { result = "Load" }
279311}
280312
281313/**
282314 * The source value operand of a `Store` instruction.
283315 */
284316class StoreValueOperand extends RegisterOperand {
285317 override StoreValueOperandTag tag ;
286-
287- override string toString ( ) { result = "StoreValue" }
288318}
289319
290320/**
291321 * The sole operand of a unary instruction (e.g. `Convert`, `Negate`, `Copy`).
292322 */
293323class UnaryOperand extends RegisterOperand {
294324 override UnaryOperandTag tag ;
295-
296- override string toString ( ) { result = "Unary" }
297325}
298326
299327/**
300328 * The left operand of a binary instruction (e.g. `Add`, `CompareEQ`).
301329 */
302330class LeftOperand extends RegisterOperand {
303331 override LeftOperandTag tag ;
304-
305- override string toString ( ) { result = "Left" }
306332}
307333
308334/**
309335 * The right operand of a binary instruction (e.g. `Add`, `CompareEQ`).
310336 */
311337class RightOperand extends RegisterOperand {
312338 override RightOperandTag tag ;
313-
314- override string toString ( ) { result = "Right" }
315339}
316340
317341/**
318342 * The condition operand of a `ConditionalBranch` or `Switch` instruction.
319343 */
320344class ConditionOperand extends RegisterOperand {
321345 override ConditionOperandTag tag ;
322-
323- override string toString ( ) { result = "Condition" }
324346}
325347
326348/**
327349 * The operand representing the target function of an `Call` instruction.
328350 */
329351class CallTargetOperand extends RegisterOperand {
330352 override CallTargetOperandTag tag ;
331-
332- override string toString ( ) { result = "CallTarget" }
333353}
334354
335355/**
@@ -347,43 +367,34 @@ class ArgumentOperand extends RegisterOperand {
347367 */
348368class ThisArgumentOperand extends ArgumentOperand {
349369 override ThisArgumentOperandTag tag ;
350-
351- override string toString ( ) { result = "ThisArgument" }
352370}
353371
354372/**
355373 * An operand representing an argument to a function call.
356374 */
357375class PositionalArgumentOperand extends ArgumentOperand {
358376 override PositionalArgumentOperandTag tag ;
359- int argIndex ;
360-
361- PositionalArgumentOperand ( ) { argIndex = tag .getArgIndex ( ) }
362-
363- override string toString ( ) { result = "Arg(" + argIndex + ")" }
364377
365378 /**
366379 * Gets the zero-based index of the argument.
367380 */
368- final int getIndex ( ) { result = argIndex }
381+ final int getIndex ( ) { result = tag . getArgIndex ( ) }
369382}
370383
371384class SideEffectOperand extends TypedOperand {
372385 override SideEffectOperandTag tag ;
373-
374- override string toString ( ) { result = "SideEffect" }
375386}
376387
377388/**
378389 * An operand of a `PhiInstruction`.
379390 */
380- class PhiInputOperand extends MemoryOperand , TPhiOperand {
391+ class PhiInputOperand extends MemoryOperand , PhiOperandBase {
381392 PhiInstruction useInstr ;
382393 Instruction defInstr ;
383394 IRBlock predecessorBlock ;
384395 Overlap overlap ;
385396
386- PhiInputOperand ( ) { this = TPhiOperand ( useInstr , defInstr , predecessorBlock , overlap ) }
397+ PhiInputOperand ( ) { this = phiOperand ( useInstr , defInstr , predecessorBlock , overlap ) }
387398
388399 override string toString ( ) { result = "Phi" }
389400
@@ -413,8 +424,6 @@ class PhiInputOperand extends MemoryOperand, TPhiOperand {
413424class ChiTotalOperand extends NonPhiMemoryOperand {
414425 override ChiTotalOperandTag tag ;
415426
416- override string toString ( ) { result = "ChiTotal" }
417-
418427 final override MemoryAccessKind getMemoryAccess ( ) { result instanceof ChiTotalMemoryAccess }
419428}
420429
@@ -424,7 +433,5 @@ class ChiTotalOperand extends NonPhiMemoryOperand {
424433class ChiPartialOperand extends NonPhiMemoryOperand {
425434 override ChiPartialOperandTag tag ;
426435
427- override string toString ( ) { result = "ChiPartial" }
428-
429436 final override MemoryAccessKind getMemoryAccess ( ) { result instanceof ChiPartialMemoryAccess }
430437}
0 commit comments