void OpenMPTransform::parallel_for_preorder(OpenMP::ParallelForConstruct parallel_for_construct) { ObjectList<OpenMP::ReductionSymbol> inner_reductions; inner_reductions_stack.push(inner_reductions); // Increase the parallel nesting value parallel_nesting++; common_parallel_data_sharing_code(parallel_for_construct); Statement construct_body = parallel_for_construct.body(); // The construct is in fact a ForStatement in a #pragma omp parallel for ForStatement for_statement(construct_body); // The induction variable deserves special treatment Symbol induction_var = for_statement.get_induction_variable().get_symbol(); induction_var_stack.push(induction_var); // Set it private if it was not if ((parallel_for_construct.get_data_attribute(induction_var) & OpenMP::DA_PRIVATE) != OpenMP::DA_PRIVATE) { ObjectList<Symbol>& private_references = parallel_for_construct.get_data<ObjectList<Symbol> >("private_references"); // Set private parallel_for_construct.add_data_attribute(induction_var, OpenMP::DA_PRIVATE); // And insert into private references as well private_references.insert(induction_var); ObjectList<Symbol>& shared_references = parallel_for_construct.get_data<ObjectList<Symbol> >("shared_references"); // Remove from shared references if it appears there shared_references = shared_references.not_find(induction_var); } }
/** 语句 <statement>::=<compound_statement> |<if_statement> |<return_statement> |<break_statement> |<continue_statement> |for_statement> <expression_statement> */ void statement(){ switch(token){ case TK_BEGIN: compound_statement(); break; case KW_IF: if_statement(); break; case KW_RETURN: return_statement(); break; case KW_BREAK: break_statement(); break; case KW_CONTINUE: continue_statement(); break; case KW_FOR: for_statement(); break; default: expression_statement(); break; } get_token(); /// }
/*---------------------------------------------------------------------------*/ static void statement(void) { int token; token = tokenizer_token(); switch(token) { case TOKENIZER_PRINT: print_statement(); break; case TOKENIZER_IF: if_statement(); break; case TOKENIZER_GOTO: goto_statement(); break; case TOKENIZER_GOSUB: gosub_statement(); break; case TOKENIZER_RETURN: return_statement(); break; case TOKENIZER_FOR: for_statement(); break; case TOKENIZER_PEEK: peek_statement(); break; case TOKENIZER_POKE: poke_statement(); break; case TOKENIZER_NEXT: next_statement(); break; case TOKENIZER_END: end_statement(); break; case TOKENIZER_LET: accept(TOKENIZER_LET); /* Fall through. */ case TOKENIZER_VARIABLE: let_statement(); break; default: DEBUG_PRINTF("ubasic.c: statement(): not implemented %d\n", token); exit(1); } }
static Boolean_t statement( void ) { /* printf( "statement: %s\n", ident( 0 )); */ switch( token( 0 )) { case ';' : step( 1 ); return True; case '{' : return compound_statement(); case SN_CASE : return case_statement(); case SN_DEFAULT : return default_statement(); case SN_IF : return if_statement(); case SN_ELSE : return else_statement(); case SN_SWITCH : return switch_statement(); case SN_WHILE : return while_statement(); case SN_DO : return do_statement(); case SN_FOR : return for_statement(); case SN_BREAK : return break_statement(); case SN_CONTINUE : return continue_statement(); case SN_RETURN : return return_statement(); case SN_THROW : return throw_statement(); case SN_GOTO : return goto_statement(); case SN_TRY : return try_statement(); case SN_IDENTIFIER: if( labeled_statement ()) return True; if( declaration_statement1()) return True; if( expression_statement ()) return True; if( declaration_statement2()) return True; step( 1 ); return False; case SN_CHAR : case SN_SHORT : case SN_INT : case SN_LONG : case SN_SIGNED : case SN_UNSIGNED : case SN_FLOAT : case SN_DOUBLE : case SN_BOOL : case SN_VOID : if( declaration_statement1()) return True; if( expression_statement ()) return True; if( declaration_statement2()) return True; step( 1 ); return False; case SN_ASM : case SN_TEMPLATE : case SN_NAMESPACE: case SN_USING : case SN_AUTO : case SN_REGISTER : case SN_EXTERN : case SN_STATIC : case SN_INLINE : case SN_VIRTUAL : case SN_CONST : case SN_VOLATILE : case SN_CLASS : case SN_STRUCT : case SN_UNION : case SN_ENUM : case SN_FRIEND : case SN_TYPEDEF : if( declaration_statement1()) return True; if( declaration_statement2()) return True; f_StepTo( ';', '}', 0 ); return False; case SN_SIZEOF : case SN_NEW : case SN_DELETE : case SN_THIS : case SN_OPERATOR : case SN_STRINGliteral : case SN_FLOATINGconstant : case SN_INTEGERconstant : case SN_LONGconstant : case SN_CHARACTERconstant : case SN_ICR : case SN_DECR : case SN_CLCL : case '(': case '~': case '*': case '&': case '+': case '-': case '!': if( expression_statement ()) return True; step( 1 ); return False; case 0: printf( "unexpected end of file\n" ); return False; default: #ifdef PRINT_STATEMENT_DEFAULT printf( "statement: default: %4d %s file: %s:(%d.%d)\n" , token( 0 ) , ident( 0 ) , filename_g , f_lineno( 0 ) , f_charno( 0 ) ); #endif #ifdef BREAK_BY_STATEMENT_DEFAULT exit( -1 ); #endif if( declaration_statement1()) return True; if( expression_statement ()) return True; if( declaration_statement2()) return True; step( 1 ); return False; /* case SN_ARROW : */ /* case SN_LS : */ /* case SN_RS : */ /* case SN_LE : */ /* case SN_GE : */ /* case SN_EQ : */ /* case SN_NE : */ /* case SN_ANDAND : */ /* case SN_OROR : */ /* case SN_ELLIPSIS : */ /* case SN_DOTstar : */ /* case SN_ARROWstar : */ /* case SN_MULTassign : */ /* case SN_DIVassign : */ /* case SN_MODassign : */ /* case SN_PLUSassign : */ /* case SN_MINUSassign : */ /* case SN_LSassign : */ /* case SN_RSassign : */ /* case SN_ANDassign : */ /* case SN_ERassign : */ /* case SN_ORassign : */ /* case '=' : */ /* case '|' : */ /* case '^' : */ /* case '&' : */ /* case '<' : */ /* case '>' : */ /* case '/' : */ /* case '%' : */ /* case ')' : */ /* case '[' : */ /* case ']' : */ /* case '.' : */ /* case ',' : */ /* case '{' : */ /* case '}' : */ /* case '?' : */ /* case ':' : */ } }
/*---------------------------------------------------------------------------*/ static uint8_t statement(void) { int token; string_temp_free(); token = current_token; /* LET may be omitted.. */ if (token != TOKENIZER_INTVAR && token != TOKENIZER_STRINGVAR) accept_tok(token); switch(token) { case TOKENIZER_QUESTION: case TOKENIZER_PRINT: print_statement(); break; case TOKENIZER_IF: if_statement(); break; case TOKENIZER_GO: go_statement(); return 0; case TOKENIZER_RETURN: return_statement(); break; case TOKENIZER_FOR: for_statement(); break; case TOKENIZER_POKE: poke_statement(); break; case TOKENIZER_NEXT: next_statement(); break; case TOKENIZER_STOP: stop_statement(); break; case TOKENIZER_REM: rem_statement(); break; case TOKENIZER_DATA: data_statement(); break; case TOKENIZER_RANDOMIZE: randomize_statement(); break; case TOKENIZER_OPTION: option_statement(); break; case TOKENIZER_INPUT: input_statement(); break; case TOKENIZER_RESTORE: restore_statement(); break; case TOKENIZER_DIM: dim_statement(); break; case TOKENIZER_CLS: cls_statement(); break; case TOKENIZER_LET: case TOKENIZER_STRINGVAR: case TOKENIZER_INTVAR: let_statement(); break; default: DEBUG_PRINTF("ubasic.c: statement(): not implemented %d\n", token); syntax_error(); } return 1; }
void OpenMPTransform::parallel_for_postorder(PragmaCustomConstruct parallel_for_construct) { // One more parallel seen num_parallels++; // Decrease the parallel nesting level parallel_nesting--; // Get the enclosing function definition FunctionDefinition function_definition = parallel_for_construct.get_enclosing_function(); Scope function_scope = function_definition.get_scope(); IdExpression function_name = function_definition.get_function_name(); // This was computed in the preorder ObjectList<Symbol>& shared_references = parallel_for_construct.get_data<ObjectList<Symbol> >("shared_references"); ObjectList<Symbol>& private_references = parallel_for_construct.get_data<ObjectList<Symbol> >("private_references"); ObjectList<Symbol>& firstprivate_references = parallel_for_construct.get_data<ObjectList<Symbol> >("firstprivate_references"); ObjectList<Symbol>& lastprivate_references = parallel_for_construct.get_data<ObjectList<Symbol> >("lastprivate_references"); ObjectList<OpenMP::ReductionSymbol>& reduction_references = parallel_for_construct.get_data<ObjectList<OpenMP::ReductionSymbol> >("reduction_references"); ObjectList<Symbol>& copyin_references = parallel_for_construct.get_data<ObjectList<Symbol> >("copyin_references"); ObjectList<Symbol>& copyprivate_references = parallel_for_construct.get_data<ObjectList<Symbol> >("copyprivate_references"); // Get the construct_body of the statement Statement construct_body = parallel_for_construct.get_statement(); // The construct is in fact a ForStatement in a #pragma omp parallel do ForStatement for_statement(construct_body); Statement loop_body = for_statement.get_loop_body(); // Create the replacement map and the pass_by_pointer set ObjectList<ParameterInfo> parameter_info_list; ReplaceIdExpression replace_references = set_replacements(function_definition, loop_body, shared_references, private_references, firstprivate_references, lastprivate_references, reduction_references, inner_reductions_stack.top(), copyin_references, copyprivate_references, parameter_info_list); // Get the outline function name Source outlined_function_name = get_outlined_function_name(function_name); // Create the outline for parallel for AST_t outline_code = get_outline_parallel_for( parallel_for_construct, function_definition, outlined_function_name, for_statement, loop_body, replace_references, parameter_info_list, private_references, firstprivate_references, lastprivate_references, reduction_references, copyin_references, copyprivate_references); // Now prepend the outline function_definition.get_ast().prepend_sibling_function(outline_code); PragmaCustomClause if_clause = parallel_for_construct.get_clause("if"); PragmaCustomClause num_threads = parallel_for_construct.get_clause("num_threads"); PragmaCustomClause groups_clause = parallel_for_construct.get_clause("groups"); Source instrument_code_before; Source instrument_code_after; AST_t spawn_code = get_parallel_spawn_code( parallel_for_construct.get_ast(), function_definition, parallel_for_construct.get_scope(), parallel_for_construct.get_scope_link(), parameter_info_list, reduction_references, if_clause, num_threads, groups_clause, instrument_code_before, instrument_code_after ); // Discard inner reduction information inner_reductions_stack.pop(); // Replace all the whole construct with spawn_code parallel_for_construct.get_ast().replace(spawn_code); }
//未略过第一个符号 void grammar_parser::statement(set<e_word_t> follows,int& stk_index,while_context* p_while_conext) { word tmp=m_words.get(); if(tmp.m_type==ewt_ident) { m_words.push(tmp); if(m_expression_begs.find(tmp.m_type)!=m_expression_begs.end()) { expression(_create_syms(follows,ewt_key_assign),stk_index); gen_pop_instruction(stk_index); word semicolon=m_words.get(); if(semicolon.m_type!=ewt_key_semicolon) { report_error("语法错误:语句应以 ;结束\n"); m_words.push(semicolon); } else grammar_debug(semicolon); } } else if(m_expression_begs.find(tmp.m_type)!=m_expression_begs.end()) { m_words.push(tmp); expression(follows,stk_index); gen_pop_instruction(stk_index); word semicolon=m_words.get(); if(semicolon.m_type!=ewt_key_semicolon) { report_error("语法错误:语句应以 ;结束\n"); m_words.push(semicolon); } else grammar_debug(semicolon); } else if(tmp.m_type==ewt_key_if) { grammar_debug(tmp); if_statement(follows,stk_index,p_while_conext); } else if(tmp.m_type==ewt_key_while) { grammar_debug(tmp); while_statement(follows,stk_index); } else if(tmp.m_type==ewt_key_for) { grammar_debug(tmp); for_statement(follows,stk_index); } else if(tmp.m_type==ewt_key_break) { grammar_debug(tmp); if(p_while_conext==NULL) { report_error("语法错误:不在循环中,此处不应有break;\n"); } else { gen_code(e_pop,eab_invalid,0,stk_index-p_while_conext->m_begin_stk_index); p_while_conext->breaks.push_back(gen_code(e_jmp,eab_relat_ip,0,0)); } if(m_words.check(ewt_key_semicolon)) m_words.get(); else { report_error("语法错误:break语句缺少分号\n"); } } else if(tmp.m_type==ewt_key_continue) { grammar_debug(tmp); if(p_while_conext==NULL) { report_error("语法错误:不在循环中,此处不应有continue;\n"); } else { gen_code(e_pop,eab_invalid,0,stk_index-p_while_conext->m_begin_stk_index); p_while_conext->continues.push_back(gen_code(e_jmp,eab_relat_ip,0,0)); } if(m_words.check(ewt_key_semicolon)) m_words.get(); else { report_error("语法错误:break语句缺少分号\n"); } } else if(tmp.m_type==ewt_key_return) { grammar_debug(tmp); return_statement(follows,stk_index); } else if(tmp.m_type==ewt_key_semicolon) { grammar_debug(tmp); } else { m_words.push(tmp); test_and_skip(follows,_create_syms()); } }
//static void statement(void) void statement(void) { int token; token = tokenizer_token(); switch(token) { case TOKENIZER_PRINT: print_statement(); break; case TOKENIZER_IF: if_statement(); break; case TOKENIZER_GOTO: goto_statement(); break; case TOKENIZER_GOSUB: gosub_statement(); break; case TOKENIZER_RETURN: return_statement(); break; case TOKENIZER_FOR: for_statement(); break; case TOKENIZER_NEXT: next_statement(); break; case TOKENIZER_END: end_statement(); break; case TOKENIZER_PSET: pset_statement(); break; case TOKENIZER_CLS: cls_statement(); break; case TOKENIZER_REFRESH: refresh_statement(); break; case TOKENIZER_LIST: list_statement(); break; case TOKENIZER_LOAD: load_statement(); break; case TOKENIZER_SAVE: save_statement(); break; case TOKENIZER_FILES: files_statement(); break; case TOKENIZER_PEEK: peek_statement(); break; case TOKENIZER_POKE: poke_statement(); break; case TOKENIZER_WAIT: wait_statement(); break; case TOKENIZER_INPUT: input_statement(); break; case TOKENIZER_INP: inp_statement(); break; case TOKENIZER_INR: inr_statement(); break; case TOKENIZER_INA: ina_statement(); break; case TOKENIZER_REM: rem_statement(); break; case TOKENIZER_RUN: run_statement(); break; case TOKENIZER_ERROR: tokenizer_error_print(); ended = 1; glcd_DrawCursor(); break; case TOKENIZER_LET: accept(TOKENIZER_LET); accept(TOKENIZER_VARIABLE); accept(TOKENIZER_CR); break; /* Fall through. */ case TOKENIZER_VARIABLE: let_statement(); break; default: exit(1); } }
void OpenMPTransform::parallel_for_postorder(OpenMP::ParallelForConstruct parallel_for_construct) { // One more parallel seen num_parallels++; // Remove the induction var from the stack induction_var_stack.pop(); // Decrease the parallel nesting level parallel_nesting--; // Get the directive OpenMP::Directive directive = parallel_for_construct.directive(); // Get the enclosing function definition FunctionDefinition function_definition = parallel_for_construct.get_enclosing_function(); Scope function_scope = function_definition.get_scope(); IdExpression function_name = function_definition.get_function_name(); // This was computed in the preorder ObjectList<Symbol>& shared_references = parallel_for_construct.get_data<ObjectList<Symbol> >("shared_references"); ObjectList<Symbol>& private_references = parallel_for_construct.get_data<ObjectList<Symbol> >("private_references"); ObjectList<Symbol>& firstprivate_references = parallel_for_construct.get_data<ObjectList<Symbol> >("firstprivate_references"); ObjectList<Symbol>& lastprivate_references = parallel_for_construct.get_data<ObjectList<Symbol> >("lastprivate_references"); ObjectList<OpenMP::ReductionSymbol>& reduction_references = parallel_for_construct.get_data<ObjectList<OpenMP::ReductionSymbol> >("reduction_references"); ObjectList<Symbol>& copyin_references = parallel_for_construct.get_data<ObjectList<Symbol> >("copyin_references"); ObjectList<Symbol>& copyprivate_references = parallel_for_construct.get_data<ObjectList<Symbol> >("copyprivate_references"); // Get the construct_body of the statement Statement construct_body = parallel_for_construct.body(); // The construct is in fact a ForStatement in a #pragma omp parallel do ForStatement for_statement(construct_body); Statement loop_body = for_statement.get_loop_body(); // Create the replacement map and the pass_by_pointer set ObjectList<ParameterInfo> parameter_info_list; ReplaceIdExpression replace_references = set_replacements(function_definition, directive, loop_body, shared_references, private_references, firstprivate_references, lastprivate_references, reduction_references, inner_reductions_stack.top(), copyin_references, copyprivate_references, parameter_info_list); // Get the outline function name Source outlined_function_name = get_outlined_function_name(function_name); // Create the outline for parallel for AST_t outline_code = get_outline_parallel_for( parallel_for_construct, function_definition, outlined_function_name, for_statement, loop_body, replace_references, parameter_info_list, private_references, firstprivate_references, lastprivate_references, reduction_references, copyin_references, copyprivate_references, directive); // Now prepend the outline function_definition.get_ast().prepend_sibling_function(outline_code); OpenMP::Clause num_threads = directive.num_threads_clause(); OpenMP::CustomClause groups_clause = directive.custom_clause("groups"); Source instrument_code_before; Source instrument_code_after; if (instrumentation_requested()) { instrument_code_before << "const int EVENT_PARALLEL = 60000001;" << "const int VALUE_PARALLEL_FOR = 1;" << "mintaka_event(EVENT_PARALLEL, VALUE_PARALLEL_FOR);" << "mintaka_state_schedule();" ; instrument_code_after << "const int VALUE_PARALLEL_CLOSE = 0;" << "mintaka_event(EVENT_PARALLEL, VALUE_PARALLEL_CLOSE);" << "mintaka_state_run();" ; } AST_t spawn_code = get_parallel_spawn_code( parallel_for_construct.get_ast(), function_definition, parallel_for_construct.get_scope(), parallel_for_construct.get_scope_link(), parameter_info_list, reduction_references, num_threads, groups_clause, instrument_code_before, instrument_code_after ); // Discard inner reduction information inner_reductions_stack.pop(); // Replace all the whole construct with spawn_code parallel_for_construct.get_ast().replace(spawn_code); }