Skip to content

Commit 94414eb

Browse files
committed
ODIN_II: Add basic task support, update functions
1 parent 8550378 commit 94414eb

21 files changed

+1629
-304
lines changed

ODIN_II/SRC/ast_elaborate.cpp

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,8 @@ ast_node_t *build_hierarchy(ast_node_t *node, ast_node_t * parent, int index, sc
611611
fold_expressions = true;
612612
break;
613613
}
614+
case TASK: //fallthrough
615+
case STATEMENT: //fallthough
614616
case FUNCTION: // fallthrough
615617
case INITIAL: // fallthrough
616618
case ALWAYS:
@@ -831,6 +833,59 @@ ast_node_t *build_hierarchy(ast_node_t *node, ast_node_t * parent, int index, sc
831833
vtr::free(temp_instance_name);
832834
}
833835

836+
for (i = 0; i < node->types.task.size_task_instantiations; i++)
837+
{
838+
839+
/* make the stringed up module instance name - instance name is
840+
* MODULE_INSTANCE->MODULE_NAMED_INSTANCE(child[1])->IDENTIFIER(child[0]).
841+
* module name is MODULE_INSTANCE->IDENTIFIER(child[0])
842+
*/
843+
ast_node_t *temp_instance = node->types.task.task_instantiations_instance[i];
844+
char *instance_name_prefix = local_ref->instance_name_prefix;
845+
846+
char *temp_instance_name = make_full_ref_name(instance_name_prefix,
847+
temp_instance->children[0]->types.identifier,
848+
temp_instance->children[1]->children[0]->types.identifier,
849+
NULL, -1);
850+
851+
long sc_spot;
852+
/* lookup the name of the task associated with this instantiated point */
853+
if ((sc_spot = sc_lookup_string(module_names_to_idx, temp_instance->children[0]->types.identifier)) == -1)
854+
{
855+
error_message(NETLIST_ERROR, node->line_number, node->file_number,
856+
"Can't find task name %s\n", temp_instance->children[0]->types.identifier);
857+
}
858+
859+
/* make a unique copy of this task */
860+
ast_node_t *instance = ast_node_deep_copy((ast_node_t *)module_names_to_idx->data[sc_spot]);
861+
862+
long sc_spot_2 = sc_add_string(module_names_to_idx, temp_instance_name);
863+
oassert(sc_spot_2 > -1 && module_names_to_idx->data[sc_spot_2] == NULL);
864+
module_names_to_idx->data[sc_spot_2] = (void *)instance;
865+
866+
ast_modules = (ast_node_t **)vtr::realloc(ast_modules, sizeof(ast_node_t*)*(sc_spot_2 + 1));
867+
ast_modules[sc_spot_2] = instance;
868+
869+
/* create the string cache list for the instantiated module */
870+
sc_hierarchy *original_sc_hierarchy = ((ast_node_t *)module_names_to_idx->data[sc_spot])->types.task.string_cache_list;
871+
sc_hierarchy *task_sc_hierarchy = copy_sc_hierarchy(original_sc_hierarchy);
872+
task_sc_hierarchy->parent = local_ref;
873+
task_sc_hierarchy->instance_name_prefix = vtr::strdup(temp_instance_name);
874+
task_sc_hierarchy->scope_id = vtr::strdup(temp_instance->children[1]->children[0]->types.identifier);
875+
876+
/* update parent string cache list */
877+
int num_task_children = local_ref->num_task_children;
878+
local_ref->task_children = (sc_hierarchy **)vtr::realloc(local_ref->task_children, sizeof(sc_hierarchy *)*(num_task_children + 1));
879+
local_ref->task_children[i] = task_sc_hierarchy;
880+
local_ref->num_task_children++;
881+
882+
/* elaboration */
883+
instance = build_hierarchy(instance, NULL, -1, task_sc_hierarchy, false, true, data);
884+
885+
/* clean up */
886+
vtr::free(temp_instance_name);
887+
}
888+
834889
break;
835890
}
836891
case MODULE_INSTANCE:
@@ -1009,6 +1064,8 @@ ast_node_t *build_hierarchy(ast_node_t *node, ast_node_t * parent, int index, sc
10091064

10101065
break;
10111066
}
1067+
case STATEMENT: //fallthrough
1068+
case TASK: //fallthrough
10121069
case FUNCTION: // fallthrough
10131070
case INITIAL: // fallthrough
10141071
case ALWAYS:
@@ -1103,6 +1160,44 @@ ast_node_t *finalize_ast(ast_node_t *node, ast_node_t *parent, sc_hierarchy *loc
11031160

11041161
break;
11051162
}
1163+
case TASK:
1164+
{
1165+
if(parent != NULL)
1166+
{
1167+
skip_children = true;
1168+
}
1169+
break;
1170+
}
1171+
case TASK_INSTANCE:
1172+
{
1173+
// check ports
1174+
ast_node_t *connect_list = node->children[1]->children[1];
1175+
bool is_ordered_list;
1176+
if (connect_list->children[1]->children[0]) // skip first connection
1177+
{
1178+
is_ordered_list = false; // name was specified
1179+
}
1180+
else
1181+
{
1182+
is_ordered_list = true;
1183+
}
1184+
1185+
for (int i = 1; i < connect_list->num_children; i++)
1186+
{
1187+
if ((connect_list->children[i]
1188+
&& connect_list->children[i]->children)
1189+
&& (( connect_list->children[i]->children[0] && is_ordered_list)
1190+
|| (!connect_list->children[i]->children[0] && !is_ordered_list)))
1191+
{
1192+
error_message(PARSE_ERROR, node->line_number, node->file_number,
1193+
"%s", "Cannot mix port connections by name and port connections by ordered list\n");
1194+
}
1195+
}
1196+
1197+
skip_children = true;
1198+
1199+
break;
1200+
}
11061201
case MODULE_ITEMS:
11071202
{
11081203
/* look in the string cache for in-line continuous assignments */
@@ -1322,6 +1417,7 @@ ast_node_t *finalize_ast(ast_node_t *node, ast_node_t *parent, sc_hierarchy *loc
13221417

13231418
break;
13241419
}
1420+
case STATEMENT: //fallthrough
13251421
case ALWAYS: // fallthrough
13261422
case INITIAL:
13271423
{
@@ -1556,6 +1652,40 @@ ast_node_t *finalize_ast(ast_node_t *node, ast_node_t *parent, sc_hierarchy *loc
15561652
vtr::free(temp_instance_name);
15571653
}
15581654

1655+
for (i = 0; i < node->types.task.size_task_instantiations; i++)
1656+
{
1657+
1658+
/* make the stringed up module instance name - instance name is
1659+
* MODULE_INSTANCE->MODULE_NAMED_INSTANCE(child[1])->IDENTIFIER(child[0]).
1660+
* module name is MODULE_INSTANCE->IDENTIFIER(child[0])
1661+
*/
1662+
ast_node_t *temp_instance = node->types.task.task_instantiations_instance[i];
1663+
char *instance_name_prefix = local_ref->instance_name_prefix;
1664+
1665+
char *temp_instance_name = make_full_ref_name(instance_name_prefix,
1666+
temp_instance->children[0]->types.identifier,
1667+
temp_instance->children[1]->children[0]->types.identifier,
1668+
NULL, -1);
1669+
1670+
/* lookup the name of the task associated with this instantiated point */
1671+
long sc_spot = sc_lookup_string(module_names_to_idx, temp_instance->children[0]->types.identifier);
1672+
oassert(sc_spot > -1 && module_names_to_idx->data[sc_spot] != NULL);
1673+
ast_node_t *instance = (ast_node_t *)module_names_to_idx->data[sc_spot];
1674+
1675+
sc_hierarchy *task_sc_hierarchy = local_ref->task_children[i];
1676+
1677+
/* update the parameter table for the instantiated module */
1678+
STRING_CACHE *instance_param_table_sc = task_sc_hierarchy->local_param_table_sc;
1679+
update_instance_parameter_table(temp_instance, instance_param_table_sc);
1680+
1681+
/* elaboration */
1682+
update_string_caches(task_sc_hierarchy);
1683+
instance = finalize_ast(instance, NULL, task_sc_hierarchy, false, true, data);
1684+
1685+
/* clean up */
1686+
vtr::free(temp_instance_name);
1687+
}
1688+
15591689
break;
15601690
}
15611691
case MODULE_INSTANCE:
@@ -1779,6 +1909,7 @@ ast_node_t *finalize_ast(ast_node_t *node, ast_node_t *parent, sc_hierarchy *loc
17791909
if (node->num_children == 3) convert_2D_to_1D_array_ref(&node, local_ref);
17801910
break;
17811911
}
1912+
case STATEMENT: //fallthrough
17821913
case ALWAYS: // fallthrough
17831914
case INITIAL:
17841915
{
@@ -1836,6 +1967,11 @@ ast_node_t *reduce_expressions(ast_node_t *node, sc_hierarchy *local_ref, long *
18361967
skip_children = true;
18371968
break;
18381969
}
1970+
case TASK:
1971+
{
1972+
skip_children = true;
1973+
break;
1974+
}
18391975
case MODULE_INSTANCE:
18401976
{
18411977
skip_children = true;

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
@@ -103,6 +103,12 @@ void free_sc_hierarchy(sc_hierarchy *to_free)
103103
}
104104
to_free->function_children = (sc_hierarchy **)vtr::free(to_free->function_children);
105105

106+
for (i = 0; i < to_free->num_task_children; i++)
107+
{
108+
free_sc_hierarchy(to_free->task_children[i]);
109+
}
110+
to_free->task_children = (sc_hierarchy **)vtr::free(to_free->task_children);
111+
106112
if (to_free->local_param_table_sc)
107113
{
108114
for(i = 0; i < to_free->local_param_table_sc->free; i++)
@@ -125,6 +131,7 @@ void free_sc_hierarchy(sc_hierarchy *to_free)
125131

126132
to_free->num_module_children = 0;
127133
to_free->num_function_children = 0;
134+
to_free->num_task_children = 0;
128135

129136
vtr::free(to_free);
130137
}
@@ -181,6 +188,14 @@ ast_node_t *resolve_hierarchical_name_reference(sc_hierarchy *local_ref, char *i
181188
found = true;
182189
}
183190
}
191+
for (int i = 0; !found && i < this_ref->num_task_children; i++)
192+
{
193+
if (this_ref->task_children[i]->scope_id == scope_id)
194+
{
195+
this_ref = this_ref->task_children[i];
196+
found = true;
197+
}
198+
}
184199
}
185200

