/**
 * MultipleXNF.java
 * @author Anthony L. Slade
 */
import byucc.jhdl.parsers.xnf.*;
import byucc.jhdl.base.*;
import byucc.jhdl.Logic.*;
public class MultipleXNF extends Logic {
  public static CellInterface[] cell_interface
    = { in("a",7), in("b",7), in("even",1), out("parity",1) };
  public static CellInterface[] implicit_interface
    = { clk("clk") };
  Wire a, b, even, clk, parity;
  // NOTE: You must explicitly say byucc.jhdl.base.Node here even
  // though this file imports all of byucc.jhdl.base.*.  That is
  // because there is a Node class in the byucc.jhdl.parsers.xnf
  // package as well.
  public MultipleXNF( byucc.jhdl.base.Node parent,
		      Wire a, Wire b, Wire even, Wire parity) {
    super(parent);
    this.a = connect("a", a);
    this.b = connect("b", b);
    this.even = connect("even", even);
    this.parity = connect("parity", parity);
    this.clk = connect("clk", getDefaultClock());
    // This is an intermediate wire between the two XNF-defined
    // circuits.  Notice that we don't call it "o" or "data", we call
    // it intermediateWire.
    Wire intermediate = wire(7,"intermediateWire"); 
    String[] test1Names = { "a", "b", "o", "clk" };
    Wire[] test1wires;
    for (int i = 0; i < 7; ++i) {
      test1wires = new Wire[] { a.gw(i), b.gw(i), intermediate.gw(i), clk };
      // NOTE: parseXNF is called 7 times, with different wires each
      // time it is called!
      XNFParser.parseXNF(this, test1Names, test1wires, "test1.xnf");
    }

    // Notice how the Strings in parityPorts don't actually match the
    // variable names of the wires in parityPorts; same thing goes for
    // the arrays used above.
    XNFPortInterface[] parityPorts = {
      new XNFPortInterface("even", even),
      new XNFPortInterface("data", intermediate),
      new XNFPortInterface("parity_value", parity),
    };
    // Notice that the .xnf extension was left off the name of the
    // file!  Also, this call to parseXNF will create a new level of
    // hierarchy for the circuit defined by the file "parity.xnf".
    // Also, note that this call to parseXNF uses the XNFPortInterface
    // class.
    XNFParser.parseXNF(this, parityPorts, "parity", true);
  }
}

