Skip to content

Commit 771be2c

Browse files
authored
Merge pull request verilog-to-routing#933 from j-b-1-7/odin_basic_task_support
ODIN_II: Add basic task support
2 parents 574bc4f + c6422ed commit 771be2c

24 files changed

+1610
-476
lines changed

ODIN_II/SRC/ast_elaborate.cpp

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ ast_node_t *build_hierarchy(ast_node_t *node, ast_node_t * parent, int index, sc
682682
fold_expressions = true;
683683
break;
684684
}
685+
case TASK: //fallthrough
686+
case STATEMENT: //fallthough
685687
case FUNCTION: // fallthrough
686688
case INITIAL: // fallthrough
687689
case ALWAYS:
@@ -863,6 +865,59 @@ ast_node_t *build_hierarchy(ast_node_t *node, ast_node_t * parent, int index, sc
863865
vtr::free(temp_instance_name);
864866
}
865867

868+
for (i = 0; i < node->types.task.size_task_instantiations; i++)
869+
{
870+
871+
/* make the stringed up module instance name - instance name is
872+
* MODULE_INSTANCE->MODULE_NAMED_INSTANCE(child[1])->IDENTIFIER(child[0]).
873+
* module name is MODULE_INSTANCE->IDENTIFIER(child[0])
874+
*/
875+
ast_node_t *temp_instance = node->types.task.task_instantiations_instance[i];
876+
char *instance_name_prefix = local_ref->instance_name_prefix;
877+
878+
char *temp_instance_name = make_full_ref_name(instance_name_prefix,
879+
temp_instance->children[0]->types.identifier,
880+
temp_instance->children[1]->children[0]->types.identifier,
881+
NULL, -1);
882+
883+
long sc_spot;
884+
/* lookup the name of the task associated with this instantiated point */
885+
if ((sc_spot = sc_lookup_string(module_names_to_idx, temp_instance->children[0]->types.identifier)) == -1)
886+
{
887+
error_message(NETLIST_ERROR, node->line_number, node->file_number,
888+
"Can't find task name %s\n", temp_instance->children[0]->types.identifier);
889+
}
890+
891+
/* make a unique copy of this task */
892+
ast_node_t *instance = ast_node_deep_copy((ast_node_t *)module_names_to_idx->data[sc_spot]);
893+
894+
long sc_spot_2 = sc_add_string(module_names_to_idx, temp_instance_name);
895+
oassert(sc_spot_2 > -1 && module_names_to_idx->data[sc_spot_2] == NULL);
896+
module_names_to_idx->data[sc_spot_2] = (void *)instance;
897+
898+
ast_modules = (ast_node_t **)vtr::realloc(ast_modules, sizeof(ast_node_t*)*(sc_spot_2 + 1));
899+
ast_modules[sc_spot_2] = instance;
900+
901+
/* create the string cache list for the instantiated module */
902+
sc_hierarchy *original_sc_hierarchy = ((ast_node_t *)module_names_to_idx->data[sc_spot])->types.hierarchy;
903+
sc_hierarchy *task_sc_hierarchy = copy_sc_hierarchy(original_sc_hierarchy);
904+
task_sc_hierarchy->parent = local_ref;
905+
task_sc_hierarchy->instance_name_prefix = vtr::strdup(temp_instance_name);
906+
task_sc_hierarchy->scope_id = vtr::strdup(temp_instance->children[1]->children[0]->types.identifier);
907+
908+
/* update parent string cache list */
909+
int num_task_children = local_ref->num_task_children;
910+
local_ref->task_children = (sc_hierarchy **)vtr::realloc(local_ref->task_children, sizeof(sc_hierarchy *)*(num_task_children + 1));
911+
local_ref->task_children[i] = task_sc_hierarchy;
912+
local_ref->num_task_children++;
913+
914+
/* elaboration */
915+
instance = build_hierarchy(instance, NULL, -1, task_sc_hierarchy, false, true, data);
916+
917+
/* clean up */
918+
vtr::free(temp_instance_name);
919+
}
920+
866921
break;
867922
}
868923
case MODULE_INSTANCE:
@@ -1098,6 +1153,8 @@ ast_node_t *build_hierarchy(ast_node_t *node, ast_node_t * parent, int index, sc
10981153

10991154
break;
11001155
}
1156+
case STATEMENT: //fallthrough
1157+
case TASK: //fallthrough
11011158
case FUNCTION: // fallthrough
11021159
case INITIAL: // fallthrough
11031160
case ALWAYS:
@@ -1192,6 +1249,44 @@ ast_node_t *finalize_ast(ast_node_t *node, ast_node_t *parent, sc_hierarchy *loc
11921249

11931250
break;
11941251
}
1252+
case TASK:
1253+
{
1254+
if(parent != NULL)
1255+
{
1256+
skip_children = true;
1257+
}
1258+
break;
1259+
}
1260+
case TASK_INSTANCE:
1261+
{
1262+
// check ports
1263+
ast_node_t *connect_list = node->children[1]->children[1];
1264+
bool is_ordered_list;
1265+
if (connect_list->children[1]->children[0]) // skip first connection
1266+
{
1267+
is_ordered_list = false; // name was specified
1268+
}
1269+
else
1270+
{
1271+
is_ordered_list = true;
1272+
}
1273+
1274+
for (int i = 1; i < connect_list->num_children; i++)
1275+
{
1276+
if ((connect_list->children[i]
1277+
&& connect_list->children[i]->children)
1278+
&& (( connect_list->children[i]->children[0] && is_ordered_list)
1279+
|| (!connect_list->children[i]->children[0] && !is_ordered_list)))
1280+
{
1281+
error_message(PARSE_ERROR, node->line_number, node->file_number,
1282+
"%s", "Cannot mix port connections by name and port connections by ordered list\n");
1283+
}
1284+
}
1285+
1286+
skip_children = true;
1287+
1288+
break;
1289+
}
11951290
case MODULE_ITEMS:
11961291
{
11971292
/* look in the string cache for in-line continuous assignments */
@@ -1299,6 +1394,7 @@ ast_node_t *finalize_ast(ast_node_t *node, ast_node_t *parent, sc_hierarchy *loc
12991394
node = unroll_for_loop(node, parent, &num_unrolled, local_ref, is_generate_region);
13001395
break;
13011396
}
1397+
case STATEMENT: //fallthrough
13021398
case ALWAYS: // fallthrough
13031399
case INITIAL:
13041400
{
@@ -1547,6 +1643,40 @@ ast_node_t *finalize_ast(ast_node_t *node, ast_node_t *parent, sc_hierarchy *loc
15471643
vtr::free(temp_instance_name);
15481644
}
15491645

1646+
for (i = 0; i < node->types.task.size_task_instantiations; i++)
1647+
{
1648+
1649+
/* make the stringed up module instance name - instance name is
1650+
* MODULE_INSTANCE->MODULE_NAMED_INSTANCE(child[1])->IDENTIFIER(child[0]).
1651+
* module name is MODULE_INSTANCE->IDENTIFIER(child[0])
1652+
*/
1653+
ast_node_t *temp_instance = node->types.task.task_instantiations_instance[i];
1654+
char *instance_name_prefix = local_ref->instance_name_prefix;
1655+
1656+
char *temp_instance_name = make_full_ref_name(instance_name_prefix,
1657+
temp_instance->children[0]->types.identifier,
1658+
temp_instance->children[1]->children[0]->types.identifier,
1659+
NULL, -1);
1660+
1661+
/* lookup the name of the task associated with this instantiated point */
1662+
long sc_spot = sc_lookup_string(module_names_to_idx, temp_instance->children[0]->types.identifier);
1663+
oassert(sc_spot > -1 && module_names_to_idx->data[sc_spot] != NULL);
1664+
ast_node_t *instance = (ast_node_t *)module_names_to_idx->data[sc_spot];
1665+
1666+
sc_hierarchy *task_sc_hierarchy = local_ref->task_children[i];
1667+
1668+
/* update the parameter table for the instantiated module */
1669+
STRING_CACHE *instance_param_table_sc = task_sc_hierarchy->local_param_table_sc;
1670+
update_instance_parameter_table(temp_instance, instance_param_table_sc);
1671+
1672+
/* elaboration */
1673+
update_string_caches(task_sc_hierarchy);
1674+
instance = finalize_ast(instance, NULL, task_sc_hierarchy, false, true);
1675+
1676+
/* clean up */
1677+
vtr::free(temp_instance_name);
1678+
}
1679+
15501680
break;
15511681
}
15521682
case MODULE_INSTANCE:
@@ -1777,6 +1907,7 @@ ast_node_t *finalize_ast(ast_node_t *node, ast_node_t *parent, sc_hierarchy *loc
17771907
if (node->num_children == 3) convert_2D_to_1D_array_ref(&node, local_ref);
17781908
break;
17791909
}
1910+
case STATEMENT: //fallthrough
17801911
case ALWAYS: // fallthrough
17811912
case INITIAL:
17821913
{
@@ -1834,6 +1965,11 @@ ast_node_t *reduce_expressions(ast_node_t *node, sc_hierarchy *local_ref, long *
18341965
skip_children = true;
18351966
break;
18361967
}
1968+
case TASK:
1969+
{
1970+
skip_children = true;
1971+
break;
1972+
}
18371973
case MODULE_INSTANCE:
18381974
{
18391975
skip_children = true;

ODIN_II/SRC/ast_util.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ char **get_name_of_pins_number(ast_node_t *var_node, int /*start*/, int width)
659659

660660
return_string = (char**)vtr::malloc(sizeof(char*)*width);
661661
int i;
662-
for (i = 0; i < width; i++)//
662+
for (i = 0; i < width; i++)
663663
{
664664
return_string[i] = get_name_of_pin_number(var_node, i);
665665
}
@@ -680,6 +680,7 @@ char *get_name_of_pin_number(ast_node_t *var_node, int bit)
680680
case BitSpace::_1: return_string = vtr::strdup(ONE_VCC_CNS); break;
681681
case BitSpace::_0: return_string = vtr::strdup(ZERO_GND_ZERO); break;
682682
case BitSpace::_x: return_string = vtr::strdup(ZERO_GND_ZERO); break;
683+
case BitSpace::_z: return_string = vtr::strdup(ZERO_PAD_ZERO); break;
683684
default:
684685
error_message(NETLIST_ERROR, var_node->line_number, var_node->file_number, "Unrecognised character %c in binary string \"%s\"!\n", c, var_node->types.vnumber->to_bit_string().c_str());
685686
break;

ODIN_II/SRC/enum_str.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ const char *ids_STR []=
124124
"FUNCTION",
125125
/* OTHER FUNCTION ITEMS */
126126
"FUNCTION_ITEMS",
127+
"TASK",
128+
"TASK_ITEMS",
127129
/* primitives */
128130
"GATE",
129131
"GATE_INSTANCE",
@@ -140,12 +142,16 @@ const char *ids_STR []=
140142
/* Function instances*/
141143
"FUNCTION_NAMED_INSTANCE",
142144
"FUNCTION_INSTANCE",
145+
146+
"TASK_NAMED_INSTANCE",
147+
"TASK_INSTANCE",
143148
/* Specify Items */
144149
"SPECIFY_ITEMS",
145150
"SPECIFY_PARAMETER",
146151
"SPECIFY_PAL_CONNECTION_STATEMENT",
147152
"SPECIFY_PAL_CONNECT_LIST",
148153
/* statements */
154+
"STATEMENT",
149155
"BLOCK",
150156
"NON_BLOCKING_STATEMENT",
151157
"BLOCKING_STATEMENT",

ODIN_II/SRC/hierarchy_util.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ void free_sc_hierarchy(sc_hierarchy *to_free)
108108
}
109109
to_free->function_children = (sc_hierarchy **)vtr::free(to_free->function_children);
110110

111+
for (i = 0; i < to_free->num_task_children; i++)
112+
{
113+
free_sc_hierarchy(to_free->task_children[i]);
114+
}
115+
to_free->task_children = (sc_hierarchy **)vtr::free(to_free->task_children);
116+
111117
for (i = 0; i < to_free->num_block_children; i++)
112118
{
113119
free_sc_hierarchy(to_free->block_children[i]);
@@ -138,6 +144,7 @@ void free_sc_hierarchy(sc_hierarchy *to_free)
138144

139145
to_free->num_module_children = 0;
140146
to_free->num_function_children = 0;
147+
to_free->num_task_children = 0;
141148
to_free->num_unnamed_genblks = 0;
142149

143150
vtr::free(to_free);
@@ -195,6 +202,14 @@ ast_node_t *resolve_hierarchical_name_reference(sc_hierarchy *local_ref, char *i
195202
found = true;
196203
}
197204
}
205+
for (int i = 0; !found && i < this_ref->num_task_children; i++)
206+
{
207+
if (this_ref->task_children[i]->scope_id == scope_id)
208+
{
209+
this_ref = this_ref->task_children[i];
210+
found = true;
211+
}
212+
}
198213
for (int i = 0; !found && i < this_ref->num_block_children; i++)
199214
{
200215
if (this_ref->block_children[i]->scope_id == scope_id)
@@ -285,6 +300,14 @@ ast_node_t *resolve_hierarchical_name_reference_by_path_search(sc_hierarchy *loc
285300
}
286301
}
287302

303+
for (int i = 0; !var_declare && i < local_ref->num_task_children; i++)
304+
{
305+
if (local_ref->task_children[i]->scope_id == scope_id)
306+
{
307+
var_declare = resolve_hierarchical_name_reference_by_path_search(local_ref->task_children[i], identifier);
308+
}
309+
}
310+
288311
for (int i = 0; !var_declare && i < local_ref->num_block_children; i++)
289312
{
290313
if (local_ref->block_children[i]->scope_id == scope_id)

ODIN_II/SRC/include/odin_types.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ enum ids
272272
FUNCTION,
273273
/* OTHER FUNCTION ITEMS */
274274
FUNCTION_ITEMS,
275+
TASK,
276+
TASK_ITEMS,
275277
/* primitives */
276278
GATE,
277279
GATE_INSTANCE,
@@ -288,12 +290,16 @@ enum ids
288290
/* Function instances*/
289291
FUNCTION_NAMED_INSTANCE,
290292
FUNCTION_INSTANCE,
293+
294+
TASK_NAMED_INSTANCE,
295+
TASK_INSTANCE,
291296
/* Specify Items */
292297
SPECIFY_ITEMS,
293298
SPECIFY_PARAMETER,
294299
SPECIFY_PAL_CONNECTION_STATEMENT,
295300
SPECIFY_PAL_CONNECT_LIST,
296301
/* statements */
302+
STATEMENT,
297303
BLOCK,
298304
NON_BLOCKING_STATEMENT,
299305
BLOCKING_STATEMENT,
@@ -378,6 +384,15 @@ struct typ
378384
STRING_CACHE *parameter_list;
379385
} function;
380386
struct
387+
{
388+
short is_instantiated;
389+
ast_node_t **task_instantiations_instance;
390+
int size_task_instantiations;
391+
int index;
392+
STRING_CACHE *parameter_list;
393+
sc_hierarchy *string_cache_list;
394+
}task;
395+
struct
381396
{
382397
int num_bit_strings;
383398
char **bit_strings;

ODIN_II/SRC/include/parse_making_ast.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,16 @@ ast_node_t *newIf(ast_node_t *compare_expression, ast_node_t *true_expression, a
5252
ast_node_t *newIfQuestion(ast_node_t *compare_expression, ast_node_t *true_expression, ast_node_t *false_expression, int line_number);
5353
ast_node_t *newCase(ast_node_t *compare_expression, ast_node_t *case_list, int line_number);
5454
ast_node_t *newAlways(ast_node_t *delay_control, ast_node_t *statements, int line_number);
55+
ast_node_t *newStatement(ast_node_t *statement, int line_number);
5556
ast_node_t *newFor(ast_node_t *initial, ast_node_t *compare_expression, ast_node_t *terminal, ast_node_t *statement, int line_number);
5657
ast_node_t *newWhile(ast_node_t *compare_expression, ast_node_t *statement, int line_number);
5758

5859
/* MODULE INSTANCES FUNCTIONS */
5960
ast_node_t *newModuleConnection(char* id, ast_node_t *expression, int line_number);
6061
ast_node_t *newModuleNamedInstance(char* unique_name, ast_node_t *module_connect_list, ast_node_t *module_parameter_list, int line_number);
6162
ast_node_t *newFunctionNamedInstance(ast_node_t *module_connect_list, ast_node_t *module_parameter_list, int line_number);
63+
ast_node_t *newTaskInstance(char *task_name, ast_node_t *task_named_instace, ast_node_t *task_parameter_list, int line_number);
64+
ast_node_t *newTaskNamedInstance(ast_node_t *module_connect_list, int line_number);
6265
ast_node_t *newModuleInstance(char* module_ref_name, ast_node_t *module_named_instance, int line_number);
6366
ast_node_t *newFunctionInstance(char* function_ref_name, ast_node_t *function_named_instance, int line_number);
6467
ast_node_t *newHardBlockInstance(char* module_ref_name, ast_node_t *module_named_instance, int line_number);
@@ -82,9 +85,11 @@ ast_node_t *newIntegerTypeVarDeclare(char* symbol, ast_node_t *expression1, ast_
8285

8386
/* HIGH LEVEL ITEMS */
8487
ast_node_t *newModule(char* module_name, ast_node_t *list_of_parameters, ast_node_t *list_of_ports, ast_node_t *list_of_module_items, int line_number);
85-
ast_node_t *newFunction(ast_node_t *list_of_ports, ast_node_t *list_of_module_items, int line_number);
88+
ast_node_t *newFunction(ast_node_t *function_return, ast_node_t *list_of_ports, ast_node_t *list_of_module_items, int line_number, bool automatic);
89+
ast_node_t *newTask(char *task_name, ast_node_t *list_of_ports, ast_node_t *list_of_task_items, int line_number, bool automatic);
8690
void next_module();
8791
void next_function();
92+
void next_task();
8893
ast_node_t *newDefparam(ids id, ast_node_t *val, int line_number);
8994

9095
void next_parsed_verilog_file(ast_node_t *file_items_list);

0 commit comments

Comments
 (0)