186201
/* if not found, check upward */
@@ -262,6 +277,14 @@ ast_node_t *resolve_hierarchical_name_reference_by_path_search(sc_hierarchy *loc
262277
var_declare = resolve_hierarchical_name_reference_by_path_search(local_ref->function_children[i], identifier);
263278
}
264279
}
280+
281+
for (int i = 0; !var_declare && i < local_ref->num_task_children; i++)
282+
{
283+
if (local_ref->task_children[i]->scope_id == scope_id)
284+
{
285+
var_declare = resolve_hierarchical_name_reference_by_path_search(local_ref->task_children[i], identifier);
286+
}
287+
}
265288
}
266289

267290
return var_declare;

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,
@@ -379,6 +385,15 @@ struct typ
379385
sc_hierarchy *string_cache_list;
380386
} function;
381387
struct
388+
{
389+
short is_instantiated;
390+
ast_node_t **task_instantiations_instance;
391+
int size_task_instantiations;
392+
int index;
393+
STRING_CACHE *parameter_list;
394+
sc_hierarchy *string_cache_list;
395+
}task;
396+
struct
382397
{
383398
int num_bit_strings;
384399
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
@@ -51,13 +51,16 @@ ast_node_t *newIf(ast_node_t *compare_expression, ast_node_t *true_expression, a
5151
ast_node_t *newIfQuestion(ast_node_t *compare_expression, ast_node_t *true_expression, ast_node_t *false_expression, int line_number);
5252
ast_node_t *newCase(ast_node_t *compare_expression, ast_node_t *case_list, int line_number);
5353
ast_node_t *newAlways(ast_node_t *delay_control, ast_node_t *statements, int line_number);
54+
ast_node_t *newStatement(ast_node_t *statement, int line_number);
5455
ast_node_t *newFor(ast_node_t *initial, ast_node_t *compare_expression, ast_node_t *terminal, ast_node_t *statement, int line_number);
5556
ast_node_t *newWhile(ast_node_t *compare_expression, ast_node_t *statement, int line_number);
5657

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

8285
/* HIGH LEVEL ITEMS */
8386
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);
84-
ast_node_t *newFunction(ast_node_t *list_of_ports, ast_node_t *list_of_module_items, int line_number);
87+
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);
88+
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);
8589
void next_module();
8690
void next_function();
91+
void next_task();
8792
ast_node_t *newDefparam(ids id, ast_node_t *val, int line_number);
8893

8994
void next_parsed_verilog_file(ast_node_t *file_items_list);

0 commit comments

Comments
 (0)