Skip to content

Commit 46b4127

Browse files
committed
odin - move remaining resolve_node cases to elaboration phase
1 parent 402f840 commit 46b4127

File tree

4 files changed

+156
-342
lines changed

4 files changed

+156
-342
lines changed

ODIN_II/SRC/ast_elaborate.cpp

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ int simplify_ast_module(ast_node_t **ast_module, STRING_CACHE_LIST *local_string
141141
// this should replace ^^
142142
ast_node_t *reduce_expressions(ast_node_t *node, STRING_CACHE_LIST *local_string_cache_list, long *max_size, long assignment_size)
143143
{
144-
// this will replace resolve_node which occurs all over the place in the code...
145-
146144
if (node)
147145
{
148146
STRING_CACHE *local_param_table_sc = local_string_cache_list->local_param_table_sc;
@@ -173,9 +171,7 @@ ast_node_t *reduce_expressions(ast_node_t *node, STRING_CACHE_LIST *local_string
173171
}
174172

175173
/* resolve right-hand side */
176-
node->children[5] = reduce_expressions(node->children[5], local_string_cache_list, NULL, 0);
177-
node->children[5] = resolve_node(local_string_cache_list, node->children[5], NULL, -1);
178-
174+
node->children[5] = reduce_expressions(node->children[5], local_string_cache_list, NULL, -1);
179175
oassert(node->children[5]->type == NUMBERS);
180176

181177
/* this forces parameter values as unsigned, since we don't currently support signed keyword...
@@ -206,8 +202,6 @@ ast_node_t *reduce_expressions(ast_node_t *node, STRING_CACHE_LIST *local_string
206202
if (newNode->type != NUMBERS)
207203
{
208204
newNode = reduce_expressions(newNode, local_string_cache_list, NULL, assignment_size);
209-
newNode = resolve_node(local_string_cache_list, newNode, NULL, -1);
210-
211205
oassert(newNode->type == NUMBERS);
212206

213207
/* this forces parameter values as unsigned, since we don't currently support signed keyword...
@@ -247,13 +241,21 @@ ast_node_t *reduce_expressions(ast_node_t *node, STRING_CACHE_LIST *local_string
247241
if (node->children[1]->type != FUNCTION_INSTANCE)
248242
{
249243
node->children[0] = reduce_expressions(node->children[0], local_string_cache_list, NULL, 0);
250-
node->children[0] = resolve_node(local_string_cache_list, node->children[0], NULL, 0);
251244

252245
assignment_size = get_size_of_variable(node->children[0], local_string_cache_list);
253246
max_size = (long*)calloc(1, sizeof(long));
254247

255-
node->children[1] = reduce_expressions(node->children[1], local_string_cache_list, max_size, assignment_size);
256-
node->children[1] = resolve_node(local_string_cache_list, node->children[1], max_size, assignment_size);
248+
if (node->children[1]->type != NUMBERS)
249+
{
250+
node->children[1] = reduce_expressions(node->children[1], local_string_cache_list, max_size, assignment_size);
251+
}
252+
else
253+
{
254+
VNumber *temp = node->children[1]->types.vnumber;
255+
node->children[1]->types.vnumber = new VNumber(*temp, assignment_size);
256+
delete temp;
257+
}
258+
257259
vtr::free(max_size);
258260

259261
/* cast to unsigned if necessary */
@@ -403,10 +405,80 @@ ast_node_t *reduce_expressions(ast_node_t *node, STRING_CACHE_LIST *local_string
403405
}
404406
break;
405407
}
406-
case CONCATENATE:
407-
break;
408408
case REPLICATE:
409+
{
410+
oassert(node_is_constant(node->children[0])); // should be taken care of in parse
411+
if( node->children[0]->types.vnumber->is_dont_care_string() )
412+
{
413+
error_message(NETLIST_ERROR, node->line_number, node->file_number,
414+
"%s","Passing a non constant value to replication command, i.e. 2'bx1{...}");
415+
}
416+
417+
int64_t value = node->children[0]->types.vnumber->get_value();
418+
if(value <= 0)
419+
{
420+
// todo, if this is part of a concat, it is valid
421+
error_message(NETLIST_ERROR, node->line_number, node->file_number,
422+
"%s","Passing a number less than or equal to 0 for replication");
423+
}
424+
425+
ast_node_t *new_node = create_node_w_type(CONCATENATE, node->line_number, node->file_number);
426+
for (size_t i = 0; i < value; i++)
427+
{
428+
add_child_to_node(new_node, ast_node_deep_copy(node->children[1]));
429+
}
430+
node = free_whole_tree(node);
431+
node = new_node;
432+
}
433+
//fallthrough
434+
case CONCATENATE:
435+
{
436+
resolve_concat_sizes(node, local_string_cache_list);
437+
438+
// for params only
439+
// TODO: this is a hack, concats cannot be folded in place as it breaks netlist expand from ast,
440+
// to fix we need to move the node resolution before netlist create from ast.
441+
if(assignment_size == -1 && node->num_children > 0)
442+
{
443+
size_t index = 1;
444+
size_t last_index = 0;
445+
446+
while(index < node->num_children)
447+
{
448+
bool previous_is_constant = node_is_constant(node->children[last_index]);
449+
bool current_is_constant = node_is_constant(node->children[index]);
450+
451+
if(previous_is_constant && current_is_constant)
452+
{
453+
VNumber new_value = V_CONCAT({*(node->children[last_index]->types.vnumber), *(node->children[index]->types.vnumber)});
454+
455+
node->children[index] = free_whole_tree(node->children[index]);
456+
457+
delete node->children[last_index]->types.vnumber;
458+
node->children[last_index]->types.vnumber = new VNumber(new_value);
459+
}
460+
else
461+
{
462+
last_index += 1;
463+
previous_is_constant = current_is_constant;
464+
node->children[last_index] = node->children[index];
465+
}
466+
index += 1;
467+
}
468+
469+
node->num_children = last_index+1;
470+
471+
if(node->num_children == 1)
472+
{
473+
ast_node_t *tmp = node->children[0];
474+
node->children[0] = NULL;
475+
free_whole_tree(node);
476+
node = tmp;
477+
}
478+
}
479+
409480
break;
481+
}
410482
case IDENTIFIERS:
411483
{
412484
// look up to resolve unresolved range refs
@@ -450,10 +522,14 @@ ast_node_t *reduce_expressions(ast_node_t *node, STRING_CACHE_LIST *local_string
450522
}
451523
case NUMBERS:
452524
{
453-
if (max_size && node->types.vnumber->size() > (*max_size))
525+
if (max_size)
454526
{
455-
*max_size = node->types.vnumber->size();
527+
if (node->types.vnumber->size() > (*max_size))
528+
{
529+
*max_size = node->types.vnumber->size();
530+
}
456531
}
532+
457533
break;
458534
}
459535
case IF_Q:

0 commit comments

Comments
 (0)