/*------------------------------------------------------------------------ * (function: connect_nodes) * Connect one output node to the inputs of the input node *----------------------------------------------------------------------*/ void connect_nodes(nnode_t *out_node, int out_idx, nnode_t *in_node, int in_idx) { npin_t *new_in_pin; oassert(out_node->num_output_pins > out_idx); oassert(in_node->num_input_pins > in_idx); new_in_pin = allocate_npin(); /* create the pin that hooks up to the input */ add_input_pin_to_node(in_node, new_in_pin, in_idx); if (out_node->output_pins[out_idx] == NULL) { /* IF - this node has no output net or pin */ npin_t *new_out_pin; nnet_t *new_net; new_net = allocate_nnet(); new_out_pin = allocate_npin(); /* create the pin that hooks up to the input */ add_output_pin_to_node(out_node, new_out_pin, out_idx); /* hook up in pin out of the new net */ add_fanout_pin_to_net(new_net, new_in_pin); /* hook up the new pin 2 to this new net */ add_driver_pin_to_net(new_net, new_out_pin); } else { /* ELSE - there is a net so we just add a fanout */ /* hook up in pin out of the new net */ add_fanout_pin_to_net(out_node->output_pins[out_idx]->net, new_in_pin); } }
/*--------------------------------------------------------------------------------------------- * (function: get_a_one_pin) * this allows us to attach to the constant netlist driving one *-------------------------------------------------------------------------------------------*/ npin_t *get_one_pin(netlist_t *netlist) { npin_t *one_fanout_pin = allocate_npin(); one_fanout_pin->name = strdup(one_string); add_fanout_pin_to_net(netlist->one_net, one_fanout_pin); return one_fanout_pin; }
/*----------------------------------------------------------------------- * (function: get_a_zero_pin) * this allows us to attach to the constant netlist driving zero *---------------------------------------------------------------------*/ npin_t *get_zero_pin(netlist_t *netlist) { npin_t *zero_fanout_pin = allocate_npin(); zero_fanout_pin->name = strdup(zero_string); add_fanout_pin_to_net(netlist->zero_net, zero_fanout_pin); return zero_fanout_pin; }
/*----------------------------------------------------------------------- * (function: get_a_pad_pin) * this allows us to attach to the constant netlist driving hb_pad *---------------------------------------------------------------------*/ npin_t *get_pad_pin(netlist_t *netlist) { npin_t *pad_fanout_pin = allocate_npin(); pad_fanout_pin->name = strdup(pad_string); add_fanout_pin_to_net(netlist->pad_net, pad_fanout_pin); return pad_fanout_pin; }
/*--------------------------------------------------------------------------------------------- * (function: make_output_pins_for_existing_node) * Looks at a node and extracts the output pins into a signal list so they can be accessed * in this form *-------------------------------------------------------------------------------------------*/ signal_list_t *make_output_pins_for_existing_node(nnode_t* node, int width) { signal_list_t *return_list = init_signal_list(); int i; oassert(node->num_output_pins == width); for (i = 0; i < width; i++) { npin_t *new_pin1; npin_t *new_pin2; nnet_t *new_net; new_pin1 = allocate_npin(); new_pin2 = allocate_npin(); new_net = allocate_nnet(); new_net->name = node->name; /* hook the output pin into the node */ add_output_pin_to_node(node, new_pin1, i); /* hook up new pin 1 into the new net */ add_driver_pin_to_net(new_net, new_pin1); /* hook up the new pin 2 to this new net */ add_fanout_pin_to_net(new_net, new_pin2); /* add the new_pin2 to the list of pins */ add_pin_to_signal_list(return_list, new_pin2); } return return_list; }
/*------------------------------------------------------------------------- * (function: copy_input_npin) * Copies an input pin and potentially adds to the net *-----------------------------------------------------------------------*/ npin_t* copy_input_npin(npin_t* copy_pin) { npin_t *new_pin = allocate_npin(); oassert(copy_pin->type == INPUT); new_pin->name = copy_pin->name?strdup(copy_pin->name):0; new_pin->type = copy_pin->type; new_pin->mapping = copy_pin->mapping?strdup(copy_pin->mapping):0; new_pin->is_default = copy_pin->is_default; if (copy_pin->net != NULL) { add_fanout_pin_to_net(copy_pin->net, new_pin); } return new_pin; }
/*--------------------------------------------------------------------------------------------- * (function: remap_pin_to_new_net) *-------------------------------------------------------------------------------------------*/ void remap_pin_to_new_net(npin_t *pin, nnet_t *new_net) { if (pin->type == INPUT) { /* clean out the entry in the old net */ pin->net->fanout_pins[pin->pin_net_idx] = NULL; /* do the new addition */ add_fanout_pin_to_net(new_net, pin); } else if (pin->type == OUTPUT) { /* clean out the entry in the old net */ pin->net->driver_pin = NULL; /* do the new addition */ add_driver_pin_to_net(new_net, pin); } }
/*--------------------------------------------------------------------------------------------- * (function: join_nets) * Copies the fanouts from input net into net *-------------------------------------------------------------------------------------------*/ void join_nets(nnet_t *join_to_net, nnet_t* other_net) { if (join_to_net == other_net) { if ((join_to_net->driver_pin) && (join_to_net->driver_pin->node != NULL) && join_to_net->driver_pin->node->related_ast_node != NULL) error_message(NETLIST_ERROR, join_to_net->driver_pin->node->related_ast_node->line_number, join_to_net->driver_pin->node->related_ast_node->file_number, "This is a combinational loop\n"); else error_message(NETLIST_ERROR, -1, -1, "This is a combinational loop\n"); if ((join_to_net->fanout_pins[0] != NULL ) && (join_to_net->fanout_pins[0]->node != NULL) && join_to_net->fanout_pins[0]->node->related_ast_node != NULL) error_message(NETLIST_ERROR, join_to_net->fanout_pins[0]->node->related_ast_node->line_number, join_to_net->fanout_pins[0]->node->related_ast_node->file_number, "This is a combinational loop with more info\n"); else error_message(NETLIST_ERROR, -1, -1, "Same error - This is a combinational loop\n"); } /* copy the driver over to the new_net */ int i; for (i = 0; i < other_net->num_fanout_pins; i++) { if (other_net->fanout_pins[i] ) { add_fanout_pin_to_net(join_to_net, other_net->fanout_pins[i]); } } }