001
002/*
003 * THIS FILE IS MACHINE_GENERATED. DO NOT EDIT.
004 * See InstructionFormats.template, InstructionFormatList.dat,
005 * OperatorList.dat, etc.
006 */
007
008package org.jikesrvm.compilers.opt.ir;
009
010import org.jikesrvm.Configuration;
011import org.jikesrvm.compilers.opt.ir.operand.*;
012
013/**
014 * The LookupSwitch InstructionFormat class.
015 *
016 * The header comment for {@link Instruction} contains
017 * an explanation of the role of InstructionFormats in the
018 * opt compiler's IR.
019 */
020@SuppressWarnings("unused")  // Machine generated code is never 100% clean
021public final class LookupSwitch extends InstructionFormat {
022  /**
023   * InstructionFormat identification method for LookupSwitch.
024   * @param i an instruction
025   * @return <code>true</code> if the InstructionFormat of the argument
026   *         instruction is LookupSwitch or <code>false</code>
027   *         if it is not.
028   */
029  public static boolean conforms(Instruction i) {
030    return conforms(i.operator());
031  }
032  /**
033   * InstructionFormat identification method for LookupSwitch.
034   * @param o an instruction
035   * @return <code>true</code> if the InstructionFormat of the argument
036   *         operator is LookupSwitch or <code>false</code>
037   *         if it is not.
038   */
039  public static boolean conforms(Operator o) {
040    return o.format == LookupSwitch_format;
041  }
042
043  /**
044   * Get the operand called Value from the
045   * argument instruction. Note that the returned operand
046   * will still point to its containing instruction.
047   * @param i the instruction to fetch the operand from
048   * @return the operand called Value
049   */
050  public static Operand getValue(Instruction i) {
051    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
052    return (Operand) i.getOperand(0);
053  }
054  /**
055   * Get the operand called Value from the argument
056   * instruction clearing its instruction pointer. The returned
057   * operand will not point to any containing instruction.
058   * @param i the instruction to fetch the operand from
059   * @return the operand called Value
060   */
061  public static Operand getClearValue(Instruction i) {
062    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
063    return (Operand) i.getClearOperand(0);
064  }
065  /**
066   * Set the operand called Value in the argument
067   * instruction to the argument operand. The operand will
068   * now point to the argument instruction as its containing
069   * instruction.
070   * @param i the instruction in which to store the operand
071   * @param Value the operand to store
072   */
073  public static void setValue(Instruction i, Operand Value) {
074    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
075    i.putOperand(0, Value);
076  }
077  /**
078   * Return the index of the operand called Value
079   * in the argument instruction.
080   * @param i the instruction to access.
081   * @return the index of the operand called Value
082   *         in the argument instruction
083   */
084  public static int indexOfValue(Instruction i) {
085    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
086    return 0;
087  }
088  /**
089   * Does the argument instruction have a non-null
090   * operand named Value?
091   * @param i the instruction to access.
092   * @return <code>true</code> if the instruction has an non-null
093   *         operand named Value or <code>false</code>
094   *         if it does not.
095   */
096  public static boolean hasValue(Instruction i) {
097    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
098    return i.getOperand(0) != null;
099  }
100
101  /**
102   * Get the operand called Unknown1 from the
103   * argument instruction. Note that the returned operand
104   * will still point to its containing instruction.
105   * @param i the instruction to fetch the operand from
106   * @return the operand called Unknown1
107   */
108  public static Operand getUnknown1(Instruction i) {
109    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
110    return (Operand) i.getOperand(1);
111  }
112  /**
113   * Get the operand called Unknown1 from the argument
114   * instruction clearing its instruction pointer. The returned
115   * operand will not point to any containing instruction.
116   * @param i the instruction to fetch the operand from
117   * @return the operand called Unknown1
118   */
119  public static Operand getClearUnknown1(Instruction i) {
120    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
121    return (Operand) i.getClearOperand(1);
122  }
123  /**
124   * Set the operand called Unknown1 in the argument
125   * instruction to the argument operand. The operand will
126   * now point to the argument instruction as its containing
127   * instruction.
128   * @param i the instruction in which to store the operand
129   * @param Unknown1 the operand to store
130   */
131  public static void setUnknown1(Instruction i, Operand Unknown1) {
132    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
133    i.putOperand(1, Unknown1);
134  }
135  /**
136   * Return the index of the operand called Unknown1
137   * in the argument instruction.
138   * @param i the instruction to access.
139   * @return the index of the operand called Unknown1
140   *         in the argument instruction
141   */
142  public static int indexOfUnknown1(Instruction i) {
143    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
144    return 1;
145  }
146  /**
147   * Does the argument instruction have a non-null
148   * operand named Unknown1?
149   * @param i the instruction to access.
150   * @return <code>true</code> if the instruction has an non-null
151   *         operand named Unknown1 or <code>false</code>
152   *         if it does not.
153   */
154  public static boolean hasUnknown1(Instruction i) {
155    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
156    return i.getOperand(1) != null;
157  }
158
159  /**
160   * Get the operand called Unknown2 from the
161   * argument instruction. Note that the returned operand
162   * will still point to its containing instruction.
163   * @param i the instruction to fetch the operand from
164   * @return the operand called Unknown2
165   */
166  public static Operand getUnknown2(Instruction i) {
167    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
168    return (Operand) i.getOperand(2);
169  }
170  /**
171   * Get the operand called Unknown2 from the argument
172   * instruction clearing its instruction pointer. The returned
173   * operand will not point to any containing instruction.
174   * @param i the instruction to fetch the operand from
175   * @return the operand called Unknown2
176   */
177  public static Operand getClearUnknown2(Instruction i) {
178    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
179    return (Operand) i.getClearOperand(2);
180  }
181  /**
182   * Set the operand called Unknown2 in the argument
183   * instruction to the argument operand. The operand will
184   * now point to the argument instruction as its containing
185   * instruction.
186   * @param i the instruction in which to store the operand
187   * @param Unknown2 the operand to store
188   */
189  public static void setUnknown2(Instruction i, Operand Unknown2) {
190    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
191    i.putOperand(2, Unknown2);
192  }
193  /**
194   * Return the index of the operand called Unknown2
195   * in the argument instruction.
196   * @param i the instruction to access.
197   * @return the index of the operand called Unknown2
198   *         in the argument instruction
199   */
200  public static int indexOfUnknown2(Instruction i) {
201    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
202    return 2;
203  }
204  /**
205   * Does the argument instruction have a non-null
206   * operand named Unknown2?
207   * @param i the instruction to access.
208   * @return <code>true</code> if the instruction has an non-null
209   *         operand named Unknown2 or <code>false</code>
210   *         if it does not.
211   */
212  public static boolean hasUnknown2(Instruction i) {
213    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
214    return i.getOperand(2) != null;
215  }
216
217  /**
218   * Get the operand called Default from the
219   * argument instruction. Note that the returned operand
220   * will still point to its containing instruction.
221   * @param i the instruction to fetch the operand from
222   * @return the operand called Default
223   */
224  public static BranchOperand getDefault(Instruction i) {
225    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
226    return (BranchOperand) i.getOperand(3);
227  }
228  /**
229   * Get the operand called Default from the argument
230   * instruction clearing its instruction pointer. The returned
231   * operand will not point to any containing instruction.
232   * @param i the instruction to fetch the operand from
233   * @return the operand called Default
234   */
235  public static BranchOperand getClearDefault(Instruction i) {
236    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
237    return (BranchOperand) i.getClearOperand(3);
238  }
239  /**
240   * Set the operand called Default in the argument
241   * instruction to the argument operand. The operand will
242   * now point to the argument instruction as its containing
243   * instruction.
244   * @param i the instruction in which to store the operand
245   * @param Default the operand to store
246   */
247  public static void setDefault(Instruction i, BranchOperand Default) {
248    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
249    i.putOperand(3, Default);
250  }
251  /**
252   * Return the index of the operand called Default
253   * in the argument instruction.
254   * @param i the instruction to access.
255   * @return the index of the operand called Default
256   *         in the argument instruction
257   */
258  public static int indexOfDefault(Instruction i) {
259    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
260    return 3;
261  }
262  /**
263   * Does the argument instruction have a non-null
264   * operand named Default?
265   * @param i the instruction to access.
266   * @return <code>true</code> if the instruction has an non-null
267   *         operand named Default or <code>false</code>
268   *         if it does not.
269   */
270  public static boolean hasDefault(Instruction i) {
271    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
272    return i.getOperand(3) != null;
273  }
274
275  /**
276   * Get the operand called DefaultBranchProfile from the
277   * argument instruction. Note that the returned operand
278   * will still point to its containing instruction.
279   * @param i the instruction to fetch the operand from
280   * @return the operand called DefaultBranchProfile
281   */
282  public static BranchProfileOperand getDefaultBranchProfile(Instruction i) {
283    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
284    return (BranchProfileOperand) i.getOperand(4);
285  }
286  /**
287   * Get the operand called DefaultBranchProfile from the argument
288   * instruction clearing its instruction pointer. The returned
289   * operand will not point to any containing instruction.
290   * @param i the instruction to fetch the operand from
291   * @return the operand called DefaultBranchProfile
292   */
293  public static BranchProfileOperand getClearDefaultBranchProfile(Instruction i) {
294    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
295    return (BranchProfileOperand) i.getClearOperand(4);
296  }
297  /**
298   * Set the operand called DefaultBranchProfile in the argument
299   * instruction to the argument operand. The operand will
300   * now point to the argument instruction as its containing
301   * instruction.
302   * @param i the instruction in which to store the operand
303   * @param DefaultBranchProfile the operand to store
304   */
305  public static void setDefaultBranchProfile(Instruction i, BranchProfileOperand DefaultBranchProfile) {
306    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
307    i.putOperand(4, DefaultBranchProfile);
308  }
309  /**
310   * Return the index of the operand called DefaultBranchProfile
311   * in the argument instruction.
312   * @param i the instruction to access.
313   * @return the index of the operand called DefaultBranchProfile
314   *         in the argument instruction
315   */
316  public static int indexOfDefaultBranchProfile(Instruction i) {
317    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
318    return 4;
319  }
320  /**
321   * Does the argument instruction have a non-null
322   * operand named DefaultBranchProfile?
323   * @param i the instruction to access.
324   * @return <code>true</code> if the instruction has an non-null
325   *         operand named DefaultBranchProfile or <code>false</code>
326   *         if it does not.
327   */
328  public static boolean hasDefaultBranchProfile(Instruction i) {
329    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
330    return i.getOperand(4) != null;
331  }
332
333  /**
334   * Get the k'th operand called Match from the
335   * argument instruction. Note that the returned operand
336   * will still point to its containing instruction.
337   * @param i the instruction to fetch the operand from
338   * @param k the index of the operand
339   * @return the k'th operand called Match
340   */
341  public static IntConstantOperand getMatch(Instruction i, int k) {
342    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
343    return (IntConstantOperand) i.getOperand(5+k*3+0);
344  }
345  /**
346   * Get the k'th operand called Match from the argument
347   * instruction clearing its instruction pointer. The returned
348   * operand will not point to any containing instruction.
349   * @param i the instruction to fetch the operand from
350   * @param k the index of the operand
351   * @return the k'th operand called Match
352   */
353  public static IntConstantOperand getClearMatch(Instruction i, int k) {
354    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
355    return (IntConstantOperand) i.getClearOperand(5+k*3+0);
356  }
357  /**
358   * Set the k'th operand called Match in the argument
359   * instruction to the argument operand. The operand will
360   * now point to the argument instruction as its containing
361   * instruction.
362   * @param i the instruction in which to store the operand
363   * @param k the index of the operand
364   * @param o the operand to store
365   */
366  public static void setMatch(Instruction i, int k, IntConstantOperand o) {
367    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
368    i.putOperand(5+k*3+0, o);
369  }
370  /**
371   * Return the index of the k'th operand called Match
372   * in the argument instruction.
373   * @param i the instruction to access.
374   * @param k the index of the operand.
375   * @return the index of the k'th operand called Match
376   *         in the argument instruction
377   */
378  public static int indexOfMatch(Instruction i, int k) {
379    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
380    return 5+k*3+0;
381  }
382  /**
383   * Does the argument instruction have a non-null
384   * k'th operand named Match?
385   * @param i the instruction to access.
386   * @param k the index of the operand.
387   * @return <code>true</code> if the instruction has an non-null
388   *         k'th operand named Match or <code>false</code>
389   *         if it does not.
390   */
391  public static boolean hasMatch(Instruction i, int k) {
392    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
393    return i.getOperand(5+k*3+0) != null;
394  }
395
396  /**
397   * Return the index of the first operand called Matches
398   * in the argument instruction.
399   * @param i the instruction to access.
400   * @return the index of the first operand called Matches
401   *         in the argument instruction
402   */
403  public static int indexOfMatches(Instruction i)
404  {
405    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
406    return 5;
407  }
408  /**
409   * Does the argument instruction have any Matches
410   * operands?
411   * @param i the instruction to access.
412   * @return <code>true</code> if the instruction has
413   *         Matches operands or <code>false</code>
414   *         if it does not.
415   */
416  public static boolean hasMatches(Instruction i)
417  {
418    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
419    return i.getNumberOfOperands()-5 > 0 && i.getOperand(5) != null;
420  }
421
422  /**
423   * How many variable-length operands called Matches
424   * does the argument instruction have?
425   * @param i the instruction to access
426   * @return the number of Matches operands the instruction has
427   */
428  public static int getNumberOfMatches(Instruction i)
429  {
430    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
431    return (i.getNumberOfOperands()-5)/3;
432  }
433
434  /**
435   * Change the number of Matches operands that may be stored in
436   * the argument instruction to numVarOps.
437   * @param i the instruction to access
438   * @param numVarOps the new number of variable operands called Matches
439   *        that may be stored in the instruction
440   */
441  public static void resizeNumberOfMatches(Instruction i, int numVarOps)
442  {
443    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
444  if (5+numVarOps*3>MIN_OPERAND_ARRAY_LENGTH)
445    i.resizeNumberOfOperands(5+numVarOps*3);
446  else
447    for (int j = 5+numVarOps*3; j < MIN_OPERAND_ARRAY_LENGTH; j++)
448      i.putOperand(j, null);
449  }
450  /**
451   * Get the k'th operand called Target from the
452   * argument instruction. Note that the returned operand
453   * will still point to its containing instruction.
454   * @param i the instruction to fetch the operand from
455   * @param k the index of the operand
456   * @return the k'th operand called Target
457   */
458  public static BranchOperand getTarget(Instruction i, int k) {
459    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
460    return (BranchOperand) i.getOperand(5+k*3+1);
461  }
462  /**
463   * Get the k'th operand called Target from the argument
464   * instruction clearing its instruction pointer. The returned
465   * operand will not point to any containing instruction.
466   * @param i the instruction to fetch the operand from
467   * @param k the index of the operand
468   * @return the k'th operand called Target
469   */
470  public static BranchOperand getClearTarget(Instruction i, int k) {
471    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
472    return (BranchOperand) i.getClearOperand(5+k*3+1);
473  }
474  /**
475   * Set the k'th operand called Target in the argument
476   * instruction to the argument operand. The operand will
477   * now point to the argument instruction as its containing
478   * instruction.
479   * @param i the instruction in which to store the operand
480   * @param k the index of the operand
481   * @param o the operand to store
482   */
483  public static void setTarget(Instruction i, int k, BranchOperand o) {
484    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
485    i.putOperand(5+k*3+1, o);
486  }
487  /**
488   * Return the index of the k'th operand called Target
489   * in the argument instruction.
490   * @param i the instruction to access.
491   * @param k the index of the operand.
492   * @return the index of the k'th operand called Target
493   *         in the argument instruction
494   */
495  public static int indexOfTarget(Instruction i, int k) {
496    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
497    return 5+k*3+1;
498  }
499  /**
500   * Does the argument instruction have a non-null
501   * k'th operand named Target?
502   * @param i the instruction to access.
503   * @param k the index of the operand.
504   * @return <code>true</code> if the instruction has an non-null
505   *         k'th operand named Target or <code>false</code>
506   *         if it does not.
507   */
508  public static boolean hasTarget(Instruction i, int k) {
509    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
510    return i.getOperand(5+k*3+1) != null;
511  }
512
513  /**
514   * Return the index of the first operand called Target
515   * in the argument instruction.
516   * @param i the instruction to access.
517   * @return the index of the first operand called Target
518   *         in the argument instruction
519   */
520  public static int indexOfTargets(Instruction i)
521  {
522    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
523    return 6;
524  }
525  /**
526   * Does the argument instruction have any operands
527   * named Target?
528   * @param i the instruction to access.
529   * @return <code>true</code> if the instruction has operands
530   *         named Target or <code>false</code> if it does not.
531   */
532  public static boolean hasTargets(Instruction i)
533  {
534    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
535    return i.getNumberOfOperands()-6 > 0 && i.getOperand(6) != null;
536  }
537
538  /**
539   * How many variable-length operands called Targets
540   * does the argument instruction have?
541   * @param i the instruction to access
542   * @return the number of operands called Targets the instruction has
543   */
544  public static int getNumberOfTargets(Instruction i)
545  {
546    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
547    return (i.getNumberOfOperands()-5)/3;
548  }
549
550  /**
551   * Change the number of Targets that may be stored in
552   * the argument instruction to numVarOps.
553   * @param i the instruction to access
554   * @param numVarOps the new number of variable operands called Targets
555   *        that may be stored in the instruction
556   */
557  public static void resizeNumberOfTargets(Instruction i, int numVarOps)
558  {
559    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
560  if (5+numVarOps*3>MIN_OPERAND_ARRAY_LENGTH)
561    i.resizeNumberOfOperands(5+numVarOps*3);
562  else
563    for (int j = 5+numVarOps*3; j < MIN_OPERAND_ARRAY_LENGTH; j++)
564      i.putOperand(j, null);
565  }
566  /**
567   * Get the k'th operand called BranchProfile from the
568   * argument instruction. Note that the returned operand
569   * will still point to its containing instruction.
570   * @param i the instruction to fetch the operand from
571   * @param k the index of the operand
572   * @return the k'th operand called BranchProfile
573   */
574  public static BranchProfileOperand getBranchProfile(Instruction i, int k) {
575    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
576    return (BranchProfileOperand) i.getOperand(5+k*3+2);
577  }
578  /**
579   * Get the k'th operand called BranchProfile from the argument
580   * instruction clearing its instruction pointer. The returned
581   * operand will not point to any containing instruction.
582   * @param i the instruction to fetch the operand from
583   * @param k the index of the operand
584   * @return the k'th operand called BranchProfile
585   */
586  public static BranchProfileOperand getClearBranchProfile(Instruction i, int k) {
587    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
588    return (BranchProfileOperand) i.getClearOperand(5+k*3+2);
589  }
590  /**
591   * Set the k'th operand called BranchProfile in the argument
592   * instruction to the argument operand. The operand will
593   * now point to the argument instruction as its containing
594   * instruction.
595   * @param i the instruction in which to store the operand
596   * @param k the index of the operand
597   * @param o the operand to store
598   */
599  public static void setBranchProfile(Instruction i, int k, BranchProfileOperand o) {
600    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
601    i.putOperand(5+k*3+2, o);
602  }
603  /**
604   * Return the index of the k'th operand called BranchProfile
605   * in the argument instruction.
606   * @param i the instruction to access.
607   * @param k the index of the operand.
608   * @return the index of the k'th operand called BranchProfile
609   *         in the argument instruction
610   */
611  public static int indexOfBranchProfile(Instruction i, int k) {
612    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
613    return 5+k*3+2;
614  }
615  /**
616   * Does the argument instruction have a non-null
617   * k'th operand named BranchProfile?
618   * @param i the instruction to access.
619   * @param k the index of the operand.
620   * @return <code>true</code> if the instruction has an non-null
621   *         k'th operand named BranchProfile or <code>false</code>
622   *         if it does not.
623   */
624  public static boolean hasBranchProfile(Instruction i, int k) {
625    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
626    return i.getOperand(5+k*3+2) != null;
627  }
628
629  /**
630   * Return the index of the first operand called BranchProfile
631   * in the argument instruction.
632   * @param i the instruction to access.
633   * @return the index of the first operand called BranchProfile
634   *         in the argument instruction
635   */
636  public static int indexOfBranchProfiles(Instruction i)
637  {
638    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
639    return 7;
640  }
641  /**
642   * Does the argument instruction have any operands
643   * named BranchProfile?
644   * @param i the instruction to access.
645   * @return <code>true</code> if the instruction has operands
646   *         named BranchProfile or <code>false</code> if it does not.
647   */
648  public static boolean hasBranchProfiles(Instruction i)
649  {
650    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
651    return i.getNumberOfOperands()-7 > 0 && i.getOperand(7) != null;
652  }
653
654  /**
655   * How many variable-length operands called BranchProfiles
656   * does the argument instruction have?
657   * @param i the instruction to access
658   * @return the number of operands called BranchProfiles the instruction has
659   */
660  public static int getNumberOfBranchProfiles(Instruction i)
661  {
662    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
663    return (i.getNumberOfOperands()-5)/3;
664  }
665
666  /**
667   * Change the number of BranchProfiles that may be stored in
668   * the argument instruction to numVarOps.
669   * @param i the instruction to access
670   * @param numVarOps the new number of variable operands called BranchProfiles
671   *        that may be stored in the instruction
672   */
673  public static void resizeNumberOfBranchProfiles(Instruction i, int numVarOps)
674  {
675    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LookupSwitch");
676  if (5+numVarOps*3>MIN_OPERAND_ARRAY_LENGTH)
677    i.resizeNumberOfOperands(5+numVarOps*3);
678  else
679    for (int j = 5+numVarOps*3; j < MIN_OPERAND_ARRAY_LENGTH; j++)
680      i.putOperand(j, null);
681  }
682
683  /**
684   * Create an instruction of the LookupSwitch instruction format.
685   * @param o the instruction's operator
686   * @param Value the instruction's Value operand
687   * @param Unknown1 the instruction's Unknown1 operand
688   * @param Unknown2 the instruction's Unknown2 operand
689   * @param Default the instruction's Default operand
690   * @param DefaultBranchProfile the instruction's DefaultBranchProfile operand
691   * @param numVarOps the number of variable length operands that
692   *                 will be stored in the insruction.
693   * @return the newly created LookupSwitch instruction
694   */
695  public static Instruction create(Operator o
696                   , Operand Value
697                   , Operand Unknown1
698                   , Operand Unknown2
699                   , BranchOperand Default
700                   , BranchProfileOperand DefaultBranchProfile
701                   , int numVarOps
702                )
703  {
704    if (Configuration.ExtremeAssertions && !conforms(o)) fail(o, "LookupSwitch");
705    Instruction i = Instruction.create(o, Math.max(5+numVarOps*3, MIN_OPERAND_ARRAY_LENGTH));
706    i.putOperand(0, Value);
707    i.putOperand(1, Unknown1);
708    i.putOperand(2, Unknown2);
709    i.putOperand(3, Default);
710    i.putOperand(4, DefaultBranchProfile);
711    return i;
712  }
713
714  /**
715   * Mutate the argument instruction into an instruction of the
716   * LookupSwitch instruction format having the specified
717   * operator and operands.
718   * @param i the instruction to mutate
719   * @param o the instruction's operator
720   * @param Value the instruction's Value operand
721   * @param Unknown1 the instruction's Unknown1 operand
722   * @param Unknown2 the instruction's Unknown2 operand
723   * @param Default the instruction's Default operand
724   * @param DefaultBranchProfile the instruction's DefaultBranchProfile operand
725   * @param numVarOps the number of variable length operands that
726   *                  will be stored in the instruction.
727   * @return the mutated instruction
728   */
729  public static Instruction mutate(Instruction i, Operator o
730                   , Operand Value
731                   , Operand Unknown1
732                   , Operand Unknown2
733                   , BranchOperand Default
734                   , BranchProfileOperand DefaultBranchProfile
735                   , int numVarOps
736                )
737  {
738    if (Configuration.ExtremeAssertions && !conforms(o)) fail(o, "LookupSwitch");
739    if (5+numVarOps*3>MIN_OPERAND_ARRAY_LENGTH)
740      i.resizeNumberOfOperands(5+numVarOps*3);
741
742    i.changeOperatorTo(o);
743    i.putOperand(0, Value);
744    i.putOperand(1, Unknown1);
745    i.putOperand(2, Unknown2);
746    i.putOperand(3, Default);
747    i.putOperand(4, DefaultBranchProfile);
748    return i;
749  }
750}
751