📄 tasking.c
字号:
*/voidtasking_registry (){ tree tasknode, fn_decl; if (pass == 1) return; fn_decl = lookup_name (get_identifier ("__register_tasking")); for (tasknode = tasking_list; tasknode != NULL_TREE; tasknode = TREE_CHAIN (tasknode)) { tree proc_decl = TASK_INFO_PDECL (tasknode); tree name = DECL_NAME (proc_decl); tree arg_decl; char *init_struct = (char *) alloca (IDENTIFIER_LENGTH (name) + 20); sprintf (init_struct, "__tmp_%s_struct", IDENTIFIER_POINTER (name)); arg_decl = lookup_name (get_identifier (init_struct)); expand_expr_stmt ( build_chill_function_call (fn_decl, build_tree_list (NULL_TREE, force_addr_of (arg_decl)))); }}/* * Put a tasking entity (a PROCESS, or SIGNAL) onto * the list for tasking_setup (). CODE_DECL is the integer code * variable's DECL, which describes the shadow integer which * accompanies each tasking entity. STUFFTYPE is a string * representing the sort of tasking entity we have here (i.e. * process, signal, etc.). STUFFNUMBER is an enumeration * value saying the same thing. PROC_DECL is the declaration of * the entity. It's a FUNCTION_DECL if the entity is a PROCESS, it's * a TYPE_DECL if the entity is a SIGNAL. */voidadd_taskstuff_to_list (code_decl, stufftype, stuffnumber, proc_decl, entry) tree code_decl; char *stufftype; tree stuffnumber, proc_decl, entry;{ if (pass == 1) /* tell chill_finish_compile that there's task-level code to be processed. */ tasking_list = integer_one_node; /* do only in pass 2 so we know in chill_finish_compile whether to generate a constructor function, and to avoid double the correct number of entries. */ else /* pass == 2 */ { tree task_node = make_tree_vec (5); TASK_INFO_PDECL (task_node) = proc_decl; TASK_INFO_ENTRY (task_node) = entry; TASK_INFO_CODE_DECL (task_node) = code_decl; TASK_INFO_STUFF_NUM (task_node) = stuffnumber; TASK_INFO_STUFF_TYPE (task_node) = lookup_name (get_identifier (stufftype)); TREE_CHAIN (task_node) = tasking_list; tasking_list = task_node; }}/* * These next routines are called out of build_generalized_call */treebuild_copy_number (instance_expr) tree instance_expr;{ tree result; if (instance_expr == NULL_TREE || TREE_CODE (instance_expr) == ERROR_MARK) return error_mark_node; if (! CH_IS_INSTANCE_MODE (TREE_TYPE (instance_expr))) { error ("COPY_NUMBER argument must be INSTANCE expression"); return error_mark_node; } result = build_component_ref (instance_expr, get_identifier (INS_COPY)); CH_DERIVED_FLAG (result) = 1; return result;}treebuild_gen_code (decl) tree decl;{ tree result; if (decl == NULL_TREE || TREE_CODE (decl) == ERROR_MARK) return error_mark_node; if ((TREE_CODE (decl) == FUNCTION_DECL && CH_DECL_PROCESS (decl)) || (TREE_CODE (decl) == TYPE_DECL && CH_DECL_SIGNAL (decl))) result = (tree)(DECL_TASKING_CODE_DECL (decl)); else { error ("GEN_CODE argument must be a process or signal name."); return error_mark_node; } CH_DERIVED_FLAG (result) = 1; return (result);}treebuild_gen_inst (process, copyn) tree process, copyn;{ tree ptype; tree result; if (copyn == NULL_TREE || TREE_CODE (copyn) == ERROR_MARK) return error_mark_node; if (process == NULL_TREE || TREE_CODE (process) == ERROR_MARK) return error_mark_node; if (TREE_CODE (TREE_TYPE (copyn)) != INTEGER_TYPE) { error ("GEN_INST parameter 2 must be an integer mode"); copyn = integer_zero_node; } copyn = check_range (copyn, copyn, TYPE_MIN_VALUE (chill_taskingcode_type_node), TYPE_MAX_VALUE (chill_taskingcode_type_node)); if (TREE_CODE (process) == FUNCTION_DECL && CH_DECL_PROCESS (process)) ptype = (tree)DECL_TASKING_CODE_DECL (process); else if (TREE_TYPE (process) != NULL_TREE && TREE_CODE (TREE_TYPE (process)) == INTEGER_TYPE) { process = check_range (process, process, TYPE_MIN_VALUE (chill_taskingcode_type_node), TYPE_MAX_VALUE (chill_taskingcode_type_node)); ptype = convert (chill_taskingcode_type_node, process); } else { error ("GEN_INST parameter 1 must be a PROCESS or an integer expression"); return (error_mark_node); } result = convert (instance_type_node, build_nt (CONSTRUCTOR, NULL_TREE, tree_cons (NULL_TREE, ptype, tree_cons (NULL_TREE, convert (chill_taskingcode_type_node, copyn), NULL_TREE)))); CH_DERIVED_FLAG (result) = 1; return result;}treebuild_gen_ptype (process_decl) tree process_decl;{ tree result; if (process_decl == NULL_TREE || TREE_CODE (process_decl) == ERROR_MARK) return error_mark_node; if (TREE_CODE (process_decl) != FUNCTION_DECL || ! CH_DECL_PROCESS (process_decl)) { error_with_decl (process_decl, "%s is not a declared process"); return error_mark_node; } result = (tree)DECL_TASKING_CODE_DECL (process_decl); CH_DERIVED_FLAG (result) = 1; return result;}treebuild_proc_type (instance_expr) tree instance_expr;{ tree result; if (instance_expr == NULL_TREE || TREE_CODE (instance_expr) == ERROR_MARK) return error_mark_node; if (! CH_IS_INSTANCE_MODE (TREE_TYPE (instance_expr))) { error ("PROC_TYPE argument must be INSTANCE expression"); return error_mark_node; } result = build_component_ref (instance_expr, get_identifier (INS_PTYPE)); CH_DERIVED_FLAG (result) = 1; return result;}treebuild_queue_length (buf_ev) tree buf_ev;{ if (buf_ev == NULL_TREE || TREE_CODE (buf_ev) == ERROR_MARK) return error_mark_node; if (TREE_TYPE (buf_ev) == NULL_TREE || TREE_CODE (TREE_TYPE (buf_ev)) == ERROR_MARK) return error_mark_node; if (CH_IS_BUFFER_MODE (TREE_TYPE (buf_ev)) || CH_IS_EVENT_MODE (TREE_TYPE (buf_ev))) { char *field_name; tree arg1, arg2; if (CH_IS_EVENT_MODE (TREE_TYPE (buf_ev))) { field_name = "__event_data"; arg2 = integer_one_node; } else { field_name = "__buffer_data"; arg2 = integer_zero_node; } arg1 = build_component_ref (buf_ev, get_identifier (field_name)); return build_chill_function_call ( lookup_name (get_identifier ("__queue_length")), tree_cons (NULL_TREE, arg1, tree_cons (NULL_TREE, arg2, NULL_TREE))); } error ("QUEUE_LENGTH argument must be a BUFFER/EVENT location."); return error_mark_node;}treebuild_signal_struct_type (signame, sigmodelist, optsigdest) tree signame, sigmodelist, optsigdest;{ tree decl, temp; if (pass == 1) { int fldcnt = 0; tree mode, field_decls = NULL_TREE; for (mode = sigmodelist; mode != NULL_TREE; mode = TREE_CHAIN (mode)) { tree field; char fldname[20]; if (TREE_VALUE (mode) == NULL_TREE) continue; sprintf (fldname, "fld%03d", fldcnt++); field = build_decl (FIELD_DECL, get_identifier (fldname), TREE_VALUE (mode)); if (field_decls == NULL_TREE) field_decls = field; else chainon (field_decls, field); } if (field_decls == NULL_TREE) field_decls = build_decl (FIELD_DECL, get_identifier ("__tmp_empty"), boolean_type_node); temp = build_chill_struct_type (field_decls); /* save the destination process name of the signal */ IDENTIFIER_SIGNAL_DEST (signame) = optsigdest; IDENTIFIER_SIGNAL_DATA (signame) = fldcnt; } else { /* optsigset is only valid in pass 2, so we have to save it now */ IDENTIFIER_SIGNAL_DEST (signame) = optsigdest; temp = NULL_TREE; /* Actually, don't care. */ } decl = push_modedef (signame, temp, -1); if (decl != NULL_TREE) CH_DECL_SIGNAL (decl) = 1; return decl;}/* * An instance type is a unique process identifier in the CHILL * tasking arena. It consists of a process type and a copy number. */voidbuild_instance_type (){ tree decl1, decl2, tdecl; decl1 = build_decl (FIELD_DECL, get_identifier (INS_PTYPE), chill_taskingcode_type_node); TREE_CHAIN (decl1) = decl2 = build_decl (FIELD_DECL, get_identifier (INS_COPY), chill_taskingcode_type_node); TREE_CHAIN (decl2) = NULL_TREE; instance_type_node = build_chill_struct_type (decl1); tdecl = build_decl (TYPE_DECL, ridpointers[(int) RID_INSTANCE], instance_type_node); TYPE_NAME (instance_type_node) = tdecl; CH_NOVELTY (instance_type_node) = tdecl; DECL_SOURCE_LINE (tdecl) = 0; pushdecl (tdecl); pointer_to_instance = build_chill_pointer_type (instance_type_node);}#if 0 * * The tasking message descriptor looks like this C structure: * * typedef struct * { * short *sc; /* ptr to code integer */ * int data_len; /* length of signal/buffer data msg */ * void *data; /* ptr to signal/buffer data */ * } SignalDescr; * *#endifvoidbuild_tasking_message_type (){ tree type_name; tree temp; /* We temporarily reset maximum_field_alignment to deal with the runtime system. */ extern int maximum_field_alignment; int save_maximum_field_alignment = maximum_field_alignment; tree field1, field2, field3; maximum_field_alignment = 0; field1 = build_decl (FIELD_DECL, get_identifier ("_SD_code_ptr"), build_pointer_type (chill_integer_type_node)); field2 = build_decl (FIELD_DECL, get_identifier ("_SD_data_len"), integer_type_node); field3 = build_decl (FIELD_DECL, get_identifier ("_SD_data_ptr"), ptr_type_node); TREE_CHAIN (field1) = field2; TREE_CHAIN (field2) = field3; temp = build_chill_struct_type (field1); type_name = get_identifier ("__tmp_SD_struct"); tasking_message_type = build_decl (TYPE_DECL, type_name, temp); /* This won't get seen in pass 2, so lay it out now. */ layout_chill_struct_type (temp); pushdecl (tasking_message_type); maximum_field_alignment = save_maximum_field_alignment;}treebuild_signal_descriptor (sigdef, exprlist) tree sigdef, exprlist;{ tree fieldlist, typetail, valtail; tree actuallist = NULL_TREE; tree signame = DECL_NAME (sigdef); tree dataptr, datalen; int parmno = 1; if (sigdef == NULL_TREE || TREE_CODE (sigdef) == ERROR_MARK) return error_mark_node; if (exprlist != NULL_TREE && TREE_CODE (exprlist) == ERROR_MARK) return error_mark_node; if (TREE_CODE (sigdef) != TYPE_DECL || ! CH_DECL_SIGNAL (sigdef)) { error ("SEND requires a SIGNAL; %s is not a SIGNAL name", IDENTIFIER_POINTER (signame)); return error_mark_node; } if (CH_TYPE_NONVALUE_P (TREE_TYPE (sigdef))) return error_mark_node; fieldlist = TYPE_FIELDS (TREE_TYPE (sigdef)); if (IDENTIFIER_SIGNAL_DATA (signame) == 0) fieldlist = TREE_CHAIN (fieldlist); for (valtail = exprlist, typetail = fieldlist; valtail != NULL_TREE && typetail != NULL_TREE; parmno++, valtail = TREE_CHAIN (valtail), typetail = TREE_CHAIN (typetail)) { register tree actual = valtail ? TREE_VALUE (valtail) : 0; register tree type = typetail ? TREE_TYPE (typetail) : 0; char place[30]; sprintf (place, "signal field %d", parmno); actual = chill_convert_for_assignment (type, actual, place); actuallist = tree_cons (NULL_TREE, actual, actuallist); } if (valtail != 0 && TREE_VALUE (valtail) != void_type_node) { error ("too many values for SIGNAL `%s'", IDENTIFIER_POINTER (signame)); return error_mark_node; } else if (typetail != 0 && TREE_VALUE (typetail) != void_type_node) { error ("too few values for SIGNAL `%s'", IDENTIFIER_POINTER (signame)); return error_mark_node; } { /* build signal data structure */ tree sigdataname = get_unique_identifier ( IDENTIFIER_POINTER (signame)); if (exprlist == NULL_TREE) { dataptr = null_pointer_node; datalen = integer_zero_node; } else { tree tuple = build_nt (CONSTRUCTOR, NULL_TREE, nreverse (actuallist)); tree decl = decl_temp1 (sigdataname, TREE_TYPE (sigdef), 0, tuple, 0, 0); /* prevent granting of this type */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -