dspl.intermediate.instructions
Class LoopInstruction

java.lang.Object
  extended by dspl.intermediate.instructions.Instruction
      extended by dspl.intermediate.instructions.LoopInstruction

public class LoopInstruction
extends Instruction

LoopInstruction is used to represent for and while loops.
Note that in DSPL a while loop is a subclass of for-loop internally. meaning "for(x=0; x<10; x++) { ... }" == "x=0; while(x<10) { ... x++; }"

A note on terminology:
Assume a for loop of structure "for (x=0, y=7, z=10; x<10; x++) { a = 5+x; ... } The first portion ("x=0, y=7, z=10") is referred to as the Assignment Instruction(s) The second portion ("x<10;") is referred to as the Condition Instruction(s) The third portion ("x++") is referred to as the Arithmatic Instruction(s) The fourth portion ("a = 5+x") is referred to as the Loop Instruction(s)

Author:
David

Field Summary
 Instruction arithmaticInstr
          Contains the instruction(s) to be evaluated directly before evaluating the conditionInstr instruction(s)
 Instruction assignmentInstr
          Contains the instruction(s) to be evaluated before entering the loop is allowed to be empty
 Comparison comp
          Contains the single comparison instruction which if false, terminates the loop
 Instruction loopInstr
          Contains the instructions to be evaluated wtihin the body fo the loop
 
Fields inherited from class dspl.intermediate.instructions.Instruction
INST_TYPE_ARITHMATIC, INST_TYPE_BRANCH, INST_TYPE_CCALL, INST_TYPE_FORLOOP, lastInstruction, nextInstruction, prevInstruction
 
Constructor Summary
LoopInstruction(Instruction assignmentInstr, Comparison comp, Instruction arithmaticInstr, Instruction loopInstr)
           
 
Method Summary
 int getInstType()
           
 boolean usesVariable(Variable v)
          Designed to be a recursive call to see if a given variable is used anymore within a code block, after the current instruction.
 
Methods inherited from class dspl.intermediate.instructions.Instruction
setNextInstruction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

assignmentInstr

public Instruction assignmentInstr
Contains the instruction(s) to be evaluated before entering the loop is allowed to be empty


comp

public Comparison comp
Contains the single comparison instruction which if false, terminates the loop


arithmaticInstr

public Instruction arithmaticInstr
Contains the instruction(s) to be evaluated directly before evaluating the conditionInstr instruction(s)


loopInstr

public Instruction loopInstr
Contains the instructions to be evaluated wtihin the body fo the loop

Constructor Detail

LoopInstruction

public LoopInstruction(Instruction assignmentInstr,
                       Comparison comp,
                       Instruction arithmaticInstr,
                       Instruction loopInstr)
Parameters:
assignmentInstr - Assignment Instruction(s)
conditionInstr - Condition Instruction(s)
arithmaticInstr - Arithmatic Instruction(s)
loopInstr - Loop Instruction(s)
Method Detail

usesVariable

public boolean usesVariable(Variable v)
Description copied from class: Instruction
Designed to be a recursive call to see if a given variable is used anymore within a code block, after the current instruction. Intention is to allow a way to parse the Instruction tree to see if a specific variable is used again. NOTE: may not be necessary, or may need to be augmented to return a value indicating how far away from the current instruction will it be used again if desire to perform better register allocation.

Specified by:
usesVariable in class Instruction
Parameters:
v - the variable to search for to see if it is used
Returns:

getInstType

public int getInstType()
Specified by:
getInstType in class Instruction
Returns:
the instruction type of this instruction