stage4/generate_cc/generate_cc.cc
changeset 27 667721cf52c5
parent 26 fd67f54e64e1
child 28 5b170c9ce134
equal deleted inserted replaced
26:fd67f54e64e1 27:667721cf52c5
    36 
    36 
    37 
    37 
    38 // #include <stdio.h>  /* required for NULL */
    38 // #include <stdio.h>  /* required for NULL */
    39 #include <string>
    39 #include <string>
    40 #include <iostream>
    40 #include <iostream>
       
    41 #include <sstream>
    41 #include <typeinfo>
    42 #include <typeinfo>
    42 
    43 
    43 #include "../../util/symtable.hh"
    44 #include "../../util/symtable.hh"
    44 #include "../../util/dsymtable.hh"
    45 #include "../../util/dsymtable.hh"
    45 #include "../../absyntax/visitor.hh"
    46 #include "../../absyntax/visitor.hh"
   298 /***********************************************************************/
   299 /***********************************************************************/
   299 /***********************************************************************/
   300 /***********************************************************************/
   300 /***********************************************************************/
   301 /***********************************************************************/
   301 
   302 
   302 
   303 
   303 class generate_cc_c: public generate_cc_typedecl_c {
   304 class generate_cc_pous_c: public generate_cc_typedecl_c {
   304 
   305 
   305   public:
   306   public:
   306     generate_cc_c(stage4out_c *s4o_ptr)
   307     generate_cc_pous_c(stage4out_c *s4o_ptr)
   307       : generate_cc_typedecl_c(s4o_ptr) {};
   308       : generate_cc_typedecl_c(s4o_ptr) {};
   308     virtual ~generate_cc_c(void) {}
   309     virtual ~generate_cc_pous_c(void) {}
   309 
   310 
   310 
   311 
   311   public:
   312   public:
   312 /***************************/
   313 /***************************/
   313 /* B 0 - Programming Model */
   314 /* B 0 - Programming Model */
   765   s4o.print("\n\n\n\n");
   766   s4o.print("\n\n\n\n");
   766 
   767 
   767   return NULL;
   768   return NULL;
   768 }
   769 }
   769 
   770 
   770 
   771 }; /* generate_cc_pous_c */
   771 /* intermediate helper symbol for program_declaration_c */
   772 
   772 /*  { io_var_declarations | other_var_declarations }   */
   773 /***********************************************************************/
   773 /*
   774 /***********************************************************************/
   774  * NOTE: we re-use the var_declarations_list_c
   775 /***********************************************************************/
   775  */
   776 /***********************************************************************/
   776 
   777 /***********************************************************************/
   777 /*********************************************/
   778 /***********************************************************************/
   778 /* B.1.6  Sequential function chart elements */
   779 /***********************************************************************/
   779 /*********************************************/
   780 /***********************************************************************/
       
   781 
       
   782 class generate_cc_config_c: public generate_cc_typedecl_c {
       
   783 
       
   784   public:
       
   785     generate_cc_config_c(stage4out_c *s4o_ptr)
       
   786       : generate_cc_typedecl_c(s4o_ptr) {};
       
   787     virtual ~generate_cc_config_c(void) {}
       
   788 
   780 
   789 
   781 /********************************/
   790 /********************************/
   782 /* B 1.7 Configuration elements */
   791 /* B 1.7 Configuration elements */
   783 /********************************/
   792 /********************************/
   784 
   793 
   882 
   891 
   883   /* (D) Close the class declaration... */
   892   /* (D) Close the class declaration... */
   884   s4o.indent_left();
   893   s4o.indent_left();
   885   s4o.print(s4o.indent_spaces + "}; /* class ");
   894   s4o.print(s4o.indent_spaces + "}; /* class ");
   886   symbol->configuration_name->accept(*this);
   895   symbol->configuration_name->accept(*this);
       
   896 
   887   s4o.print(" */\n\n\n");
   897   s4o.print(" */\n\n\n");
   888 
   898 
   889   return NULL;
   899   return NULL;
   890 }
   900 }
   891 
   901     
   892 
   902 };
   893 
   903 
   894 
   904 /***********************************************************************/
   895 
   905 /***********************************************************************/
   896 
   906 /***********************************************************************/
   897 
   907 /***********************************************************************/
   898 #if 0
   908 /***********************************************************************/
   899 
   909 /***********************************************************************/
   900 /* helper symbol for configuration_declaration */
   910 /***********************************************************************/
   901 SYM_LIST(resource_declaration_list_c)
   911 /***********************************************************************/
   902 
   912 
   903 /*
   913 
   904 RESOURCE resource_name ON resource_type_name
   914 class generate_cc_resources_c: public generate_cc_typedecl_c {
   905    optional_global_var_declarations
   915 
   906    single_resource_declaration
   916   public:
   907 END_RESOURCE
   917     generate_cc_resources_c(stage4out_c *s4o_ptr)
   908 */
   918       : generate_cc_typedecl_c(s4o_ptr) {};
   909 SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration)
   919     virtual ~generate_cc_resources_c(void) {}
   910 
   920 
   911 /* task_configuration_list program_configuration_list */
   921     void *visit(resource_declaration_c *symbol) {
   912 SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list)
   922     	return NULL;
   913 
   923     }
   914 /* helper symbol for single_resource_declaration */
   924 
   915 SYM_LIST(task_configuration_list_c)
   925     void *visit(single_resource_declaration_c *symbol) {
   916 
   926     	return NULL;
   917 /* helper symbol for single_resource_declaration */
   927     }
   918 SYM_LIST(program_configuration_list_c)
   928     
   919 
   929 };
   920 /* helper symbol for
   930 /***********************************************************************/
   921  *  - access_path
   931 /***********************************************************************/
   922  *  - instance_specific_init
   932 /***********************************************************************/
   923  */
   933 /***********************************************************************/
   924 SYM_LIST(any_fb_name_list_c)
   934 /***********************************************************************/
   925 
   935 /***********************************************************************/
   926 /*  [resource_name '.'] global_var_name ['.' structure_element_name] */
   936 /***********************************************************************/
   927 SYM_REF4(global_var_reference_c, resource_name, global_var_name, structure_element_name, unused)
   937 /***********************************************************************/
   928 
   938 
   929 /*  prev_declared_program_name '.' symbolic_variable */
   939 class generate_cc_c: public iterator_visitor_c {
   930 SYM_REF2(program_output_reference_c, program_name, symbolic_variable)
   940   protected:
   931 
   941     stage4out_c &s4o;
   932 /*  TASK task_name task_initialization */
   942     stage4out_c pous_s4o;
   933 SYM_REF2(task_configuration_c, task_name, task_initialization)
   943     generate_cc_pous_c generate_cc_pous;
   934 
   944 
   935 /*  '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' */
   945     const char *current_name;
   936 SYM_REF4(task_initialization_c, single_data_source, interval_data_source, priority_data_source, unused)
   946 
   937 
   947   public:
   938 /*  PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */
   948     generate_cc_c(stage4out_c *s4o_ptr): 
   939 SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused)
   949             s4o(*s4o_ptr),
   940 
   950             generate_cc_pous(&pous_s4o) {}
   941 /* prog_conf_elements ',' prog_conf_element */
   951             
   942 SYM_LIST(prog_conf_elements_c)
   952     ~generate_cc_c(void) {}
   943 
   953 
   944 /*  fb_name WITH task_name */
   954 /*************************/
   945 SYM_REF2(fb_task_c, fb_name, task_name)
   955 /* B.1 - Common elements */
   946 
   956 /*************************/
   947 /*  any_symbolic_variable ASSIGN prog_data_source */
   957 /*******************************************/
   948 SYM_REF2(prog_cnxn_assign_c, symbolic_variable, prog_data_source)
   958 /* B 1.1 - Letters, digits and identifiers */
   949 
   959 /*******************************************/
   950 /* any_symbolic_variable SENDTO data_sink */
   960     void *visit(identifier_c *symbol) {
   951 SYM_REF2(prog_cnxn_sendto_c, symbolic_variable, prog_data_source)
   961     	current_name = symbol->value;
   952 
   962     	return NULL;
   953 /* VAR_CONFIG instance_specific_init_list END_VAR_BOGUS */
   963     }
   954 SYM_REF2(instance_specific_initializations_c, instance_specific_init_list, unused)
   964 
   955 
   965 /**************************************/
   956 /* helper symbol for instance_specific_initializations */
   966 /* B.1.5 - Program organization units */
   957 SYM_LIST(instance_specific_init_list_c)
   967 /**************************************/
   958 
   968 /***********************/
   959 /* resource_name '.' program_name '.' {fb_name '.'}
   969 /* B 1.5.1 - Functions */
   960     ((variable_name [location] ':' located_var_spec_init) | (fb_name ':' fb_initialization))
   970 /***********************/
   961 */
   971     void *visit(function_declaration_c *symbol) {
   962 SYM_REF6(instance_specific_init_c, resource_name, program_name, any_fb_name_list, variable_name, location, initialization)
   972     	symbol->accept(generate_cc_pous);
   963 
   973     	return NULL;
   964 /* helper symbol for instance_specific_init */
   974     }
   965 /* function_block_type_name ':=' structure_initialization */
   975     
   966 SYM_REF2(fb_initialization_c, function_block_type_name, structure_initialization)
   976 /*****************************/
   967 
   977 /* B 1.5.2 - Function Blocks */
   968 #endif
   978 /*****************************/
   969 
   979     void *visit(function_block_declaration_c *symbol) {
   970 
   980     	symbol->accept(generate_cc_pous);
   971 }; /* generate_cc_c */
   981     	return NULL;
   972 
   982     }
   973 
   983     
       
   984 /**********************/
       
   985 /* B 1.5.3 - Programs */
       
   986 /**********************/    
       
   987     void *visit(program_declaration_c *symbol) {
       
   988     	symbol->accept(generate_cc_pous);
       
   989     	return NULL;
       
   990     }
       
   991     
       
   992 
       
   993 /********************************/
       
   994 /* B 1.7 Configuration elements */
       
   995 /********************************/
       
   996     void *visit(configuration_declaration_c *symbol) {
       
   997     	symbol->configuration_name->accept(*this);
       
   998     	stage4out_c config_s4o(current_name, "c");
       
   999     	generate_cc_config_c generate_cc_config(&config_s4o);
       
  1000     	symbol->accept(generate_cc_config);
       
  1001     	return NULL;
       
  1002     }
       
  1003 
       
  1004     void *visit(resource_declaration_c *symbol) {
       
  1005     	symbol->resource_name->accept(*this);
       
  1006     	stage4out_c resources_s4o(current_name, "c");
       
  1007     	generate_cc_resources_c generate_cc_resources(&resources_s4o);
       
  1008     	symbol->accept(generate_cc_resources);
       
  1009     	return NULL;
       
  1010     }
       
  1011 
       
  1012     void *visit(single_resource_declaration_c *symbol) {
       
  1013     	stage4out_c resources_s4o("resource", "c");
       
  1014     	generate_cc_resources_c generate_cc_resources(&resources_s4o);
       
  1015     	symbol->accept(generate_cc_resources);
       
  1016     	return NULL;
       
  1017     }
       
  1018 
       
  1019     
       
  1020 };
   974 
  1021 
   975 /***********************************************************************/
  1022 /***********************************************************************/
   976 /***********************************************************************/
  1023 /***********************************************************************/
   977 /***********************************************************************/
  1024 /***********************************************************************/
   978 /***********************************************************************/
  1025 /***********************************************************************/