739 // unless global_vt is acompanied by resource_vt |
739 // unless global_vt is acompanied by resource_vt |
740 static const unsigned int located_vt = 0x0080; // VAR <var_name> AT <location> |
740 static const unsigned int located_vt = 0x0080; // VAR <var_name> AT <location> |
741 static const unsigned int program_vt = 0x0100; // PROGRAM (inside a configuration!) |
741 static const unsigned int program_vt = 0x0100; // PROGRAM (inside a configuration!) |
742 // Programs declared inside a resource will not be declared |
742 // Programs declared inside a resource will not be declared |
743 // unless program_vt is acompanied by resource_vt |
743 // unless program_vt is acompanied by resource_vt |
744 |
744 static const unsigned int en_vt = 0x0200; // EN declaration |
745 static const unsigned int eneno_vt = 0x0200; // EN/ENO declaration |
745 static const unsigned int eno_vt = 0x0400; // ENO declaration |
746 |
|
747 static const unsigned int resource_vt = 0x8000; // RESOURCE (inside a configuration!) |
746 static const unsigned int resource_vt = 0x8000; // RESOURCE (inside a configuration!) |
748 // This, just of itself, will not print out any declarations!! |
747 // This, just of itself, will not print out any declarations!! |
749 // It must be acompanied by either program_vt and/or global_vt |
748 // It must be acompanied by either program_vt and/or global_vt |
750 |
749 |
751 /* How variables should be declared: as local variables or |
750 /* How variables should be declared: as local variables or |
829 int finterface_var_count; |
828 int finterface_var_count; |
830 |
829 |
831 /* Current parsed resource name, for resource |
830 /* Current parsed resource name, for resource |
832 * specific global variable declaration (with #define...)*/ |
831 * specific global variable declaration (with #define...)*/ |
833 symbol_c *resource_name; |
832 symbol_c *resource_name; |
834 |
|
835 /* Store if En and ENO parameters have been defined by user */ |
|
836 bool en_declared; |
|
837 bool eno_declared; |
|
838 |
833 |
839 /* Holds the references to the type and initial value |
834 /* Holds the references to the type and initial value |
840 * of the variables currently being declared. |
835 * of the variables currently being declared. |
841 * Please read the comment under var1_init_decl_c for further |
836 * Please read the comment under var1_init_decl_c for further |
842 * details... |
837 * details... |
876 * declared. |
871 * declared. |
877 */ |
872 */ |
878 symbol_c *globalnamespace; |
873 symbol_c *globalnamespace; |
879 |
874 |
880 /* Actually produce the output where variables are declared... */ |
875 /* Actually produce the output where variables are declared... */ |
881 /* Note that located variables are the exception, they |
876 /* Note that located variables and EN/ENO are the exception, they |
882 * being declared in the located_var_decl_c visitor... |
877 * being declared in the located_var_decl_c, |
|
878 * en_param_declaration_c and eno_param_declaration_c visitors... |
883 */ |
879 */ |
884 void *declare_variables(symbol_c *symbol, bool is_fb = false) { |
880 void *declare_variables(symbol_c *symbol, bool is_fb = false) { |
885 list_c *list = dynamic_cast<list_c *>(symbol); |
881 list_c *list = dynamic_cast<list_c *>(symbol); |
886 /* should NEVER EVER occur!! */ |
882 /* should NEVER EVER occur!! */ |
887 if (list == NULL) ERROR; |
883 if (list == NULL) ERROR; |
984 current_var_type_symbol = NULL; |
980 current_var_type_symbol = NULL; |
985 current_var_init_symbol = NULL; |
981 current_var_init_symbol = NULL; |
986 globalnamespace = NULL; |
982 globalnamespace = NULL; |
987 nv = NULL; |
983 nv = NULL; |
988 resource_name = res_name; |
984 resource_name = res_name; |
989 en_declared = false; |
|
990 eno_declared = false; |
|
991 } |
985 } |
992 |
986 |
993 ~generate_c_vardecl_c(void) {} |
987 ~generate_c_vardecl_c(void) {} |
994 |
|
995 bool is_en_declared(void) { |
|
996 return en_declared; |
|
997 } |
|
998 |
|
999 bool is_eno_declared(void) { |
|
1000 return eno_declared; |
|
1001 } |
|
1002 |
988 |
1003 void print(symbol_c *symbol, symbol_c *scope = NULL, const char *variable_prefix = NULL) { |
989 void print(symbol_c *symbol, symbol_c *scope = NULL, const char *variable_prefix = NULL) { |
1004 this->set_variable_prefix(variable_prefix); |
990 this->set_variable_prefix(variable_prefix); |
1005 if (globalinit_vf == wanted_varformat) |
991 if (globalinit_vf == wanted_varformat) |
1006 globalnamespace = scope; |
992 globalnamespace = scope; |
1018 symbol->accept(*this); |
1004 symbol->accept(*this); |
1019 |
1005 |
1020 delete nv; |
1006 delete nv; |
1021 nv = NULL; |
1007 nv = NULL; |
1022 globalnamespace = NULL; |
1008 globalnamespace = NULL; |
1023 } |
|
1024 |
|
1025 void print_eneno(void) { |
|
1026 if (!en_declared) { |
|
1027 if (wanted_varformat == finterface_vf) { |
|
1028 if (finterface_var_count > 0) |
|
1029 s4o.print(",\n" + s4o.indent_spaces); |
|
1030 s4o.print("BOOL EN"); |
|
1031 } |
|
1032 else |
|
1033 s4o.print(s4o.indent_spaces + "BOOL EN;\n"); |
|
1034 } |
|
1035 if (!eno_declared) { |
|
1036 if (wanted_varformat == finterface_vf) |
|
1037 s4o.print(",\n" + s4o.indent_spaces + "BOOL *ENO"); |
|
1038 else |
|
1039 s4o.print(s4o.indent_spaces + "BOOL ENO;\n"); |
|
1040 } |
|
1041 } |
1009 } |
1042 |
1010 |
1043 protected: |
1011 protected: |
1044 /***************************/ |
1012 /***************************/ |
1045 /* B 0 - Programming Model */ |
1013 /* B 0 - Programming Model */ |
1155 return NULL; |
1123 return NULL; |
1156 } |
1124 } |
1157 |
1125 |
1158 void *visit(en_param_declaration_c *symbol) { |
1126 void *visit(en_param_declaration_c *symbol) { |
1159 TRACE("en_declaration_c"); |
1127 TRACE("en_declaration_c"); |
1160 if (en_declared) ERROR; |
|
1161 if (wanted_varformat == finterface_vf) { |
1128 if (wanted_varformat == finterface_vf) { |
1162 finterface_var_count++; |
1129 finterface_var_count++; |
1163 } |
1130 } |
1164 if ((current_vartype & eneno_vt) != 0) { |
1131 if ((wanted_vartype & en_vt) != 0) { |
1165 if (wanted_varformat == finterface_vf) { |
1132 if (wanted_varformat == finterface_vf) { |
1166 s4o.print(nv->get()); |
1133 s4o.print(nv->get()); |
1167 s4o.print("\n" + s4o.indent_spaces + "BOOL EN"); |
1134 s4o.print("\n" + s4o.indent_spaces); |
1168 } |
1135 symbol->type->accept(*this); |
|
1136 s4o.print(" "); |
|
1137 symbol->name->accept(*this); |
|
1138 } |
|
1139 |
|
1140 if ((wanted_varformat == local_vf) || |
|
1141 (wanted_varformat == init_vf) || |
|
1142 (wanted_varformat == localinit_vf)) { |
|
1143 s4o.print(s4o.indent_spaces); |
|
1144 if (wanted_varformat != init_vf) { |
|
1145 symbol->type->accept(*this); |
|
1146 s4o.print(" "); |
|
1147 } |
|
1148 print_variable_prefix(); |
|
1149 symbol->name->accept(*this); |
|
1150 if (wanted_varformat != local_vf) { |
|
1151 s4o.print(" = "); |
|
1152 symbol->value->accept(*this); |
|
1153 s4o.print(";"); |
|
1154 } |
|
1155 s4o.print(";\n"); |
|
1156 } |
|
1157 |
1169 if (wanted_varformat == constructorinit_vf) { |
1158 if (wanted_varformat == constructorinit_vf) { |
|
1159 /* NOTE: I (Mario) think this is dead code - never gets executed. Must confirm it before deleting it... */ |
1170 s4o.print(nv->get()); |
1160 s4o.print(nv->get()); |
1171 this->print_variable_prefix(); |
1161 this->print_variable_prefix(); |
1172 s4o.print("ENO = __BOOL_LITERAL(TRUE);"); |
1162 // s4o.print("EN = __BOOL_LITERAL(TRUE);"); |
|
1163 symbol->name->accept(*this); |
|
1164 s4o.print(" = "); |
|
1165 symbol->value->accept(*this); |
|
1166 s4o.print(";"); |
1173 } |
1167 } |
1174 } |
1168 } |
1175 en_declared = true; |
1169 return NULL; |
1176 return NULL; |
1170 } |
1177 } |
1171 |
|
1172 |
|
1173 void *visit(eno_param_declaration_c *symbol) { |
|
1174 TRACE("eno_declaration_c"); |
|
1175 if (wanted_varformat == finterface_vf) { |
|
1176 finterface_var_count++; |
|
1177 } |
|
1178 if ((wanted_vartype & eno_vt) != 0) { |
|
1179 if (wanted_varformat == finterface_vf) { |
|
1180 s4o.print(nv->get()); |
|
1181 // s4o.print("\n" + s4o.indent_spaces + "BOOL *ENO"); |
|
1182 s4o.print("\n" + s4o.indent_spaces); |
|
1183 symbol->type->accept(*this); |
|
1184 s4o.print(" *__"); |
|
1185 symbol->name->accept(*this); |
|
1186 } |
|
1187 |
|
1188 if ((wanted_varformat == local_vf) || |
|
1189 (wanted_varformat == init_vf) || |
|
1190 (wanted_varformat == localinit_vf)) { |
|
1191 s4o.print(s4o.indent_spaces); |
|
1192 if (wanted_varformat != init_vf) { |
|
1193 symbol->type->accept(*this); |
|
1194 s4o.print(" "); |
|
1195 } |
|
1196 print_variable_prefix(); |
|
1197 symbol->name->accept(*this); |
|
1198 if (wanted_varformat != local_vf) { |
|
1199 s4o.print(" = __BOOL_LITERAL(TRUE);"); |
|
1200 } |
|
1201 s4o.print(";\n"); |
|
1202 } |
|
1203 |
|
1204 if (wanted_varformat == foutputassign_vf) { |
|
1205 s4o.print(s4o.indent_spaces + "if (__"); |
|
1206 symbol->name->accept(*this); |
|
1207 s4o.print(" != NULL) {\n"); |
|
1208 s4o.indent_right(); |
|
1209 s4o.print(s4o.indent_spaces + "*__"); |
|
1210 symbol->name->accept(*this); |
|
1211 s4o.print(" = "); |
|
1212 symbol->name->accept(*this); |
|
1213 s4o.print(";\n"); |
|
1214 s4o.indent_left(); |
|
1215 s4o.print(s4o.indent_spaces + "}\n"); |
|
1216 } |
|
1217 |
|
1218 if (wanted_varformat == constructorinit_vf) { |
|
1219 /* NOTE: I (Mario) think this is dead code - never gets executed. Must confirm it before deleting it... */ |
|
1220 s4o.print(nv->get()); |
|
1221 this->print_variable_prefix(); |
|
1222 // s4o.print("ENO = __BOOL_LITERAL(TRUE);"); |
|
1223 symbol->name->accept(*this); |
|
1224 s4o.print(" = __BOOL_LITERAL(TRUE);"); |
|
1225 } |
|
1226 } |
|
1227 return NULL; |
|
1228 } |
|
1229 |
1178 |
1230 |
1179 void *visit(raising_edge_option_c *symbol) { |
1231 void *visit(raising_edge_option_c *symbol) { |
1180 // TO DO ... |
1232 // TO DO ... |
1181 s4o.print("R_EDGE"); |
1233 s4o.print("R_EDGE"); |
1182 return NULL; |
1234 return NULL; |
1296 //s4o.indent_left(); |
1348 //s4o.indent_left(); |
1297 } |
1349 } |
1298 return NULL; |
1350 return NULL; |
1299 } |
1351 } |
1300 |
1352 |
1301 void *visit(eno_param_declaration_c *symbol) { |
|
1302 TRACE("eno_declaration_c"); |
|
1303 if (eno_declared) ERROR; |
|
1304 if (wanted_varformat == finterface_vf) { |
|
1305 finterface_var_count++; |
|
1306 } |
|
1307 if ((current_vartype & eneno_vt) != 0) { |
|
1308 if (wanted_varformat == finterface_vf) { |
|
1309 s4o.print(nv->get()); |
|
1310 s4o.print("\n" + s4o.indent_spaces + "BOOL *EN0"); |
|
1311 } |
|
1312 if (wanted_varformat == constructorinit_vf) { |
|
1313 s4o.print(nv->get()); |
|
1314 this->print_variable_prefix(); |
|
1315 s4o.print("ENO = __BOOL_LITERAL(TRUE);"); |
|
1316 } |
|
1317 } |
|
1318 eno_declared = true; |
|
1319 return NULL; |
|
1320 } |
|
1321 |
1353 |
1322 /* VAR_IN_OUT var_declaration_list END_VAR */ |
1354 /* VAR_IN_OUT var_declaration_list END_VAR */ |
1323 void *visit(input_output_declarations_c *symbol) { |
1355 void *visit(input_output_declarations_c *symbol) { |
1324 TRACE("input_output_declarations_c"); |
1356 TRACE("input_output_declarations_c"); |
1325 if ((wanted_vartype & inoutput_vt) != 0) { |
1357 if ((wanted_vartype & inoutput_vt) != 0) { |
2211 |
2243 |
2212 /* loop through each function parameter, find the value we should pass |
2244 /* loop through each function parameter, find the value we should pass |
2213 * to it, and then output the c equivalent... |
2245 * to it, and then output the c equivalent... |
2214 */ |
2246 */ |
2215 function_param_iterator_c fp_iterator(p_decl); |
2247 function_param_iterator_c fp_iterator(p_decl); |
|
2248 #if 0 |
2216 function_call_param_iterator_c function_call_param_iterator(symbol); |
2249 function_call_param_iterator_c function_call_param_iterator(symbol); |
|
2250 #endif |
2217 identifier_c *param_name; |
2251 identifier_c *param_name; |
2218 nv->push("", ", "); |
2252 nv->push("", ", "); |
2219 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
2253 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
2220 |
2254 |
2221 symbol_c *param_type = fp_iterator.param_type(); |
2255 symbol_c *param_type = fp_iterator.param_type(); |