Skip to content

Commit 8031e3a

Browse files
author
djns1
committed
Implemented InOuts
1 parent 9108b17 commit 8031e3a

20 files changed

+327
-191
lines changed

ODIN_II/SRC/ast_elaborate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2656,11 +2656,11 @@ void create_param_table_for_scope(ast_node_t* module_items, sc_hierarchy* local_
26562656
/* symbols are already dealt with */
26572657
if (var_declare->types.variable.is_input
26582658
|| var_declare->types.variable.is_output
2659+
|| var_declare->types.variable.is_inout
26592660
|| var_declare->types.variable.is_reg
26602661
|| var_declare->types.variable.is_genvar
26612662
|| var_declare->types.variable.is_wire
26622663
|| var_declare->types.variable.is_defparam)
2663-
26642664
continue;
26652665

26662666
oassert(module_items->children[i]->children[j]->type == VAR_DECLARE);

ODIN_II/SRC/netlist_create_from_ast.cpp

Lines changed: 71 additions & 61 deletions
Large diffs are not rendered by default.

ODIN_II/SRC/netlist_utils.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ nnet_t* allocate_nnet() {
296296
*-------------------------------------------------------------------------------------------*/
297297
nnet_t* free_nnet(nnet_t* to_free) {
298298
if (to_free) {
299-
to_free->fanout_pins = (npin_t**)vtr::free(to_free->fanout_pins);
299+
if (to_free->num_fanout_pins)
300+
to_free->fanout_pins = (npin_t**)vtr::free(to_free->fanout_pins);
300301

301302
if (to_free->name)
302303
vtr::free(to_free->name);
@@ -417,13 +418,13 @@ void add_driver_pin_to_net(nnet_t* net, npin_t* pin) {
417418
* The lasting one is input, and output disappears
418419
*-------------------------------------------------------------------------------------------*/
419420
void combine_nets(nnet_t* output_net, nnet_t* input_net, netlist_t* netlist) {
421+
/* in case there are any fanouts in output net (should only be zero and one nodes) */
422+
join_nets(input_net, output_net);
420423
/* copy the driver over to the new_net */
421424
for (int i = 0; i < output_net->num_driver_pins; i++) {
422425
/* IF - there is a pin assigned to this net, then copy it */
423426
add_driver_pin_to_net(input_net, output_net->driver_pins[i]);
424427
}
425-
/* in case there are any fanouts in output net (should only be zero and one nodes) */
426-
join_nets(input_net, output_net);
427428
/* mark that this is combined */
428429
input_net->combined = true;
429430

@@ -465,11 +466,27 @@ void join_nets(nnet_t* join_to_net, nnet_t* other_net) {
465466
}
466467

467468
error_message(NETLIST, unknown_location, "%s", "Found a combinational loop");
468-
} else if (other_net->num_driver_pins > 1) {
469-
if (other_net->name && join_to_net->name)
470-
error_message(NETLIST, unknown_location, "Tried to join net %s to %s but this would lose %d drivers for net %s", other_net->name, join_to_net->name, other_net->num_driver_pins - 1, other_net->name);
471-
else
472-
error_message(NETLIST, unknown_location, "Tried to join nets but this would lose %d drivers", other_net->num_driver_pins - 1);
469+
} else if (other_net->num_driver_pins > 1 && join_to_net->num_driver_pins != 0) {
470+
bool drivers_match = true;
471+
if(other_net->num_driver_pins == join_to_net->num_driver_pins) {
472+
for (int i = 0; drivers_match && i < other_net->num_driver_pins; i++)
473+
{
474+
bool driver_match = false;
475+
for (int j = 0; !driver_match && j < join_to_net->num_driver_pins; j++)
476+
{
477+
driver_match = join_to_net->driver_pins[j] == other_net->driver_pins[i];
478+
}
479+
drivers_match &= driver_match;
480+
}
481+
}
482+
// Either we tried to eliminate a buffer into a net with multiple drivers
483+
// or we tried to combine nets that already had mismatching drivers
484+
if(!drivers_match) {
485+
if (other_net->name && join_to_net->name)
486+
error_message(NETLIST, unknown_location, "Tried to join net %s to %s but this would lose %d drivers for net %s", other_net->name, join_to_net->name, other_net->num_driver_pins - 1, other_net->name);
487+
else
488+
error_message(NETLIST, unknown_location, "Tried to join nets but this would lose %d drivers", other_net->num_driver_pins - 1);
489+
}
473490
}
474491

475492
/* copy the driver over to the new_net */

ODIN_II/SRC/output_blif.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,24 @@ static bool warn_undriven(nnode_t* node, nnet_t* net) {
6565
return false;
6666
}
6767

68-
// TODO Uncomment this for In Outs
69-
//static void merge_with_inputs(nnode_t* node, long pin_idx) {
70-
// oassert(pin_idx < node->num_input_pins);
71-
// nnet_t* net = node->input_pins[pin_idx]->net;
72-
// warn_undriven(node, net);
73-
// // Merge node with all inputs with fanout of 1
74-
// if (net->num_fanout_pins <= 1) {
75-
// for (int i = 0; i < net->num_driver_pins; i++) {
76-
// npin_t* driver = net->driver_pins[i];
77-
// if (driver->name != NULL && ((driver->node->type == MULTIPLY) || (driver->node->type == HARD_IP) || (driver->node->type == MEMORY) || (driver->node->type == ADD) || (driver->node->type == MINUS))) {
78-
// vtr::free(driver->name);
79-
// driver->name = vtr::strdup(node->name);
80-
// } else {
81-
// vtr::free(driver->node->name);
82-
// driver->node->name = vtr::strdup(node->name);
83-
// }
84-
// }
85-
// }
86-
//}
68+
static void merge_with_inputs(nnode_t* node, long pin_idx) {
69+
oassert(pin_idx < node->num_input_pins);
70+
nnet_t* net = node->input_pins[pin_idx]->net;
71+
warn_undriven(node, net);
72+
// Merge node with all inputs with fanout of 1
73+
if (net->num_fanout_pins <= 1) {
74+
for (int i = 0; i < net->num_driver_pins; i++) {
75+
npin_t* driver = net->driver_pins[i];
76+
if (driver->name != NULL && ((driver->node->type == MULTIPLY) || (driver->node->type == HARD_IP) || (driver->node->type == MEMORY) || (driver->node->type == ADD) || (driver->node->type == MINUS))) {
77+
vtr::free(driver->name);
78+
driver->name = vtr::strdup(node->name);
79+
} else {
80+
vtr::free(driver->node->name);
81+
driver->node->name = vtr::strdup(node->name);
82+
}
83+
}
84+
}
85+
}
8786

8887
static void print_net_driver(FILE* out, nnode_t* node, nnet_t* net, long driver_idx) {
8988
oassert(driver_idx < net->num_driver_pins);
@@ -221,14 +220,13 @@ void output_blif(FILE* out, netlist_t* netlist) {
221220
fprintf(out, "\n.names gnd\n.names unconn\n.names vcc\n1\n");
222221
fprintf(out, "\n");
223222

224-
// TODO Uncomment this for In Outs
225223
// connect all the outputs up to the last gate
226-
// for (long i = 0; i < netlist->num_top_output_nodes; i++) {
227-
// nnode_t* node = netlist->top_output_nodes[i];
228-
// for (int j = 0; j < node->num_input_pins; j++) {
229-
// merge_with_inputs(node, j);
230-
// }
231-
// }
224+
for (long i = 0; i < netlist->num_top_output_nodes; i++) {
225+
nnode_t* node = netlist->top_output_nodes[i];
226+
for (int j = 0; j < node->num_input_pins; j++) {
227+
merge_with_inputs(node, j);
228+
}
229+
}
232230

233231
/* traverse the internals of the flat net-list */
234232
if (strcmp(configuration.output_type.c_str(), "blif") == 0) {
@@ -241,8 +239,7 @@ void output_blif(FILE* out, netlist_t* netlist) {
241239
for (long i = 0; i < netlist->num_top_output_nodes; i++) {
242240
nnode_t* node = netlist->top_output_nodes[i];
243241

244-
// TODO Change this to > 1 for In Outs
245-
if (node->input_pins[0]->net->num_fanout_pins > 0) {
242+
if (node->input_pins[0]->net->num_fanout_pins > 1) {
246243
nnet_t* net = node->input_pins[0]->net;
247244
warn_undriven(node, net);
248245
for (int j = 0; j < net->num_driver_pins; j++) {

0 commit comments

Comments
 (0)