294 generate_cc_il_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
296 generate_cc_il_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
295 : generate_cc_typedecl_c(s4o_ptr), |
297 : generate_cc_typedecl_c(s4o_ptr), |
296 default_variable_name(IL_DEFVAR, NULL), |
298 default_variable_name(IL_DEFVAR, NULL), |
297 default_variable_back_name(IL_DEFVAR_BACK, NULL) |
299 default_variable_back_name(IL_DEFVAR_BACK, NULL) |
298 { |
300 { |
299 search_il_operand_type = new search_il_operand_type_c(scope); |
301 //search_il_operand_type = new search_il_operand_type_c(scope); |
|
302 search_expression_type = new search_expression_type_c(scope); |
300 search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
303 search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
301 current_operand = NULL; |
304 current_operand = NULL; |
302 current_operand_type = NULL; |
305 current_operand_type = NULL; |
303 il_default_variable_init_value = NULL; |
306 il_default_variable_init_value = NULL; |
304 this->set_variable_prefix(variable_prefix); |
307 this->set_variable_prefix(variable_prefix); |
305 } |
308 } |
306 |
309 |
307 virtual ~generate_cc_il_c(void) { |
310 virtual ~generate_cc_il_c(void) { |
308 delete search_fb_instance_decl; |
311 delete search_fb_instance_decl; |
309 delete search_il_operand_type; |
312 //delete search_il_operand_type; |
|
313 delete search_expression_type; |
310 } |
314 } |
311 |
315 |
312 void generate(instruction_list_c *il) { |
316 void generate(instruction_list_c *il) { |
313 generate_cc_tempvardecl_c generate_cc_tempvardecl(&s4o); |
317 generate_cc_tempvardecl_c generate_cc_tempvardecl(&s4o); |
314 generate_cc_tempvardecl.generate(il, &temp_var_name_factory); |
318 generate_cc_tempvardecl.generate(il, &temp_var_name_factory); |
315 il->accept(*this); |
319 il->accept(*this); |
316 } |
320 } |
317 |
321 |
318 private: |
322 private: |
319 /* A helper function... */ |
323 /* A helper function... */ |
|
324 /* |
320 bool is_bool_type(symbol_c *type_symbol) { |
325 bool is_bool_type(symbol_c *type_symbol) { |
321 return (NULL != dynamic_cast<bool_type_name_c *>(type_symbol)); |
326 return (NULL != dynamic_cast<bool_type_name_c *>(type_symbol)); |
322 } |
327 } |
|
328 */ |
323 |
329 |
324 /* A helper function... */ |
330 /* A helper function... */ |
325 void *XXX_operator(symbol_c *lo, const char *op, symbol_c *ro) { |
331 void *XXX_operator(symbol_c *lo, const char *op, symbol_c *ro) { |
326 if ((NULL == lo) || (NULL == ro)) ERROR; |
332 if ((NULL == lo) || (NULL == ro)) ERROR; |
327 if (NULL == op) ERROR; |
333 if (NULL == op) ERROR; |
328 |
334 |
329 lo->accept(*this); |
335 lo->accept(*this); |
330 s4o.print(op); |
336 s4o.print(op); |
331 ro->accept(*this); |
337 ro->accept(*this); |
|
338 return NULL; |
|
339 } |
|
340 |
|
341 /* A helper function... */ |
|
342 void *XXX_function(const char *func, symbol_c *lo, symbol_c *ro) { |
|
343 if ((NULL == lo) || (NULL == ro)) ERROR; |
|
344 if (NULL == func) ERROR; |
|
345 |
|
346 lo->accept(*this); |
|
347 s4o.print(" = "); |
|
348 s4o.print(func); |
|
349 s4o.print("("); |
|
350 lo->accept(*this); |
|
351 s4o.print(", "); |
|
352 ro->accept(*this); |
|
353 s4o.print(")"); |
332 return NULL; |
354 return NULL; |
333 } |
355 } |
334 |
356 |
335 /* A helper function... */ |
357 /* A helper function... */ |
336 void *XXX_CAL_operator(const char *param_name, symbol_c *fb_name) { |
358 void *XXX_CAL_operator(const char *param_name, symbol_c *fb_name) { |
363 symbol_c *backup = this->default_variable_name.current_type; |
385 symbol_c *backup = this->default_variable_name.current_type; |
364 this->default_variable_name.current_type = &(this->bool_type); |
386 this->default_variable_name.current_type = &(this->bool_type); |
365 this->default_variable_name.accept(*this); |
387 this->default_variable_name.accept(*this); |
366 this->default_variable_name.current_type = backup; |
388 this->default_variable_name.current_type = backup; |
367 |
389 |
368 s4o.print(" = ("); |
390 if (search_expression_type->is_time_compatible(this->default_variable_name.current_type) && |
369 this->default_variable_name.accept(*this); |
391 search_expression_type->is_time_compatible(this->current_operand_type)) { |
370 s4o.print(operation); |
392 s4o.print(" = __compare_timespec("); |
371 o->accept(*this); |
393 s4o.print(operation); |
372 s4o.print(")"); |
394 s4o.print(", "); |
373 |
395 this->default_variable_name.accept(*this); |
|
396 s4o.print(", "); |
|
397 o->accept(*this); |
|
398 s4o.print(")"); |
|
399 } |
|
400 else { |
|
401 s4o.print(" = ("); |
|
402 this->default_variable_name.accept(*this); |
|
403 s4o.print(operation); |
|
404 o->accept(*this); |
|
405 s4o.print(")"); |
|
406 } |
374 /* the data type resulting from this operation... */ |
407 /* the data type resulting from this operation... */ |
375 this->default_variable_name.current_type = &(this->bool_type); |
408 this->default_variable_name.current_type = &(this->bool_type); |
376 return NULL; |
409 return NULL; |
377 } |
410 } |
378 |
411 |
379 |
412 |
380 /* A helper function... */ |
413 /* A helper function... */ |
381 void C_modifier(void) { |
414 void C_modifier(void) { |
382 if (NULL == this->default_variable_name.current_type) ERROR; |
415 if (search_expression_type->is_numeric_compatible(default_variable_name.current_type)) { |
383 |
416 s4o.print("if ("); |
384 s4o.print("if ("); |
417 this->default_variable_name.accept(*this); |
385 this->default_variable_name.accept(*this); |
418 s4o.print(") "); |
386 s4o.print(") "); |
419 } |
|
420 else {ERROR;} |
387 } |
421 } |
388 |
422 |
389 /* A helper function... */ |
423 /* A helper function... */ |
390 void CN_modifier(void) { |
424 void CN_modifier(void) { |
391 if (NULL == this->default_variable_name.current_type) ERROR; |
425 if (search_expression_type->is_numeric_compatible(default_variable_name.current_type)) { |
392 |
426 s4o.print("if (!"); |
393 s4o.print("if (!"); |
427 this->default_variable_name.accept(*this); |
394 this->default_variable_name.accept(*this); |
428 s4o.print(") "); |
395 s4o.print(") "); |
429 } |
|
430 else {ERROR;} |
396 } |
431 } |
397 |
432 |
398 |
433 |
399 public: |
434 public: |
400 void *visit(il_default_variable_c *symbol) { |
435 void *visit(il_default_variable_c *symbol) { |
986 return NULL; |
1021 return NULL; |
987 } |
1022 } |
988 |
1023 |
989 void *visit(STN_operator_c *symbol) { |
1024 void *visit(STN_operator_c *symbol) { |
990 XXX_operator(this->current_operand, |
1025 XXX_operator(this->current_operand, |
991 is_bool_type(this->current_operand_type)?" = !":" = ~", |
1026 search_expression_type->is_bool_type(this->current_operand_type)?" = !":" = ~", |
992 &(this->default_variable_name)); |
1027 &(this->default_variable_name)); |
993 /* the data type resulting from this operation is unchamged. */ |
1028 /* the data type resulting from this operation is unchamged. */ |
994 return NULL; |
1029 return NULL; |
995 } |
1030 } |
996 |
1031 |
997 void *visit(NOT_operator_c *symbol) { |
1032 void *visit(NOT_operator_c *symbol) { |
998 if ((NULL != this->current_operand) || (NULL != this->current_operand_type)) ERROR; |
1033 if ((NULL != this->current_operand) || (NULL != this->current_operand_type)) ERROR; |
999 XXX_operator(&(this->default_variable_name), |
1034 XXX_operator(&(this->default_variable_name), |
1000 is_bool_type(this->default_variable_name.current_type)?" = !":" = ~", |
1035 search_expression_type->is_bool_type(this->default_variable_name.current_type)?" = !":" = ~", |
1001 &(this->default_variable_name)); |
1036 &(this->default_variable_name)); |
1002 /* the data type resulting from this operation is unchanged. */ |
1037 /* the data type resulting from this operation is unchanged. */ |
1003 return NULL; |
1038 return NULL; |
1004 } |
1039 } |
1005 |
1040 |
1006 void *visit(S_operator_c *symbol) { |
1041 void *visit(S_operator_c *symbol) { |
1007 if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR; |
1042 if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR; |
1008 |
1043 |
1009 C_modifier(); |
1044 C_modifier(); |
1010 this->current_operand->accept(*this); |
1045 this->current_operand->accept(*this); |
1011 s4o.print(is_bool_type(this->current_operand_type)?" = true":" = 1"); |
1046 s4o.print(search_expression_type->is_bool_type(this->current_operand_type)?" = true":" = 1"); |
1012 /* the data type resulting from this operation is unchanged! */ |
1047 /* the data type resulting from this operation is unchanged! */ |
1013 return NULL; |
1048 return NULL; |
1014 } |
1049 } |
1015 |
1050 |
1016 void *visit(R_operator_c *symbol) { |
1051 void *visit(R_operator_c *symbol) { |
1017 if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR; |
1052 if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR; |
1018 |
1053 |
1019 C_modifier(); |
1054 C_modifier(); |
1020 this->current_operand->accept(*this); |
1055 this->current_operand->accept(*this); |
1021 s4o.print(is_bool_type(this->current_operand_type)?" = false":" = 0"); |
1056 s4o.print(search_expression_type->is_bool_type(this->current_operand_type)?" = false":" = 0"); |
1022 /* the data type resulting from this operation is unchanged! */ |
1057 /* the data type resulting from this operation is unchanged! */ |
1023 return NULL; |
1058 return NULL; |
1024 } |
1059 } |
1025 |
1060 |
1026 void *visit(S1_operator_c *symbol) {return XXX_CAL_operator("S1", this->current_operand);} |
1061 void *visit(S1_operator_c *symbol) {return XXX_CAL_operator("S1", this->current_operand);} |
1031 void *visit(PV_operator_c *symbol) {return XXX_CAL_operator("PV", this->current_operand);} |
1066 void *visit(PV_operator_c *symbol) {return XXX_CAL_operator("PV", this->current_operand);} |
1032 void *visit(IN_operator_c *symbol) {return XXX_CAL_operator("IN", this->current_operand);} |
1067 void *visit(IN_operator_c *symbol) {return XXX_CAL_operator("IN", this->current_operand);} |
1033 void *visit(PT_operator_c *symbol) {return XXX_CAL_operator("PT", this->current_operand);} |
1068 void *visit(PT_operator_c *symbol) {return XXX_CAL_operator("PT", this->current_operand);} |
1034 |
1069 |
1035 void *visit(AND_operator_c *symbol) { |
1070 void *visit(AND_operator_c *symbol) { |
1036 XXX_operator(&(this->default_variable_name), " &= ", this->current_operand); |
1071 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1037 /* the data type resulting from this operation... */ |
1072 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1038 this->default_variable_name.current_type = this->current_operand_type; |
1073 XXX_operator(&(this->default_variable_name), " &= ", this->current_operand); |
|
1074 /* the data type resulting from this operation... */ |
|
1075 this->default_variable_name.current_type = this->current_operand_type; |
|
1076 } |
|
1077 else {ERROR;} |
1039 return NULL; |
1078 return NULL; |
1040 } |
1079 } |
1041 |
1080 |
1042 void *visit(OR_operator_c *symbol) { |
1081 void *visit(OR_operator_c *symbol) { |
1043 XXX_operator(&(this->default_variable_name), " |= ", this->current_operand); |
1082 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1044 /* the data type resulting from this operation... */ |
1083 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1045 this->default_variable_name.current_type = this->current_operand_type; |
1084 XXX_operator(&(this->default_variable_name), " |= ", this->current_operand); |
|
1085 /* the data type resulting from this operation... */ |
|
1086 this->default_variable_name.current_type = this->current_operand_type; |
|
1087 } |
|
1088 else {ERROR;} |
1046 return NULL; |
1089 return NULL; |
1047 } |
1090 } |
1048 |
1091 |
1049 void *visit(XOR_operator_c *symbol) { |
1092 void *visit(XOR_operator_c *symbol) { |
1050 // '^' is a bit by bit exclusive OR !! Also seems to work with boolean types! |
1093 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1051 XXX_operator(&(this->default_variable_name), " ^= ", this->current_operand); |
1094 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1052 /* the data type resulting from this operation... */ |
1095 // '^' is a bit by bit exclusive OR !! Also seems to work with boolean types! |
1053 this->default_variable_name.current_type = this->current_operand_type; |
1096 XXX_operator(&(this->default_variable_name), " ^= ", this->current_operand); |
|
1097 /* the data type resulting from this operation... */ |
|
1098 this->default_variable_name.current_type = this->current_operand_type; |
|
1099 } |
|
1100 else {ERROR;} |
1054 return NULL; |
1101 return NULL; |
1055 } |
1102 } |
1056 |
1103 |
1057 void *visit(ANDN_operator_c *symbol) { |
1104 void *visit(ANDN_operator_c *symbol) { |
1058 XXX_operator(&(this->default_variable_name), |
1105 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1059 is_bool_type(this->current_operand_type)?" &= !":" &= ~", |
1106 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1060 this->current_operand); |
1107 XXX_operator(&(this->default_variable_name), |
1061 /* the data type resulting from this operation... */ |
1108 search_expression_type->is_bool_type(this->current_operand_type)?" &= !":" &= ~", |
1062 this->default_variable_name.current_type = this->current_operand_type; |
1109 this->current_operand); |
|
1110 /* the data type resulting from this operation... */ |
|
1111 this->default_variable_name.current_type = this->current_operand_type; |
|
1112 } |
|
1113 else {ERROR;} |
1063 return NULL; |
1114 return NULL; |
1064 } |
1115 } |
1065 |
1116 |
1066 void *visit(ORN_operator_c *symbol) { |
1117 void *visit(ORN_operator_c *symbol) { |
1067 XXX_operator(&(this->default_variable_name), |
1118 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1068 is_bool_type(this->current_operand_type)?" |= !":" |= ~", |
1119 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1069 this->current_operand); |
1120 XXX_operator(&(this->default_variable_name), |
1070 /* the data type resulting from this operation... */ |
1121 search_expression_type->is_bool_type(this->current_operand_type)?" |= !":" |= ~", |
1071 this->default_variable_name.current_type = this->current_operand_type; |
1122 this->current_operand); |
|
1123 /* the data type resulting from this operation... */ |
|
1124 this->default_variable_name.current_type = this->current_operand_type; |
|
1125 } |
|
1126 else {ERROR;} |
1072 return NULL; |
1127 return NULL; |
1073 } |
1128 } |
1074 |
1129 |
1075 void *visit(XORN_operator_c *symbol) { |
1130 void *visit(XORN_operator_c *symbol) { |
1076 XXX_operator(&(this->default_variable_name), |
1131 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1077 // bit by bit exclusive OR !! Also seems to work with boolean types! |
1132 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1078 is_bool_type(this->current_operand_type)?" ^= !":" ^= ~", |
1133 XXX_operator(&(this->default_variable_name), |
1079 this->current_operand); |
1134 // bit by bit exclusive OR !! Also seems to work with boolean types! |
1080 /* the data type resulting from this operation... */ |
1135 search_expression_type->is_bool_type(this->current_operand_type)?" ^= !":" ^= ~", |
1081 this->default_variable_name.current_type = this->current_operand_type; |
1136 this->current_operand); |
|
1137 /* the data type resulting from this operation... */ |
|
1138 this->default_variable_name.current_type = this->current_operand_type; |
|
1139 } |
|
1140 else {ERROR;} |
1082 return NULL; |
1141 return NULL; |
1083 } |
1142 } |
1084 |
1143 |
1085 void *visit(ADD_operator_c *symbol) { |
1144 void *visit(ADD_operator_c *symbol) { |
1086 XXX_operator(&(this->default_variable_name), " += ", this->current_operand); |
1145 if (search_expression_type->is_time_compatible(this->default_variable_name.current_type) && |
1087 /* the data type resulting from this operation... */ |
1146 search_expression_type->is_time_compatible(this->current_operand_type)) { |
1088 this->default_variable_name.current_type = this->current_operand_type; |
1147 XXX_function("__add_timespec", &(this->default_variable_name), this->current_operand); |
|
1148 /* the data type resulting from this operation... */ |
|
1149 this->default_variable_name.current_type = this->current_operand_type; |
|
1150 return NULL; |
|
1151 } |
|
1152 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
|
1153 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
|
1154 XXX_operator(&(this->default_variable_name), " += ", this->current_operand); |
|
1155 /* the data type resulting from this operation... */ |
|
1156 this->default_variable_name.current_type = this->current_operand_type; |
|
1157 return NULL; |
|
1158 } |
|
1159 ERROR; |
1089 return NULL; |
1160 return NULL; |
1090 } |
1161 } |
1091 |
1162 |
1092 void *visit(SUB_operator_c *symbol) { |
1163 void *visit(SUB_operator_c *symbol) { |
1093 XXX_operator(&(this->default_variable_name), " -= ", this->current_operand); |
1164 if (search_expression_type->is_time_compatible(this->default_variable_name.current_type) && |
1094 /* the data type resulting from this operation... */ |
1165 search_expression_type->is_time_compatible(this->current_operand_type)) { |
1095 this->default_variable_name.current_type = this->current_operand_type; |
1166 XXX_function("__sub_timespec", &(this->default_variable_name), this->current_operand); |
|
1167 /* the data type resulting from this operation... */ |
|
1168 this->default_variable_name.current_type = this->current_operand_type; |
|
1169 return NULL; |
|
1170 } |
|
1171 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
|
1172 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
|
1173 XXX_operator(&(this->default_variable_name), " -= ", this->current_operand); |
|
1174 /* the data type resulting from this operation... */ |
|
1175 this->default_variable_name.current_type = this->current_operand_type; |
|
1176 return NULL; |
|
1177 } |
|
1178 ERROR; |
1096 return NULL; |
1179 return NULL; |
1097 } |
1180 } |
1098 |
1181 |
1099 void *visit(MUL_operator_c *symbol) { |
1182 void *visit(MUL_operator_c *symbol) { |
1100 XXX_operator(&(this->default_variable_name), " *= ", this->current_operand); |
1183 if (search_expression_type->is_time_compatible(this->default_variable_name.current_type) && |
1101 /* the data type resulting from this operation... */ |
1184 search_expression_type->is_time_compatible(this->current_operand_type)) { |
1102 this->default_variable_name.current_type = this->current_operand_type; |
1185 XXX_function("__mul_timespec", &(this->default_variable_name), this->current_operand); |
|
1186 /* the data type resulting from this operation... */ |
|
1187 this->default_variable_name.current_type = this->current_operand_type; |
|
1188 return NULL; |
|
1189 } |
|
1190 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
|
1191 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
|
1192 XXX_operator(&(this->default_variable_name), " *= ", this->current_operand); |
|
1193 /* the data type resulting from this operation... */ |
|
1194 this->default_variable_name.current_type = this->current_operand_type; |
|
1195 return NULL; |
|
1196 } |
|
1197 ERROR; |
1103 return NULL; |
1198 return NULL; |
1104 } |
1199 } |
1105 |
1200 |
1106 void *visit(DIV_operator_c *symbol) { |
1201 void *visit(DIV_operator_c *symbol) { |
1107 XXX_operator(&(this->default_variable_name), " /= ", this->current_operand); |
1202 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1108 /* the data type resulting from this operation... */ |
1203 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1109 this->default_variable_name.current_type = this->current_operand_type; |
1204 XXX_operator(&(this->default_variable_name), " /= ", this->current_operand); |
|
1205 /* the data type resulting from this operation... */ |
|
1206 this->default_variable_name.current_type = this->current_operand_type; |
|
1207 } |
|
1208 else {ERROR;} |
1110 return NULL; |
1209 return NULL; |
1111 } |
1210 } |
1112 |
1211 |
1113 void *visit(MOD_operator_c *symbol) { |
1212 void *visit(MOD_operator_c *symbol) { |
1114 XXX_operator(&(this->default_variable_name), " %= ", this->current_operand); |
1213 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1115 /* the data type resulting from this operation... */ |
1214 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1116 this->default_variable_name.current_type = this->current_operand_type; |
1215 XXX_operator(&(this->default_variable_name), " %= ", this->current_operand); |
|
1216 /* the data type resulting from this operation... */ |
|
1217 this->default_variable_name.current_type = this->current_operand_type; |
|
1218 } |
|
1219 else {ERROR;} |
1117 return NULL; |
1220 return NULL; |
1118 } |
1221 } |
1119 |
1222 |
1120 void *visit(GT_operator_c *symbol) { |
1223 void *visit(GT_operator_c *symbol) { |
1121 return CMP_operator(this->current_operand, " > "); |
1224 return CMP_operator(this->current_operand, " > "); |