// $Id: LowInstruction.java,v 1.1.1.1 1999/12/05 22:19:51 mpp Exp $

package IR2;

import java.util.*;

public abstract class LowInstruction implements Traversable {
  protected Label label;
  public LowInstruction next; 
  protected DelocalizedInstruction deloc_instr;
  public boolean printed;

  public LowInstruction() { label = null; }
  
  public Label get_label() {
    return label;
  }
  
  public void add_label() {
    if (label == null) label = new Label();
  }    

  // For naming Enter nodes of methods
  public void set_label(String s) { label = new Label(s); }

  // Track what the first of the resulting Deloc'ed instructions are
  // Needed for nodes with labels, so the CFG can get fixed up correctly to
  // preserve the cycle.
  public void set_deloc_instr(DelocalizedInstruction di) { deloc_instr = di; }
  public DelocalizedInstruction get_deloc_instr() { return deloc_instr; }
  
  // Do the asm for this instruction ; toss it to output. return last
  // DelocalizedInstruction added to the graph (starting point for next)
  public abstract DelocalizedInstruction do_asm(Codegen c, MethodDescriptor d,
                                                CFG output,
                                                DelocalizedInstruction prev);
  
  /* Algebraic simplification optimization. */
  public void algebraic_simplify() { }

  
  public abstract String desc();
  
  public String pretty_print_lowIR(int indent, boolean recursive) {
    String output = "";

    if (this.printed) {
      if (label != null) {
	for (int i = 0; i < indent; i++) output += " ";
	return output + "---> " + label.get_name() + "\n";
      } 
      // return "weird. Needs label? " + this + "\n";
    }

    this.printed = true;
    if (label != null)
      output += label.get_name() + ":\n";

    for (int i = 0; i < indent; i++) output += " ";
    
    output += desc() + "\n";

    if (recursive && next != null)
      output += next.pretty_print_lowIR(indent, true);

    return output;
  }

}
