@@ -26,6 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
26
26
#include < string.h>
27
27
#include < algorithm>
28
28
#include < cmath>
29
+ #include < string>
29
30
#include " odin_types.h"
30
31
#include " node_creation_library.h"
31
32
#include " multipliers.h"
@@ -38,6 +39,7 @@ OTHER DEALINGS IN THE SOFTWARE.
38
39
39
40
#include " vtr_memory.h"
40
41
#include " vtr_list.h"
42
+ #include " vtr_util.h"
41
43
42
44
43
45
using vtr::t_linked_vptr;
@@ -395,39 +397,55 @@ void declare_hard_multiplier(nnode_t *node)
395
397
*-------------------------------------------------------------------------*/
396
398
void instantiate_hard_multiplier (nnode_t *node, short mark, netlist_t * /* netlist*/ )
397
399
{
398
- char *new_name;
399
- int len, sanity, i ;
400
+ oassert (node
401
+ && " node is NULL to instanciate hard multiplier " ) ;
400
402
401
403
declare_hard_multiplier (node);
402
404
403
- /* Need to give node proper name */
404
- len = strlen (node->name );
405
- len = len + 20 ; /* 20 chars should hold mul specs */
406
- new_name = (char *)vtr::malloc (len);
405
+ std::string node_name = " " ;
406
+ if ( node->name )
407
+ {
408
+ node_name = node->name ;
409
+ vtr::free (node->name );
410
+ node->name = NULL ;
411
+ }
407
412
408
- /* wide input first :) */
409
- if (node->input_port_sizes [0 ] > node->input_port_sizes [1 ])
410
- sanity = odin_sprintf (new_name, " %s_%d_%d_%d" , node->name , node->input_port_sizes [0 ], node->input_port_sizes [1 ], node->output_port_sizes [0 ]);
413
+ if (node->num_output_pins <= 0 )
414
+ {
415
+ /* wide input first :) */
416
+ int portA = 0 ;
417
+ int portB = 1 ;
418
+ if (node->input_port_sizes [1 ] > node->input_port_sizes [0 ])
419
+ {
420
+ portA = 1 ;
421
+ portB = 0 ;
422
+ }
423
+ std::string tmp (
424
+ node_name +
425
+ " _" + std::to_string (node->input_port_sizes [portA]) +
426
+ " _" + std::to_string (node->input_port_sizes [portB]) +
427
+ " _" + std::to_string (node->output_port_sizes [0 ])
428
+ );
429
+ node->name = vtr::strdup (tmp.c_str ());
430
+ }
411
431
else
412
- sanity = odin_sprintf (new_name, " %s_%d_%d_%d" , node->name , node->input_port_sizes [1 ], node->input_port_sizes [0 ], node->output_port_sizes [0 ]);
413
-
414
- if (len <= sanity) /* buffer not large enough */
415
- oassert (FALSE );
416
-
417
- /* Give names to the output pins */
418
- for (i = 0 ; i < node->num_output_pins ; i++)
419
432
{
420
- if (node->output_pins [i]->name )
433
+ /* Give names to the output pins */
434
+ for (int i = 0 ; i < node->num_output_pins ; i++)
421
435
{
422
- vtr::free (node->output_pins [i]->name );
436
+ if (node->output_pins [i]->name )
437
+ {
438
+ vtr::free (node->output_pins [i]->name );
439
+ }
440
+ // build the output string
441
+ std::string tmp (
442
+ node_name +
443
+ " [" + std::to_string (node->output_pins [i]->pin_node_idx ) + " ]"
444
+ );
445
+ node->output_pins [i]->name = vtr::strdup (tmp.c_str ());
423
446
}
424
- len = strlen (node->name ) + 6 ; /* 6 chars for pin idx */
425
- new_name = (char *)vtr::malloc (len);
426
- odin_sprintf (new_name, " %s[%d]" , node->name , node->output_pins [i]->pin_node_idx );
427
- node->output_pins [i]->name = new_name;
447
+ node->name = vtr::strdup (node->output_pins [node->num_output_pins -1 ]->name );
428
448
}
429
- vtr::free (node->name );
430
- node->name = new_name;
431
449
node->traverse_visited = mark;
432
450
return ;
433
451
}
0 commit comments