Skip to content

Commit

Permalink
added a strcmp inside @vtr_util to do NULL check first(undefined in c)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlego committed Jun 5, 2017
1 parent 92ae350 commit b09fd0d
Show file tree
Hide file tree
Showing 26 changed files with 346 additions and 404 deletions.
180 changes: 59 additions & 121 deletions ODIN_II/SRC/adders.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ OTHER DEALINGS IN THE SOFTWARE.
#include "subtractions.h"
#include "print_tags.h"
#include "vtr_memory.h"

#include "vtr_util.h"
#include "vtr_list.h"

using vtr::t_linked_vptr;
Expand Down Expand Up @@ -133,7 +133,7 @@ void find_hard_adders()

while (hard_adders != NULL)
{
if (strcmp(hard_adders->name, "adder") == 0)
if (vtr::strcmp(hard_adders->name, "adder") == 0)
{
init_add_distribution();
return;
Expand Down Expand Up @@ -1034,8 +1034,6 @@ void traverse_list(operation_list oper, t_linked_vptr *place)
*-------------------------------------------------------------------------*/
void match_node(t_linked_vptr *place, operation_list oper)
{
int flag = 0;
int mark = 0;
nnode_t *node = NULL;
nnode_t *next_node = NULL;
node = (nnode_t*)place->data_vptr;
Expand All @@ -1045,29 +1043,15 @@ void match_node(t_linked_vptr *place, operation_list oper)
next = place->next;
while (next != NULL)
{
flag = 0;
mark = 0;
next_node = (nnode_t*)next->data_vptr;
if (node->type == next_node->type)
{
if (node->num_input_pins == next_node->num_input_pins)
{
flag = match_ports(node, next_node, oper);
if (flag == 1)
{
mark = match_pins(node, next_node);
if (mark == 1)
{
merge_nodes(node, next_node);
remove_list_node(pre, next);
}
}
}
}
if (mark == 1)
next = pre->next;
else
{
if (node->num_input_pins == next_node->num_input_pins &&
match_ports(node, next_node, oper) &&
match_pins(node, next_node)
){
merge_nodes(node, next_node);
remove_list_node(pre, next);
next = pre->next;
}else{
pre = next;
next= next->next;
}
Expand All @@ -1078,98 +1062,67 @@ void match_node(t_linked_vptr *place, operation_list oper)
/*---------------------------------------------------------------------------
* (function: match_ports)
*-------------------------------------------------------------------------*/
int match_ports(nnode_t *node, nnode_t *next_node, operation_list oper)
{
int flag = 0;
int sign = 0;
int *mark = &sign;
int mark1 = 1;
int mark2 = 1;
ast_node_t *ast_node, *ast_node_next;
char *component_s[2] = {0};
char *component_o[2] = {0};
ast_node = node->related_ast_node;
ast_node_next = next_node->related_ast_node;
if (ast_node->types.operation.op == oper)
short match_ports(nnode_t *node, nnode_t *next_node, operation_list oper){
char *component_s[2] = { 0 };
char *component_o[2] = { 0 };

if (node->related_ast_node->types.operation.op == oper &&
traverse_operation_node(node->related_ast_node, component_s, oper) &&
traverse_operation_node(next_node->related_ast_node, component_o, oper))
{
traverse_operation_node(ast_node, component_s, oper, mark);
if (sign != 1)
//oassert(component_s[0] && component_o[1] && component_s[1] && component_o[0]);
switch (oper)
{
traverse_operation_node(ast_node_next, component_o, oper, mark);
if (sign != 1)
{
switch (oper)
case ADD:
case MULTIPLY:
if (vtr::strcmp(component_s[0], component_o[1]) == 0 &&
vtr::strcmp(component_s[1], component_o[0]) == 0)
{
case ADD:
case MULTIPLY:
{
mark1 = strcmp(component_s[0], component_o[0]);
if (mark1 == 0)
mark2 = strcmp(component_s[1], component_o[1]);
else
{
assert(component_s[0] && component_o[1] && component_s[1] && component_o[0]);
mark1 = strcmp(component_s[0], component_o[1]);
mark2 = strcmp(component_s[1], component_o[0]);
}
if (mark1 == 0 && mark2 == 0)
flag = 1;
}
break;

case MINUS:
mark1 = strcmp(component_s[0], component_o[0]);
if (mark1 == 0)
mark2 = strcmp(component_s[1], component_s[1]);
if (mark2 == 0)
flag = 1;
break;

default:

break;
return TRUE;
}
}
case MINUS:
if (vtr::strcmp(component_s[0], component_o[0]) == 0 &&
vtr::strcmp(component_s[1], component_o[1]) == 0)
{
return TRUE;
}

default:
break;
}
}

return flag;
return FALSE;
}

/*-------------------------------------------------------------------------
* (function: traverse_operation_node)
*
* search the ast find the couple of components
*-----------------------------------------------------------------------*/
void traverse_operation_node(ast_node_t *node, char *component[], operation_list op, int *mark)
{
short traverse_operation_node(ast_node_t *node, char *component[], operation_list op){
int i;

if (node == NULL)
return;

if (node->types.operation.op == op)
{
for (i = 0; i < node->num_children; i++)
{
*mark = 0;
if (node->children[i]->type != IDENTIFIERS && node->children[i]->type != NUMBERS)
{
*mark = 1;
break;
}
else
{
if (node->children[i]->type == IDENTIFIERS)
component[i] = node->children[i]->types.identifier;
else
if (node->children[i]->type == NUMBERS)
if (node && node->types.operation.op == op){
for (i = 0; i < node->num_children; i++){
if(node->children[i] && node->children[i]->type){
switch (node->children[i]->type){
case IDENTIFIERS:
component[i] = node->children[i]->types.identifier;
break;
case NUMBERS:
component[i] = node->children[i]->types.number.number;
break;
default:
return FALSE;
}
}else{
return FALSE;
}

}
//if it goes through without breaking then it is successfull
return TRUE;
}

return FALSE;
}

/*---------------------------------------------------------------------------
Expand Down Expand Up @@ -1268,31 +1221,16 @@ void free_op_nodes(nnode_t *node)
/*---------------------------------------------------------------------------
* (function: match_pins)
*-------------------------------------------------------------------------*/
int match_pins(nnode_t *node, nnode_t *next_node)
short match_pins(nnode_t *node, nnode_t *next_node)
{
int flag = 0;
int i, j;
long id;
for (i = 0; i < node->num_input_pins; i++)
{
flag = 0;
id = node->input_pins[i]->net->driver_pin->unique_id;
for (j = 0; j < next_node->num_input_pins; j++)
{
if (id == next_node->input_pins[j]->net->driver_pin->unique_id)
{
flag = 1;
break;
}
if (j == next_node->num_input_pins - 1)
{
flag = -1;
break;
for (i = 0; i < node->num_input_pins; i++){
for (j = 0; node->input_pins[i]->net->driver_pin->unique_id
!= next_node->input_pins[j]->net->driver_pin->unique_id; j++){
if (j == next_node->num_input_pins - 1){
return FALSE;
}
}
if (flag == -1)
break;
}

return flag;
return TRUE;
}
6 changes: 3 additions & 3 deletions ODIN_II/SRC/adders.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ extern void clean_adders();
extern void reduce_operations(netlist_t *netlist, operation_list op);
extern void traverse_list(operation_list oper, vtr::t_linked_vptr *place);
extern void match_node(vtr::t_linked_vptr *place, operation_list oper);
extern int match_ports(nnode_t *node, nnode_t *next_node, operation_list oper);
extern void traverse_operation_node(ast_node_t *node, char *component[], operation_list op, int *mark);
extern short match_ports(nnode_t *node, nnode_t *next_node, operation_list oper);
extern short traverse_operation_node(ast_node_t *node, char *component[], operation_list op);
//extern void find_leaf_children(ast_node_t *node, char *component[], operation_list op, int flag, int ids);
extern void merge_nodes(nnode_t *node, nnode_t *next_node);
extern void remove_list_node(vtr::t_linked_vptr *node, vtr::t_linked_vptr *place);
extern void remove_fanout_pins(nnode_t *node);
extern void reallocate_pins(nnode_t *node, nnode_t *next_node);
extern void free_op_nodes(nnode_t *node);
extern int match_pins(nnode_t *node, nnode_t *next_node);
extern short match_pins(nnode_t *node, nnode_t *next_node);

#endif // ADDERS_H

22 changes: 11 additions & 11 deletions ODIN_II/SRC/ast_elaborate.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ void copy_tree(ast_node_t *node, ast_node_t *new_node)
switch (node->type)
{
case IDENTIFIERS:
if(strcmp(node->types.identifier, v_name) == 0)
if(vtr::strcmp(node->types.identifier, v_name) == 0)
{
initial_node(new_node, NUMBERS, node->line_number, node->file_number, ++count_id);
complete_node(node, new_node);
change_to_number_node(new_node, v_value);
change_to_number_node(new_node, v_value, NULL, false);
}
else
{
Expand Down Expand Up @@ -301,7 +301,7 @@ int calculation(char *post_exp[])
for(i = 0; i < Max_size - 1; ++i) {
pop.data[i] = 0;
}
pop.data[Max_size] = -1;
pop.data[Max_size-1] = -1;

for (i = 0; post_exp[i] != NULL; i++)
{
Expand Down Expand Up @@ -449,12 +449,12 @@ void modify_expression(char *exp[], char *infix_exp[], char *value)
i = 0;
k = 0;

while((strcmp(exp[i], "=") != 0) && i < Max_size)
while((vtr::strcmp(exp[i], "=") != 0) && i < Max_size)
i++;

for (j = i + 1; exp[j] != NULL; j++)
{
if (strcmp(exp[j], v_name) == 0)
if (vtr::strcmp(exp[j], v_name) == 0)
infix_exp[k++] = value;

else
Expand Down Expand Up @@ -532,7 +532,7 @@ void mark_node_read(ast_node_t *node, char list[10][20])
if (node->type == IDENTIFIERS)
{
for (i = 0; i < 10; i++)
if (strcmp(node->types.identifier, list[i]) == 0 && node->is_read_write != 2)
if (vtr::strcmp(node->types.identifier, list[i]) == 0 && node->is_read_write != 2)
node->is_read_write = 1;
}

Expand Down Expand Up @@ -600,7 +600,7 @@ void search_marked_node(ast_node_t *node, int is, char *temp, ast_node_t **p2)
{
if (node->children[i]->type == IDENTIFIERS)
{
if( strcmp(node->children[0]->types.identifier, temp) == 0 && node->children[0]->is_read_write == is)
if( vtr::strcmp(node->children[0]->types.identifier, temp) == 0 && node->children[0]->is_read_write == is)
*p2 = node;
}

Expand Down Expand Up @@ -1218,7 +1218,7 @@ void create_ast_node(enode *temp, ast_node_t *node, int line_num, int file_num)
{
case 1:
initial_node(node, NUMBERS, line_num, file_num, ++count_id);
change_to_number_node(node, temp->type.data);
change_to_number_node(node, temp->type.data, NULL, false);
break;

case 2:
Expand Down Expand Up @@ -1730,8 +1730,8 @@ void change_para_node(ast_node_t *node, char *name, long long value)
int i;

if (node){
if (node->type == IDENTIFIERS && strcmp(name, node->types.identifier) == 0)
change_to_number_node(node, value);
if (node->type == IDENTIFIERS && vtr::strcmp(name, node->types.identifier) == 0)
change_to_number_node(node, value, NULL, false);

if (node->num_children != 0){
for (i = 0; i < node->num_children; i++){
Expand Down Expand Up @@ -1813,7 +1813,7 @@ void check_node_number(ast_node_t *parent, ast_node_t *child, int flag)
}
if (number == 1) // the previous number is a power of 2
{
change_to_number_node(child, power);
change_to_number_node(child, power, NULL, false);
if (flag == 1) // multiply
parent->types.operation.op = SL;
else if (flag == 2) // multiply and needs to move children nodes
Expand Down
Loading

0 comments on commit b09fd0d

Please sign in to comment.