00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <string.h>
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <stdarg.h>
00027 #include "types.h"
00028 #include "globals.h"
00029 #include "errors.h"
00030 #include "netlist_utils.h"
00031 #include "node_creation_library.h"
00032 #include "odin_util.h"
00033 #include "util.h"
00034
00035
00036
00037
00038 nnode_t* allocate_nnode()
00039 {
00040 nnode_t *new_node;
00041
00042 new_node = (nnode_t *)my_malloc_struct(sizeof(nnode_t));
00043
00044 new_node->name = NULL;
00045 new_node->type = NO_OP;
00046 new_node->related_ast_node = NULL;
00047 new_node->traverse_visited = -1;
00048
00049 new_node->input_pins = NULL;
00050 new_node->num_input_pins = 0;
00051 new_node->output_pins = NULL;
00052 new_node->num_output_pins = 0;
00053
00054 new_node->input_port_sizes = NULL;
00055 new_node->num_input_port_sizes = 0;
00056 new_node->output_port_sizes = NULL;
00057 new_node->num_output_port_sizes = 0;
00058
00059 new_node->node_data = NULL;
00060 new_node->unique_node_data_id = -1;
00061
00062 new_node->forward_level = -1;
00063 new_node->backward_level = -1;
00064 new_node->sequential_level = -1;
00065 new_node->sequential_terminator = FALSE;
00066
00067 new_node->internal_netlist = NULL;
00068
00069 new_node->associated_function = NULL;
00070
00071 new_node->simulate_block_cycle = NULL;
00072 new_node->memory_data = NULL;
00073
00074 new_node->bit_map= NULL;
00075 new_node->bit_map_line_count=0;
00076
00077 return new_node;
00078 }
00079
00080
00081
00082
00083 void free_nnode(nnode_t *to_free)
00084 {
00085 int i;
00086
00087 if (to_free != NULL)
00088 {
00089
00090
00091 for (i = 0; i < to_free->num_input_pins; i++)
00092 {
00093 if (to_free->input_pins[i] != NULL)
00094 {
00095 free_npin(to_free->input_pins[i]);
00096 to_free->input_pins[i] = NULL;
00097 }
00098 }
00099 if (to_free->input_pins != NULL)
00100 {
00101 free(to_free->input_pins);
00102 to_free->input_pins = NULL;
00103 }
00104
00105 for (i = 0; i < to_free->num_output_pins; i++)
00106 {
00107 if (to_free->output_pins[i] != NULL)
00108 {
00109 free_npin(to_free->output_pins[i]);
00110 to_free->output_pins[i] = NULL;
00111 }
00112 }
00113 if (to_free->output_pins != NULL)
00114 {
00115 free(to_free->output_pins);
00116 to_free->output_pins = NULL;
00117 }
00118
00119 if (to_free->input_port_sizes != NULL)
00120 free(to_free->input_port_sizes);
00121 if (to_free->output_port_sizes != NULL)
00122 free(to_free->output_port_sizes);
00123
00124
00125 free(to_free);
00126 }
00127 }
00128
00129
00130
00131
00132
00133 void allocate_more_node_input_pins(nnode_t *node, int width)
00134 {
00135 int i;
00136
00137 if (width <= 0)
00138 {
00139 warning_message(NETLIST_ERROR, -1, -1, "tried adding output pins for with <= 0 %s\n", node->name);
00140 return;
00141 }
00142
00143 node->input_pins = (npin_t**)realloc(node->input_pins, sizeof(npin_t*)*(node->num_input_pins+width));
00144 for (i = 0; i < width; i++)
00145 {
00146 node->input_pins[node->num_input_pins+i] = NULL;
00147 }
00148 node->num_input_pins += width;
00149 }
00150
00151
00152
00153
00154
00155 void allocate_more_node_output_pins(nnode_t *node, int width)
00156 {
00157 int i;
00158
00159 if (width <= 0)
00160 {
00161 warning_message(NETLIST_ERROR, -1, -1, "tried adding output pins for with <= 0 %s\n", node->name);
00162 return;
00163 }
00164
00165 node->output_pins = (npin_t**)realloc(node->output_pins, sizeof(npin_t*)*(node->num_output_pins+width));
00166 for (i = 0; i < width; i++)
00167 {
00168 node->output_pins[node->num_output_pins+i] = NULL;
00169 }
00170 node->num_output_pins += width;
00171 }
00172
00173
00174
00175
00176 void add_output_port_information(nnode_t *node, int port_width)
00177 {
00178 node->output_port_sizes = (int *)realloc(node->output_port_sizes, sizeof(int)*(node->num_output_port_sizes+1));
00179 node->output_port_sizes[node->num_output_port_sizes] = port_width;
00180 node->num_output_port_sizes++;
00181 }
00182
00183
00184
00185
00186 void add_input_port_information(nnode_t *node, int port_width)
00187 {
00188 node->input_port_sizes = (int *)realloc(node->input_port_sizes, sizeof(int)*(node->num_input_port_sizes+1));
00189 node->input_port_sizes[node->num_input_port_sizes] = port_width;
00190 node->num_input_port_sizes++;
00191 }
00192
00193
00194
00195
00196 npin_t* allocate_npin()
00197 {
00198 npin_t *new_pin;
00199
00200 new_pin = (npin_t *)my_malloc_struct(sizeof(npin_t));
00201
00202 new_pin->name = NULL;
00203 new_pin->type = NO_ID;
00204 new_pin->net = NULL;
00205 new_pin->pin_net_idx = -1;
00206 new_pin->node = NULL;
00207 new_pin->pin_node_idx = -1;
00208 new_pin->mapping = NULL;
00209
00210 new_pin->sim_state = (sim_state_t *)malloc(sizeof(sim_state_t));
00211 new_pin->sim_state->cycle = -1;
00212 new_pin->sim_state->value = -1;
00213 new_pin->sim_state->prev_value = -1;
00214
00215 return new_pin;
00216 }
00217
00218
00219
00220
00221
00222 npin_t* copy_output_npin(npin_t* copy_pin)
00223 {
00224 npin_t *new_pin = allocate_npin();
00225 oassert(copy_pin->type == OUTPUT);
00226
00227 new_pin->name = copy_pin->name;
00228 new_pin->type = copy_pin->type;
00229 new_pin->net = copy_pin->net;
00230 new_pin->mapping = copy_pin->mapping;
00231 return new_pin;
00232 }
00233
00234
00235
00236
00237
00238 npin_t* copy_input_npin(npin_t* copy_pin)
00239 {
00240 npin_t *new_pin = allocate_npin();
00241 oassert(copy_pin->type == INPUT);
00242
00243 new_pin->name = copy_pin->name;
00244 new_pin->type = copy_pin->type;
00245 new_pin->mapping = copy_pin->mapping;
00246 if (copy_pin->net != NULL)
00247 {
00248 add_a_fanout_pin_to_net(copy_pin->net, new_pin);
00249 }
00250
00251 return new_pin;
00252 }
00253
00254
00255
00256
00257
00258 void free_npin(npin_t *to_free)
00259 {
00260 if (to_free != NULL)
00261 {
00262 free(to_free->sim_state);
00263 free(to_free);
00264 }
00265 }
00266
00267
00268
00269
00270 nnet_t* allocate_nnet()
00271 {
00272 nnet_t *new_net;
00273
00274 new_net = (nnet_t*)my_malloc_struct(sizeof(nnet_t));
00275
00276 new_net->name = NULL;
00277 new_net->driver_pin = NULL;
00278 new_net->fanout_pins = NULL;
00279 new_net->num_fanout_pins = 0;
00280 new_net->combined = FALSE;
00281
00282 new_net->net_data = NULL;
00283 new_net->unique_net_data_id = -1;
00284
00285 return new_net;
00286 }
00287
00288
00289
00290
00291
00292 void free_nnet(nnet_t *to_free)
00293 {
00294 if (to_free != NULL)
00295 {
00296 free(to_free);
00297 }
00298 }
00299
00300
00301
00302
00303 void move_a_output_pin(nnode_t *node, int old_idx, int new_idx)
00304 {
00305 npin_t *pin;
00306
00307 oassert(node != NULL);
00308 oassert(((old_idx >= 0) && (old_idx < node->num_output_pins)));
00309 oassert(((new_idx >= 0) && (new_idx < node->num_output_pins)));
00310
00311 pin = node->output_pins[old_idx];
00312 node->output_pins[new_idx] = node->output_pins[old_idx];
00313 node->output_pins[old_idx] = NULL;
00314
00315 pin->type = OUTPUT;
00316 pin->node = node;
00317 pin->pin_node_idx = new_idx;
00318 }
00319
00320
00321
00322
00323 void move_a_input_pin(nnode_t *node, int old_idx, int new_idx)
00324 {
00325 npin_t *pin;
00326
00327 oassert(node != NULL);
00328 oassert(((old_idx >= 0) && (old_idx < node->num_input_pins)));
00329 oassert(((new_idx >= 0) && (new_idx < node->num_input_pins)));
00330
00331 node->input_pins[new_idx] = node->input_pins[old_idx];
00332 pin = node->input_pins[old_idx];
00333 node->input_pins[old_idx] = NULL;
00334
00335 pin->type = INPUT;
00336 pin->node = node;
00337 pin->pin_node_idx = new_idx;
00338 }
00339
00340
00341
00342
00343 void add_a_input_pin_to_node_spot_idx(nnode_t *node, npin_t *pin, int pin_idx)
00344 {
00345 oassert(node != NULL);
00346 oassert(pin != NULL);
00347 oassert(pin_idx < node->num_input_pins);
00348
00349 node->input_pins[pin_idx] = pin;
00350
00351 pin->type = INPUT;
00352 pin->node = node;
00353 pin->pin_node_idx = pin_idx;
00354 }
00355
00356
00357
00358
00359 void add_a_fanout_pin_to_net(nnet_t *net, npin_t *pin)
00360 {
00361 oassert(net != NULL);
00362 oassert(pin != NULL);
00363 oassert(pin->type != OUTPUT);
00364
00365 net->fanout_pins = (npin_t**)realloc(net->fanout_pins, sizeof(npin_t*)*(net->num_fanout_pins+1));
00366 net->fanout_pins[net->num_fanout_pins] = pin;
00367 net->num_fanout_pins++;
00368
00369 pin->net = net;
00370 pin->pin_net_idx = net->num_fanout_pins-1;
00371 pin->type = INPUT;
00372 }
00373
00374
00375
00376
00377 void add_a_output_pin_to_node_spot_idx(nnode_t *node, npin_t *pin, int pin_idx)
00378 {
00379 oassert(node != NULL);
00380 oassert(pin != NULL);
00381 oassert(pin_idx < node->num_output_pins);
00382
00383 node->output_pins[pin_idx] = pin;
00384
00385 pin->type = OUTPUT;
00386 pin->node = node;
00387 pin->pin_node_idx = pin_idx;
00388 }
00389
00390
00391
00392
00393 void add_a_driver_pin_to_net(nnet_t *net, npin_t *pin)
00394 {
00395 oassert(net != NULL);
00396 oassert(pin != NULL);
00397 oassert(pin->type != INPUT);
00398
00399 net->driver_pin = pin;
00400
00401 pin->net = net;
00402 pin->type = OUTPUT;
00403 }
00404
00405
00406
00407
00408
00409
00410
00411 void combine_nets(nnet_t *output_net, nnet_t* input_net, netlist_t *netlist)
00412 {
00413
00414 if (output_net->driver_pin != NULL)
00415 {
00416
00417 add_a_driver_pin_to_net(input_net, output_net->driver_pin);
00418 }
00419
00420 join_nets(input_net, output_net);
00421
00422 input_net->combined = TRUE;
00423
00424
00425 if (output_net == netlist->zero_net)
00426 {
00427 netlist->zero_net = input_net;
00428 }
00429 else if (output_net == netlist->one_net)
00430 {
00431 netlist->one_net = input_net;
00432 }
00433
00434
00435 free_nnet(output_net);
00436 }
00437
00438
00439
00440
00441
00442 void join_nets(nnet_t *join_to_net, nnet_t* other_net)
00443 {
00444 int i;
00445
00446 if (join_to_net == other_net)
00447 {
00448 if ((join_to_net->driver_pin != NULL ) && (join_to_net->driver_pin->node != NULL) && join_to_net->driver_pin->node->related_ast_node != NULL)
00449 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");
00450 else
00451 error_message(NETLIST_ERROR, -1, -1, "This is a combinational loop\n");
00452 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)
00453 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");
00454 else
00455 error_message(NETLIST_ERROR, -1, -1, "Same error - This is a combinational loop\n");
00456 }
00457
00458
00459 for (i = 0; i < other_net->num_fanout_pins; i++)
00460 {
00461 if (other_net->fanout_pins[i] != NULL)
00462 {
00463 add_a_fanout_pin_to_net(join_to_net, other_net->fanout_pins[i]);
00464 }
00465 }
00466 }
00467
00468
00469
00470
00471 void remap_pin_to_new_net(npin_t *pin, nnet_t *new_net)
00472 {
00473 if (pin->type == INPUT)
00474 {
00475
00476 pin->net->fanout_pins[pin->pin_net_idx] = NULL;
00477
00478 add_a_fanout_pin_to_net(new_net, pin);
00479 }
00480 else if (pin->type == OUTPUT)
00481 {
00482
00483 pin->net->driver_pin = NULL;
00484
00485 add_a_driver_pin_to_net(new_net, pin);
00486 }
00487 }
00488
00489
00490
00491
00492 void remap_pin_to_new_node(npin_t *pin, nnode_t *new_node, int pin_idx)
00493 {
00494 if (pin->type == INPUT)
00495 {
00496
00497 pin->node->input_pins[pin->pin_node_idx] = NULL;
00498
00499 add_a_input_pin_to_node_spot_idx(new_node, pin, pin_idx);
00500 }
00501 else if (pin->type == OUTPUT)
00502 {
00503
00504 pin->node->output_pins[pin->pin_node_idx] = NULL;
00505
00506 add_a_output_pin_to_node_spot_idx(new_node, pin, pin_idx);
00507 }
00508 }
00509
00510
00511
00512
00513
00514 void connect_nodes(nnode_t *out_node, int out_idx, nnode_t *in_node, int in_idx)
00515 {
00516 npin_t *new_in_pin;
00517
00518 oassert(out_node->num_output_pins > out_idx);
00519 oassert(in_node->num_input_pins > in_idx);
00520
00521 new_in_pin = allocate_npin();
00522
00523
00524 add_a_input_pin_to_node_spot_idx(in_node, new_in_pin, in_idx);
00525
00526 if (out_node->output_pins[out_idx] == NULL)
00527 {
00528
00529 npin_t *new_out_pin;
00530 nnet_t *new_net;
00531 new_net = allocate_nnet();
00532 new_out_pin = allocate_npin();
00533
00534
00535 add_a_output_pin_to_node_spot_idx(out_node, new_out_pin, out_idx);
00536
00537 add_a_fanout_pin_to_net(new_net, new_in_pin);
00538
00539 add_a_driver_pin_to_net(new_net, new_out_pin);
00540 }
00541 else
00542 {
00543
00544
00545 add_a_fanout_pin_to_net(out_node->output_pins[out_idx]->net, new_in_pin);
00546 }
00547 }
00548
00549
00550
00551
00552
00553
00554 signal_list_t *init_signal_list_structure()
00555 {
00556 signal_list_t *list;
00557 list = (signal_list_t*)malloc(sizeof(signal_list_t));
00558
00559 list->signal_list_size = 0;
00560 list->signal_list = NULL;
00561 list->is_memory = FALSE;
00562
00563 return list;
00564 }
00565
00566
00567
00568
00569
00570 void add_pin_to_signal_list(signal_list_t *list, npin_t* pin)
00571 {
00572 list->signal_list = (npin_t**)realloc(list->signal_list, sizeof(npin_t*)*(list->signal_list_size+1));
00573 list->signal_list[list->signal_list_size] = pin;
00574 list->signal_list_size++;
00575 }
00576
00577
00578
00579
00580 signal_list_t *combine_lists(signal_list_t **signal_lists, int num_signal_lists)
00581 {
00582 int i, j;
00583
00584 for (i = 1; i < num_signal_lists; i++)
00585 {
00586 for (j = 0; j < signal_lists[i]->signal_list_size; j++)
00587 {
00588 add_pin_to_signal_list(signal_lists[0], signal_lists[i]->signal_list[j]);
00589 }
00590 clean_signal_list_structure(signal_lists[i]);
00591 }
00592
00593 return signal_lists[0];
00594 }
00595
00596
00597
00598
00599 signal_list_t *combine_lists_without_freeing_originals(signal_list_t **signal_lists, int num_signal_lists)
00600 {
00601 int i, j;
00602 signal_list_t *return_list = init_signal_list_structure();
00603
00604 for (i = 0; i < num_signal_lists; i++)
00605 {
00606 for (j = 0; j < signal_lists[i]->signal_list_size; j++)
00607 {
00608 add_pin_to_signal_list(return_list, signal_lists[i]->signal_list[j]);
00609 }
00610 }
00611
00612 return return_list;
00613 }
00614
00615
00616
00617
00618
00619 void sort_signal_list_alphabetically(signal_list_t *list)
00620 {
00621 int i, j;
00622 npin_t *tmp_pin;
00623
00624 for (i = 0; i < list->signal_list_size-1; i++)
00625 {
00626 for (j = 0; j< (list->signal_list_size-1-i); j++)
00627 {
00628
00629 if (strcmp(list->signal_list[j+1]->name, list->signal_list[j]->name) < 0 )
00630 {
00631 tmp_pin = list->signal_list[j];
00632 list->signal_list[j] = list->signal_list[j+1];
00633 list->signal_list[j+1] = tmp_pin;
00634 }
00635 }
00636 }
00637 }
00638
00639
00640
00641
00642
00643
00644 signal_list_t *make_output_pins_for_existing_node(nnode_t* node, int width)
00645 {
00646 signal_list_t *return_list = init_signal_list_structure();
00647 int i;
00648
00649 oassert(node->num_output_pins == width);
00650
00651 for (i = 0; i < width; i++)
00652 {
00653 npin_t *new_pin1;
00654 npin_t *new_pin2;
00655 nnet_t *new_net;
00656 new_pin1 = allocate_npin();
00657 new_pin2 = allocate_npin();
00658 new_net = allocate_nnet();
00659 new_net->name = node->name;
00660
00661 add_a_output_pin_to_node_spot_idx(node, new_pin1, i);
00662
00663 add_a_driver_pin_to_net(new_net, new_pin1);
00664
00665 add_a_fanout_pin_to_net(new_net, new_pin2);
00666
00667
00668 add_pin_to_signal_list(return_list, new_pin2);
00669 }
00670
00671 return return_list;
00672 }
00673
00674
00675
00676
00677 void clean_signal_list_structure(signal_list_t *list)
00678 {
00679 if (list == NULL)
00680 return;
00681 if (list->signal_list != NULL)
00682 free(list->signal_list);
00683 list->signal_list_size = 0;
00684
00685 free(list);
00686 }
00687
00688
00689
00690
00691
00692 void hookup_input_pins_from_signal_list(nnode_t *node, int n_start_idx, signal_list_t* input_list, int il_start_idx, int width, netlist_t *netlist)
00693 {
00694 int i;
00695
00696 for (i = 0; i < width; i++)
00697 {
00698 if (il_start_idx+i < input_list->signal_list_size)
00699 {
00700 oassert(input_list->signal_list_size > (il_start_idx+i));
00701 add_a_input_pin_to_node_spot_idx(node, input_list->signal_list[il_start_idx+i], n_start_idx+i);
00702 }
00703 else
00704 {
00705
00706 add_a_input_pin_to_node_spot_idx(node, get_a_zero_pin(netlist), n_start_idx+i);
00707 warning_message(NETLIST_ERROR, -1, -1, "padding an input port with 0 for node %s\n", node->name);
00708 }
00709 }
00710 }
00711
00712
00713
00714
00715
00716
00717 void hookup_hb_input_pins_from_signal_list(nnode_t *node, int n_start_idx, signal_list_t* input_list, int il_start_idx, int width, netlist_t *netlist)
00718 {
00719 int i;
00720
00721 for (i = 0; i < width; i++)
00722 {
00723 if (il_start_idx+i < input_list->signal_list_size)
00724 {
00725 oassert(input_list->signal_list_size > (il_start_idx+i));
00726 add_a_input_pin_to_node_spot_idx(node, input_list->signal_list[il_start_idx+i], n_start_idx+i);
00727 }
00728 else
00729 {
00730
00731 add_a_input_pin_to_node_spot_idx(node, get_a_pad_pin(netlist), n_start_idx+i);
00732 warning_message(NETLIST_ERROR, -1, -1, "padding an input port with HB_PAD for node %s\n", node->name);
00733 }
00734 }
00735 }
00736
00737
00738
00739
00740
00741 void hookup_output_pins_from_signal_list(nnode_t *node, int n_start_idx, signal_list_t* output_list, int ol_start_idx, int width)
00742 {
00743 int i;
00744 long sc_spot_output;
00745
00746 for (i = 0; i < width; i++)
00747 {
00748 oassert(output_list->signal_list_size > (ol_start_idx+i));
00749
00750
00751 add_a_output_pin_to_node_spot_idx(node, output_list->signal_list[ol_start_idx+i], n_start_idx+i);
00752
00753 if ((sc_spot_output = sc_lookup_string(output_nets_sc, output_list->signal_list[ol_start_idx+i]->name)) == -1)
00754 {
00755
00756 error_message(NETLIST_ERROR, -1, -1, "Net for driver (%s) doesn't exist for node %s\n", output_list->signal_list[ol_start_idx+i]->name, node->name);
00757 }
00758
00759
00760 add_a_driver_pin_to_net(((nnet_t*)output_nets_sc->data[sc_spot_output]), output_list->signal_list[ol_start_idx+i]);
00761 }
00762 }
00763
00764 void depth_traverse_count(nnode_t *node, int *count, int traverse_mark_number);
00765
00766
00767
00768 int count_nodes_in_netlist(netlist_t *netlist)
00769 {
00770 int i;
00771 int count = 0;
00772
00773
00774 depth_traverse_count(netlist->gnd_node, &count, COUNT_NODES);
00775 depth_traverse_count(netlist->vcc_node, &count, COUNT_NODES);
00776 depth_traverse_count(netlist->pad_node, &count, COUNT_NODES);
00777
00778
00779 for (i = 0; i < netlist->num_top_input_nodes; i++)
00780 {
00781 if (netlist->top_input_nodes[i] != NULL)
00782 {
00783 depth_traverse_count(netlist->top_input_nodes[i], &count, COUNT_NODES);
00784 }
00785 }
00786
00787 return count;
00788 }
00789
00790
00791
00792
00793 void depth_traverse_count(nnode_t *node, int *count, int traverse_mark_number)
00794 {
00795 int i, j;
00796 nnode_t *next_node;
00797 nnet_t *next_net;
00798
00799 if (node->traverse_visited == traverse_mark_number)
00800 {
00801 return;
00802 }
00803 else
00804 {
00805
00806 (*count) ++;
00807
00808
00809 node->traverse_visited = traverse_mark_number;
00810
00811 for (i = 0; i < node->num_output_pins; i++)
00812 {
00813 if (node->output_pins[i]->net == NULL)
00814 continue;
00815
00816 next_net = node->output_pins[i]->net;
00817 for (j = 0; j < next_net->num_fanout_pins; j++)
00818 {
00819 if (next_net->fanout_pins[j] == NULL)
00820 continue;
00821 next_node = next_net->fanout_pins[j]->node;
00822 if (next_node == NULL)
00823 continue;
00824
00825
00826 depth_traverse_count(next_node, count, traverse_mark_number);
00827 }
00828 }
00829 }
00830 }
00831
00832
00833
00834
00835 netlist_t* allocate_netlist()
00836 {
00837 netlist_t *new_netlist;
00838
00839 new_netlist = (netlist_t *)my_malloc_struct(sizeof(netlist_t));
00840
00841 new_netlist->gnd_node = NULL;
00842 new_netlist->vcc_node = NULL;
00843 new_netlist->pad_node = NULL;
00844 new_netlist->zero_net = NULL;
00845 new_netlist->one_net = NULL;
00846 new_netlist->pad_net = NULL;
00847 new_netlist->top_input_nodes = NULL;
00848 new_netlist->num_top_input_nodes = 0;
00849 new_netlist->top_output_nodes = NULL;
00850 new_netlist->num_top_output_nodes = 0;
00851 new_netlist->ff_nodes = NULL;
00852 new_netlist->num_ff_nodes = 0;
00853 new_netlist->internal_nodes = NULL;
00854 new_netlist->num_internal_nodes = 0;
00855 new_netlist->clocks = NULL;
00856 new_netlist->num_clocks = 0;
00857
00858 new_netlist->forward_levels = NULL;
00859 new_netlist->num_forward_levels = 0;
00860 new_netlist->num_at_forward_level = NULL;
00861 new_netlist->backward_levels = NULL;
00862 new_netlist->num_backward_levels = 0;
00863 new_netlist->num_at_backward_level = NULL;
00864 new_netlist->sequential_level_nodes = NULL;
00865 new_netlist->num_sequential_levels = 0;
00866 new_netlist->num_at_sequential_level = NULL;
00867 new_netlist->sequential_level_combinational_termination_node = NULL;
00868 new_netlist->num_sequential_level_combinational_termination_nodes = 0;
00869 new_netlist->num_at_sequential_level_combinational_termination_node = NULL;
00870
00871
00872 new_netlist->nets_sc = sc_new_string_cache();
00873 new_netlist->out_pins_sc = sc_new_string_cache();
00874 new_netlist->nodes_sc = sc_new_string_cache();
00875
00876 new_netlist->stats = NULL;
00877
00878 return new_netlist;
00879 }
00880
00881
00882
00883
00884 void free_netlist(netlist_t *to_free)
00885 {
00886 sc_free_string_cache(to_free->nets_sc);
00887 sc_free_string_cache(to_free->out_pins_sc);
00888 sc_free_string_cache(to_free->nodes_sc);
00889 }
00890
00891
00892
00893
00894 void add_node_to_netlist(netlist_t *netlist, nnode_t *node, short special_node)
00895 {
00896 long sc_spot;
00897
00898
00899 {
00900
00901 sc_spot = sc_add_string(netlist->nodes_sc, node->name);
00902 if (netlist->nodes_sc->data[sc_spot] != NULL)
00903 {
00904 error_message(NETLIST_ERROR, linenum, -1, "Two nodes with the same name (%s)\n", node->name);
00905 }
00906 netlist->nodes_sc->data[sc_spot] = (void*)node;
00907 }
00908
00909 if (special_node == INPUT_NODE)
00910 {
00911
00912
00913 netlist->top_input_nodes = (nnode_t**)realloc(netlist->top_input_nodes, sizeof(nnode_t*)*(netlist->num_top_input_nodes+1));
00914 netlist->top_input_nodes[netlist->num_top_input_nodes] = node;
00915 netlist->num_top_input_nodes++;
00916 }
00917 else if (node->type == INPUT_NODE)
00918 {
00919
00920 netlist->top_input_nodes = (nnode_t**)realloc(netlist->top_input_nodes, sizeof(nnode_t*)*(netlist->num_top_input_nodes+1));
00921 netlist->top_input_nodes[netlist->num_top_input_nodes] = node;
00922 netlist->num_top_input_nodes++;
00923 }
00924 else if (node->type == OUTPUT_NODE)
00925 {
00926 netlist->top_output_nodes = (nnode_t**)realloc(netlist->top_output_nodes, sizeof(nnode_t*)*(netlist->num_top_output_nodes+1));
00927 netlist->top_output_nodes[netlist->num_top_output_nodes] = node;
00928 netlist->num_top_output_nodes++;
00929 }
00930 else if (node->type == FF_NODE)
00931 {
00932 netlist->ff_nodes = (nnode_t**)realloc(netlist->ff_nodes, sizeof(nnode_t*)*(netlist->num_ff_nodes+1));
00933 netlist->ff_nodes[netlist->num_ff_nodes] = node;
00934 netlist->num_ff_nodes++;
00935 }
00936 else
00937 {
00938 netlist->internal_nodes = (nnode_t**)realloc(netlist->internal_nodes, sizeof(nnode_t*)*(netlist->num_internal_nodes+1));
00939 netlist->internal_nodes[netlist->num_internal_nodes] = node;
00940 netlist->num_internal_nodes++;
00941 }
00942 }
00943
00944
00945
00946
00947 void
00948 mark_clock_node (
00949 netlist_t *netlist,
00950 char *clock_name
00951 )
00952 {
00953 long sc_spot;
00954 nnet_t *clock_net;
00955 nnode_t *clock_node;
00956
00957
00958 if ((sc_spot = sc_lookup_string(netlist->nets_sc, clock_name)) == -1)
00959 {
00960 error_message(NETLIST_ERROR, linenum, -1, "clock input does not exist (%s)\n", clock_name);
00961 }
00962 clock_net = (nnet_t*)netlist->nets_sc->data[sc_spot];
00963 clock_node = clock_net->driver_pin->node;
00964
00965 netlist->clocks = (nnode_t**)realloc(netlist->clocks, sizeof(nnode_t*)*(netlist->num_clocks+1));
00966 netlist->clocks[netlist->num_clocks] = clock_node;
00967 netlist->num_clocks++;
00968
00969
00970 clock_node->type = CLOCK_NODE;
00971 }