⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 circuit.java

📁 一种将c高级语言转化给VHDL的编译器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    } else {      _nethash.addSource(name, port);      insertOutPort(name, name, name, width);    }  }  public Memory insertMemory(String name, String data, int width,			     String address, int address_width,			     String we, String output, int[] contents) {    Memory memory = newMemory(this, name, width, address_width, contents);    PortTag address_port = memory.addPort("addr",PortTag.IN, address_width);    _nethash.addSink( address, address_port);    PortTag clk = memory.addPort("clk", PortTag.IN, CONTROL);    _nethash.addSink("clk",clk);    // add a port for the processor.    // hmmm ... if we knew if there was more than one memory    // and if there were the same size (which they must be same size or     // smaller, then -- we could add a high bits for addressing multiple    // rams ...    insertParentPort(memory, "proc_addr", PortTag.IN, address_width);    if (data != null) {      // these go together.      PortTag in = memory.addPort("data", PortTag.IN, width);      _nethash.addSink( data, in);      PortTag we_port = memory.addPort("we", PortTag.IN, CONTROL);      _nethash.addSink( we, we_port);    }        insertParentPort(memory, "proc_data", PortTag.IN, width);    insertParentPort(memory, "proc_we", PortTag.IN, CONTROL);    if (output != null) {      PortTag out = memory.addPort("d_out", PortTag.OUT, width);      _nethash.addSink( output, out);    }    insertParentPort(memory, "proc_out", PortTag.OUT, width);    return memory;  }			   public Node insertNode(String name, HashMap ports, String object_name, 			 Object[] parameters) {    Node node = newNode(this, name, ports, object_name, parameters);        for (Iterator set_itr = ports.entrySet().iterator(); set_itr.hasNext();) {      Map.Entry entry = (Map.Entry)set_itr.next();      String net = (String)entry.getKey();      // my port_infos do not have nets.      PortTag port_info = (PortTag)entry.getValue();                   // ?? not necessary, done when added.      // port_info.setParent(node);      node.addPortTag(port_info);      if (port_info.getType() == PortTag.IN) {        _nethash.addSink(net, port_info);      } else if (port_info.getType() == PortTag.OUT) {        _nethash.addSource(net, port_info);      } else {        System.err.println("Circuit: insertNode: Unhandled port direction"                           +port_info.getType());        System.exit(-1);      }    }    return node;  }			       /**   * Create a new Port and associate wires with both sides of the new   * port.   *    * @param child_net Name of the    *     insider wire   * @param name Name of the port   * @param parent_net Name of the    *     outside wire   * @param width size of the port   * @return the newly created Port.   */  public Port insertOutPort(String child_net, String name, 			    String parent_net, int width) {    Port port = newPort(this, name, width, PortTag.OUT);        PortTag in = port.addPort("in", PortTag.IN, width);    _nethash.addSink(child_net, in);    if (parent_net != null) {      PortTag out = port.addPort("out", PortTag.OUT, width);      _parent.getNetHash().addSource(parent_net, out);    }    _ports.add(port);    return port;  }      /**   * Inserts a new Out port into the current Circuit.   *    * @param in_name Inside wire name   * @param out_name The name of    *     the new Port   * @param width size of the new    *     Port   * @return the newly created Port.   */  public Port insertOutPort(String in_name, String out_name, int width) {    return insertOutPort(in_name, out_name, null, width);  }    /**   * This is the generic operator insertation method.  It allows   * operators of any number of inputs and outputs and sizes to be   * inserted.  The input/outputs of this operator are defined by a   * HashMap made up of PortTags.  The Hash should be "String"   * "PortTag" where the string represents the name of the wire that   * should connect to this port.  This probably should be a special   * subclass of HashMap to assure that it is built correctly.   *    * @param type the kind of operation.   * @param map The map of inputs    *     and outputs and their wires..   * @return A newly minted Operator.   */  public Operator insertOperator(String name, Operation type, HashMap map) {    Operator op = newOperator(this, name, type);    // If this is pipelined...then a clk input should be added.    if(type.isPipelined()) {       PortTag clk_info = new PortTag(op, "clk", PortTag.IN, 1);      op.addPortTag(clk_info);      _nethash.addSink("clk", clk_info);    }    for (Iterator set_itr = map.entrySet().iterator(); set_itr.hasNext();) {      Map.Entry entry = (Map.Entry)set_itr.next();      String net = (String)entry.getKey();            PortTag port_info = (PortTag)entry.getValue();                   op.addPortTag(port_info);      if (port_info.getType() == PortTag.IN) {        _nethash.addSink(net, port_info);      } else if (port_info.getType() == PortTag.OUT) {        _nethash.addSource(net, port_info);      } else {        System.err.println("Circuit: insertOpertor: Unhandled port direction"                           +port_info.getType());        System.exit(-1);      }    }        return op;  }  /**   * This is a more traditionaly insertOperator for a fixed number of   * inputs All of the inputs and outputs must be the same size.  This   * is true of logic functions (sometimes) and some operators.   *    * @param type The kind of operator.   * @param in0 Input wire 1   * @param in1 Input wire 2   * @param in2 Input wire 3   * @param out Output wire   * @param width    * @return New Operator.   */  public Operator insertOperator(Operation type, String name, 				 String in0, String in1, String in2,				 String out, int width) {    Operator op = newOperator(this, name, type);    // If this is pipelined...then a clk input should be added.    if(type.isPipelined()) {       PortTag clk_info = new PortTag(op, "clk", PortTag.IN, 1);      op.addPortTag(clk_info);      _nethash.addSink("clk", clk_info);    }    PortTag port0 = op.addPort("in0", PortTag.IN, width);    _nethash.addSink(in0, port0);    if (in1 != null) {      PortTag port1 = op.addPort("in1", PortTag.IN, width);      _nethash.addSink(in1, port1);    }    if (in2 != null) {       PortTag port2 = op.addPort("in2", PortTag.IN, width);      _nethash.addSink(in2, port2);    }    PortTag q = op.addPort("out", PortTag.OUT, width);    _nethash.addSource(out, q);    return op;  }  /**   * @param type    * @param in0    * @param in1    * @param out    * @param width    */  public Operator insertOperator(Operation type, String name, 				 String in0, String in1, String out,				  int width) {    return insertOperator(type, name, in0, in1, null, out, width);  }  /**   * @param type    * @param in0    * @param out    * @param width    */  public Operator insertOperator(Operation type, String name, 				 String in0, String out, int width) {    return insertOperator(type, name, in0, null, null, out, width);  }  /**   * @param in_name    * @param out_name    * @param width    * @param contents    */  /*  public Register insertRegister(String name, String in_name, String out_name, 				 int width, int contents) {    return insertRegister(name, in_name, null, out_name, width, contents);  }  */  /**   * Creates s new register with a write enable and a preset value.   * The preset value and write enable are optional.  This method uses    * a hex string to hold integer/float/double types.   *    * @param in_name in wire name   * @param we_name write enable wire (optional)   * @param out_name output name   * @param width size of register   * @param contents pre-set value   * @return The new register.   */  private Register insertRegister(String name, String in_name, String we_name, 				 String out_name, int width, String contents) {    Register reg = newRegister(this, name, width, contents);        PortTag in = reg.addPort("in", PortTag.IN, width);    PortTag out = reg.addPort("out", PortTag.OUT, width);    /*        PortTag clk = reg.addPort("clk", PortTag.IN, CONTROL);    _nethash.addSink("clk",clk);    */    PortTag we = null;    if (we_name != null) {      we = reg.addPort("we", PortTag.IN, CONTROL);      _nethash.addSink(we_name, we);    }    _nethash.addSink( in_name, in);    _nethash.addSource( out_name, out);        return reg;  }  /**    * Creates a new register with a integer preset value.   */  public Register insertRegister(String name, String in_name, String we_name, 				 String out_name, int width, int contents) {    BigInteger big = BigInteger.valueOf(contents);    return insertRegister(name, in_name, we_name, out_name, width, 			  big);  }  /**    * Creates a new register with a integer preset value.   */  public Register insertRegister(String name, String in_name, String we_name, 				 String out_name, int width, 				 BigInteger contents) {    return insertRegister(name, in_name, we_name, out_name, width, 			  contents.toString(16));  }  /**   * Creates a new register with a float preset value.   */  public Register insertRegister(String name, String in_name, String we_name, 				 String out_name, int width, float contents) {        return insertRegister(name, in_name, we_name, out_name, width, 			  Integer.toHexString(Float.floatToRawIntBits(contents)));  }  /**   * Creates a new register with a double preset value.   */  public Register insertRegister(String name, String in_name, String we_name, 				 String out_name, int width, double contents) {    return insertRegister(name, in_name, we_name, out_name, width, 			  Long.toHexString(Double.doubleToRawLongBits(contents)));  }  /**   * Creates a hashset containing all of the nets of the circuit.    */  public HashSet collectNets(HashSet net_collection) {    // Add the nets at this level of hierarchy.    net_collection.addAll(getNets());    // Recursively go through sub-circuits...    Iterator it = getCircuits().iterator();    while(it.hasNext()) {      Circuit c = (Circuit) it.next();      c.collectNets(net_collection);    }    return net_collection;  }    /*    abstract CircuitCode   */    /**   * This is what is called to actuall build the circuit.  The generic   * objects allow for everything to be inserted and associated but   * the build process actually forms the circuit.  Prior to the build   * process is a good point at which to capture the generic circuit   * object.  This can be reformed and built at a later point if   * necessary.  The arg_o is really optional, but I like to leave a   * way to pass some random bits down to the implementation layers.   *    * @param name Name of thing to be built   * @param arg_o Special args   */  public abstract void build(String name, Object[] arg_o);  /**   * Not sure.  The old version had it -- it may need to be dropped.   * The only widths to be concerned about are the wires, since I do   * not think they need declared widths.   *    * @return true if the width of this object was set.   */  public abstract boolean setWidth();  /**   * These are really the "magic" of the Circuit object.  They allow   * the object to be used without knowing what the underlying   * technology is.  All off the elements of the object are abstracted   * away and must be called using these creation methods.   *    * @param graph parent Circuit   * @param name Name of the new circuit.   * @return a New Circuit   */  protected abstract Circuit newCircuit(Circuit graph, String name);  /**   * Produce a constant value.   *    * @param graph parent   * @param val constant value   * @param width requested width of the constant value.   * @return new constant node.   */  protected abstract Constant newConstant(Circuit graph, String name, 					  String val, int width, int type);  protected abstract FSM newFSM(Circuit graph, String name, 				StateMachine transitions);  /**   * Build a new memory.   *    * @param graph parent   * @param width data bus size   * @param address_width address bus size   * @param contents optional array defining the content   * @return A new Memory.   */  protected abstract Memory newMemory(Circuit graph, String name, 				      int width, int address_width, 				      int[] contents);  /**   * Insert a new Wire.   *    * @param graph parent   * @param name name   * @return the shiney new wire   */  protected abstract Net newNet(Circuit graph, String name);  /**   * This inserts a new "Leaf" Node object that will not be defined in this   * framework.  This allows the insertion of random black boxes which   * will be built using whatever tricks the underly technology wants   * to use.  For example with JHDL, it was possible to build a   * circuit modules that the synthesizer did not specifically know   * about.   *    * @param graph Circut parent   * @param name Name of the object   * @param ports Hashmap defining the ports and wires?   * @param object Name of the magic object   * @param objects special paramters or whatever the underlying guys   * want.   * @return A new circuit node.   */  protected abstract Node newNode(Circuit graph, String name, 				  HashMap ports, String object, 				  Object[] objects);    /**   * create a new Operator.   *    * @param graph parent   * @param type type of operator.   * @return The new operator.   */  protected abstract Operator newOperator(Circuit graph, String name, 					  Operation type);  /**   * Create a new port.   *    * @param graph parent.   * @param name name of new port.   * @param width size of the port.   * @param direction Direction in PortTag.CONSTANT.   * @return The new port.   */  protected abstract Port newPort(Circuit graph, String name, int width, 				  int direction);  /**   * Create a new register.   *    * @param graph parent   * @param width size   * @param contents contents   * @return the new register   */  protected abstract Register newRegister(Circuit graph, String name,					  int width, String contents);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -