64 generate_c_sfc_elements_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
65 generate_c_sfc_elements_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
65 : generate_c_base_c(s4o_ptr) { |
66 : generate_c_base_c(s4o_ptr) { |
66 generate_c_il = new generate_c_il_c(s4o_ptr, name, scope, variable_prefix); |
67 generate_c_il = new generate_c_il_c(s4o_ptr, name, scope, variable_prefix); |
67 generate_c_st = new generate_c_st_c(s4o_ptr, name, scope, variable_prefix); |
68 generate_c_st = new generate_c_st_c(s4o_ptr, name, scope, variable_prefix); |
68 generate_c_code = new generate_c_SFC_IL_ST_c(s4o_ptr, name, scope, variable_prefix); |
69 generate_c_code = new generate_c_SFC_IL_ST_c(s4o_ptr, name, scope, variable_prefix); |
|
70 search_var_instance_decl = new search_var_instance_decl_c(scope); |
69 this->set_variable_prefix(variable_prefix); |
71 this->set_variable_prefix(variable_prefix); |
70 } |
72 } |
71 |
73 |
72 ~generate_c_sfc_elements_c(void) { |
74 ~generate_c_sfc_elements_c(void) { |
73 transition_list.clear(); |
75 transition_list.clear(); |
74 delete generate_c_il; |
76 delete generate_c_il; |
75 delete generate_c_st; |
77 delete generate_c_st; |
76 delete generate_c_code; |
78 delete generate_c_code; |
77 } |
79 delete search_var_instance_decl; |
|
80 } |
|
81 |
|
82 |
|
83 bool is_variable(symbol_c *symbol) { |
|
84 /* we try to find the variable instance declaration, to determine if symbol is variable... */ |
|
85 symbol_c *var_decl = search_var_instance_decl->get_decl(symbol); |
|
86 |
|
87 return var_decl != NULL; |
|
88 } |
78 |
89 |
79 void reset_transition_number(void) {transition_number = 0;} |
90 void reset_transition_number(void) {transition_number = 0;} |
80 |
91 |
81 void generate(symbol_c *symbol, sfcgeneration_t generation_type) { |
92 void generate(symbol_c *symbol, sfcgeneration_t generation_type) { |
82 wanted_sfcgeneration = generation_type; |
93 wanted_sfcgeneration = generation_type; |
396 |
407 |
397 void *visit(action_c *symbol) { |
408 void *visit(action_c *symbol) { |
398 switch (wanted_sfcgeneration) { |
409 switch (wanted_sfcgeneration) { |
399 case actionbody_sg: |
410 case actionbody_sg: |
400 s4o.print(s4o.indent_spaces + "if("); |
411 s4o.print(s4o.indent_spaces + "if("); |
|
412 s4o.print(GET_VAR); |
|
413 s4o.print("("); |
401 print_variable_prefix(); |
414 print_variable_prefix(); |
402 s4o.print("__action_list["); |
415 s4o.print("__action_list["); |
403 s4o.print(SFC_STEP_ACTION_PREFIX); |
416 s4o.print(SFC_STEP_ACTION_PREFIX); |
404 symbol->action_name->accept(*this); |
417 symbol->action_name->accept(*this); |
405 s4o.print("].state) {\n"); |
418 s4o.print("].state)) {\n"); |
406 s4o.indent_right(); |
419 s4o.indent_right(); |
407 |
420 |
408 // generate action code |
421 // generate action code |
409 symbol->function_block_body->accept(*generate_c_code); |
422 symbol->function_block_body->accept(*generate_c_code); |
410 |
423 |
517 s4o.print(s4o.indent_spaces + "if ("); |
532 s4o.print(s4o.indent_spaces + "if ("); |
518 if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "S") == 0 || |
533 if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "S") == 0 || |
519 strcmp(qualifier, "R") == 0) { |
534 strcmp(qualifier, "R") == 0) { |
520 s4o.print("active"); |
535 s4o.print("active"); |
521 } |
536 } |
522 if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 || |
537 else if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 || |
523 strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0) { |
538 strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0 || |
|
539 strcmp(qualifier, "P0") == 0) { |
524 s4o.print("activated"); |
540 s4o.print("activated"); |
525 } |
541 } |
526 if (strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) { |
542 else if (strcmp(qualifier, "P1") == 0) { |
|
543 s4o.print("desactivated"); |
|
544 } |
|
545 else if (strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) { |
527 s4o.print("active && __time_cmp("); |
546 s4o.print("active && __time_cmp("); |
528 print_step_argument(current_step, "elapsed_time"); |
547 print_step_argument(current_step, "elapsed_time"); |
529 s4o.print(", "); |
548 s4o.print(", "); |
530 symbol->action_time->accept(*this); |
549 symbol->action_time->accept(*this); |
531 if (strcmp(qualifier, "D") == 0) { |
550 if (strcmp(qualifier, "D") == 0) { |
537 } |
556 } |
538 s4o.print(") {\n"); |
557 s4o.print(") {\n"); |
539 s4o.indent_right(); |
558 s4o.indent_right(); |
540 s4o.print(s4o.indent_spaces); |
559 s4o.print(s4o.indent_spaces); |
541 if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "P") == 0 || |
560 if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "P") == 0 || |
542 strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) { |
561 strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0 || |
543 print_action_argument(current_action, "state"); |
562 strcmp(qualifier, "P0") == 0 || strcmp(qualifier, "P1") == 0) { |
544 s4o.print(" = 1;\n"); |
563 |
545 } |
564 if (is_variable(current_action)) { |
546 if (strcmp(qualifier, "S") == 0) { |
565 unsigned int vartype = search_var_instance_decl->get_vartype(current_action); |
|
566 |
|
567 if (vartype == search_var_instance_decl_c::external_vt) |
|
568 s4o.print(SET_EXTERNAL); |
|
569 else if (vartype == search_var_instance_decl_c::located_vt) |
|
570 s4o.print(SET_LOCATED); |
|
571 else |
|
572 s4o.print(SET_VAR); |
|
573 s4o.print("("); |
|
574 print_variable_prefix(); |
|
575 s4o.print(","); |
|
576 current_action->accept(*this); |
|
577 s4o.print(",1);\n"); |
|
578 s4o.indent_left(); |
|
579 s4o.print("}\n"); |
|
580 s4o.print(s4o.indent_spaces + "else if (active) {\n"); |
|
581 s4o.indent_right(); |
|
582 if (vartype == search_var_instance_decl_c::external_vt) |
|
583 s4o.print(SET_EXTERNAL); |
|
584 else if (vartype == search_var_instance_decl_c::located_vt) |
|
585 s4o.print(SET_LOCATED); |
|
586 else |
|
587 s4o.print(SET_VAR); |
|
588 s4o.print("("); |
|
589 print_variable_prefix(); |
|
590 s4o.print(","); |
|
591 current_action->accept(*this); |
|
592 s4o.print(",0);\n"); |
|
593 } |
|
594 |
|
595 else { |
|
596 s4o.print(SET_VAR); |
|
597 s4o.print("("); |
|
598 print_action_argument(current_action, "state", true); |
|
599 s4o.print(",1);\n"); |
|
600 } |
|
601 } |
|
602 if (strcmp(qualifier, "S") == 0 || strcmp(qualifier, "SL") == 0) { |
547 print_action_argument(current_action, "set"); |
603 print_action_argument(current_action, "set"); |
548 s4o.print(" = 1;\n"); |
604 s4o.print(" = 1;\n"); |
549 } |
605 } |
550 if (strcmp(qualifier, "R") == 0) { |
606 if (strcmp(qualifier, "R") == 0) { |
551 print_action_argument(current_action, "reset"); |
607 print_action_argument(current_action, "reset"); |
712 s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
768 s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
713 print_variable_prefix(); |
769 print_variable_prefix(); |
714 s4o.print("__nb_actions; i++) {\n"); |
770 s4o.print("__nb_actions; i++) {\n"); |
715 s4o.indent_right(); |
771 s4o.indent_right(); |
716 s4o.print(s4o.indent_spaces); |
772 s4o.print(s4o.indent_spaces); |
717 print_variable_prefix(); |
773 s4o.print(SET_VAR); |
718 s4o.print("__action_list[i].state = 0;\n"); |
774 s4o.print("("); |
|
775 print_variable_prefix(); |
|
776 s4o.print(",__action_list[i].state,0);\n"); |
719 s4o.print(s4o.indent_spaces); |
777 s4o.print(s4o.indent_spaces); |
720 print_variable_prefix(); |
778 print_variable_prefix(); |
721 s4o.print("__action_list[i].set = 0;\n"); |
779 s4o.print("__action_list[i].set = 0;\n"); |
722 s4o.print(s4o.indent_spaces); |
780 s4o.print(s4o.indent_spaces); |
723 print_variable_prefix(); |
781 print_variable_prefix(); |
832 s4o.print("__action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n" + s4o.indent_spaces); |
890 s4o.print("__action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n" + s4o.indent_spaces); |
833 print_variable_prefix(); |
891 print_variable_prefix(); |
834 s4o.print("__action_list[i].stored = 0;\n"); |
892 s4o.print("__action_list[i].stored = 0;\n"); |
835 s4o.indent_left(); |
893 s4o.indent_left(); |
836 s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces); |
894 s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces); |
837 print_variable_prefix(); |
895 s4o.print(SET_VAR); |
838 s4o.print("__action_list[i].state |= "); |
896 s4o.print("("); |
839 print_variable_prefix(); |
897 print_variable_prefix(); |
840 s4o.print("__action_list[i].stored;\n"); |
898 s4o.print(",__action_list[i].state,"); |
|
899 s4o.print(GET_VAR); |
|
900 s4o.print("("); |
|
901 print_variable_prefix(); |
|
902 s4o.print("__action_list[i].state) | "); |
|
903 print_variable_prefix(); |
|
904 s4o.print("__action_list[i].stored);\n"); |
841 s4o.indent_left(); |
905 s4o.indent_left(); |
842 s4o.print(s4o.indent_spaces + "}\n\n"); |
906 s4o.print(s4o.indent_spaces + "}\n\n"); |
843 |
907 |
844 /* generate action execution */ |
908 /* generate action execution */ |
845 s4o.print(s4o.indent_spaces + "// Actions execution\n"); |
909 s4o.print(s4o.indent_spaces + "// Actions execution\n"); |
846 { |
910 { |
847 std::list<VARIABLE>::iterator pt; |
911 std::list<VARIABLE>::iterator pt; |
848 for(pt = variable_list.begin(); pt != variable_list.end(); pt++) { |
912 for(pt = variable_list.begin(); pt != variable_list.end(); pt++) { |
849 symbol_c *var_decl = search_var_instance_decl->get_decl(pt->symbol); |
913 |
850 if (var_decl != NULL) { |
914 if (is_variable(pt->symbol)) { |
851 unsigned int vartype = search_var_instance_decl->get_vartype(pt->symbol); |
915 unsigned int vartype = search_var_instance_decl->get_vartype(pt->symbol); |
852 |
916 |
853 s4o.print(s4o.indent_spaces); |
917 s4o.print(s4o.indent_spaces + "if ("); |
854 if (vartype == search_var_instance_decl_c::external_vt) |
|
855 s4o.print(SET_EXTERNAL); |
|
856 else if (vartype == search_var_instance_decl_c::located_vt) |
|
857 s4o.print(SET_LOCATED); |
|
858 else |
|
859 s4o.print(SET_VAR); |
|
860 s4o.print("("); |
|
861 print_variable_prefix(); |
|
862 s4o.print(","); |
|
863 pt->symbol->accept(*this); |
|
864 s4o.print(","); |
|
865 print_variable_prefix(); |
918 print_variable_prefix(); |
866 s4o.print("__action_list["); |
919 s4o.print("__action_list["); |
867 s4o.print(SFC_STEP_ACTION_PREFIX); |
920 s4o.print(SFC_STEP_ACTION_PREFIX); |
868 pt->symbol->accept(*this); |
921 pt->symbol->accept(*this); |
869 s4o.print("].state);\n"); |
922 s4o.print("].reset) {\n"); |
|
923 s4o.indent_right(); |
|
924 s4o.print(s4o.indent_spaces); |
|
925 if (vartype == search_var_instance_decl_c::external_vt) |
|
926 s4o.print(SET_EXTERNAL); |
|
927 else if (vartype == search_var_instance_decl_c::located_vt) |
|
928 s4o.print(SET_LOCATED); |
|
929 else |
|
930 s4o.print(SET_VAR); |
|
931 s4o.print("("); |
|
932 print_variable_prefix(); |
|
933 s4o.print(","); |
|
934 pt->symbol->accept(*this); |
|
935 s4o.print(",0);\n"); |
|
936 s4o.indent_left(); |
|
937 s4o.print(s4o.indent_spaces + "}\n"); |
|
938 s4o.print(s4o.indent_spaces + "else if ("); |
|
939 print_variable_prefix(); |
|
940 s4o.print("__action_list["); |
|
941 s4o.print(SFC_STEP_ACTION_PREFIX); |
|
942 pt->symbol->accept(*this); |
|
943 s4o.print("].set) {\n"); |
|
944 s4o.indent_right(); |
|
945 s4o.print(s4o.indent_spaces); |
|
946 if (vartype == search_var_instance_decl_c::external_vt) |
|
947 s4o.print(SET_EXTERNAL); |
|
948 else if (vartype == search_var_instance_decl_c::located_vt) |
|
949 s4o.print(SET_LOCATED); |
|
950 else |
|
951 s4o.print(SET_VAR); |
|
952 s4o.print("("); |
|
953 print_variable_prefix(); |
|
954 s4o.print(","); |
|
955 pt->symbol->accept(*this); |
|
956 s4o.print(",1);\n"); |
|
957 s4o.indent_left(); |
|
958 s4o.print(s4o.indent_spaces + "}\n"); |
870 } |
959 } |
871 } |
960 } |
872 } |
961 } |
873 for(i = 0; i < symbol->n; i++) { |
962 for(i = 0; i < symbol->n; i++) { |
874 generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::actionbody_sg); |
963 generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::actionbody_sg); |